def test_edit(self):
        """Test editing."""
        self.mock.edit.return_value = 'test2'
        self.assertEqual('test2',
                         common.edit_if_needed('test', 'p', 'c', True))

        self.mock.edit.assert_called_once_with('test', prefix='p', comment='c')
  def gn_gen(self):
    """Finalize args.gn and run `gn gen`."""
    args_gn_path = os.path.join(self.get_build_dir_path(), ARGS_GN_FILENAME)

    common.ensure_dir(self.get_build_dir_path())
    common.delete_if_exists(args_gn_path)

    # Let users edit the current args.
    content = serialize_gn_args(self.get_gn_args())
    content = common.edit_if_needed(
        content, prefix='edit-args-gn-',
        comment='Edit %s before building.' % ARGS_GN_FILENAME,
        should_edit=self.options.edit_mode)

    # Write args to file and store.
    with open(args_gn_path, 'w') as f:
      f.write(content)

    logger.info(
        common.colorize('\nGenerating %s:\n%s\n', common.BASH_GREEN_MARKER),
        args_gn_path, content)

    common.execute(
        'gn', 'gen %s' % (self.get_build_dir_path()),
        self.get_source_dir_path())
示例#3
0
    def setup_args(self):
        """Setup args."""
        # Add custom args if any.
        # TODO(tanin): refactor the condition to its own module function.
        if self.options.target_args:
            self.args += ' %s' % self.options.target_args

        # --disable-gl-drawing-for-tests does not draw gl content on screen.
        # When running in regular mode, user would want to see screen, so
        # remove this argument.
        # TODO(tanin): refactor the condition to its own module function.
        if (self.options.disable_xvfb and DISABLE_GL_DRAW_ARG in self.args):
            self.args = self.args.replace(' %s' % DISABLE_GL_DRAW_ARG, '')
            self.args = self.args.replace(DISABLE_GL_DRAW_ARG, '')

        # Replace build directory environment variable.
        self.args = self.args.replace('%APP_DIR%', self.build_directory)

        # Use %TESTCASE% argument if available. Otherwise append testcase path.
        # TODO(tanin): refactor the condition to its own module function.
        if '%TESTCASE%' in self.args:
            self.args = self.args.replace('%TESTCASE%', self.testcase_path)
        else:
            self.args += ' %s' % self.testcase_path

        self.binary_path, self.args, self.timeout = update_for_gdb_if_needed(
            self.binary_path, self.args, self.timeout,
            self.options.enable_debug)
        self.args = common.edit_if_needed(
            self.args,
            prefix='edit-args-',
            comment='Edit arguments before running %s' % self.binary_path,
            should_edit=self.options.edit_mode)
 def test_not_edit(self):
     """Test when we shouldn't edit it."""
     self.assertEqual('test', common.edit_if_needed('test', 'p', 'c',
                                                    False))
     self.assertEqual(0, self.mock.edit.call_count)