Esempio n. 1
0
    def execute_rule(self, args=tuple(), env=tuple(), exit_code=0):
        """Executes the @console_rule for this test class.

    :API: public

    Returns the text output of the task.
    """
        # Create an OptionsBootstrapper for these args/env, and a captured Console instance.
        args = self._implicit_args + (self.goal_cls.name, ) + tuple(args)
        env = dict(env)
        options_bootstrapper = OptionsBootstrapper.create(args=args, env=env)
        BuildConfigInitializer.get(options_bootstrapper)
        full_options = options_bootstrapper.get_full_options(
            list(self.goal_cls.Options.known_scope_infos()))
        stdout, stderr = StringIO(), StringIO()
        console = Console(stdout=stdout, stderr=stderr)

        # Run for the target specs parsed from the args.
        specs = TargetRootsCalculator.parse_specs(full_options.target_specs,
                                                  self.build_root)
        params = Params(specs, console, options_bootstrapper)
        actual_exit_code = self.scheduler.run_console_rule(
            self.goal_cls, params)

        # Flush and capture console output.
        console.flush()
        stdout = stdout.getvalue()
        stderr = stderr.getvalue()

        self.assertEqual(
            exit_code, actual_exit_code,
            "Exited with {} (expected {}):\nstdout:\n{}\nstderr:\n{}".format(
                actual_exit_code, exit_code, stdout, stderr))

        return stdout
Esempio n. 2
0
    def execute_rule(self,
                     args=tuple(),
                     env=tuple(),
                     exit_code=0,
                     additional_params: Iterable[Any] = tuple()):
        """Executes the @console_rule for this test class.

    :API: public

    Returns the text output of the task.
    """
        # Create an OptionsBootstrapper for these args/env, and a captured Console instance.
        args = self._implicit_args + (self.goal_cls.name, ) + tuple(args)
        env = dict(env)
        options_bootstrapper = OptionsBootstrapper.create(args=args, env=env)
        BuildConfigInitializer.get(options_bootstrapper)
        full_options = options_bootstrapper.get_full_options(
            list(self.goal_cls.subsystem_cls.known_scope_infos()))
        stdout, stderr = StringIO(), StringIO()
        console = Console(stdout=stdout, stderr=stderr)
        scheduler = self.scheduler
        workspace = Workspace(scheduler)

        # Run for the target specs parsed from the args.
        specs = TargetRootsCalculator.parse_specs(full_options.positional_args,
                                                  self.build_root)
        params = Params(specs, console, options_bootstrapper, workspace,
                        *additional_params)
        actual_exit_code = self.scheduler.run_console_rule(
            self.goal_cls, params)

        # Flush and capture console output.
        console.flush()
        stdout_val = stdout.getvalue()
        stderr_val = stderr.getvalue()

        assert exit_code == actual_exit_code, \
          f"Exited with {actual_exit_code} (expected {exit_code}):\nstdout:\n{stdout_val}\nstderr:\n{stderr_val}"

        return stdout_val