コード例 #1
0
        static internal void Dispose()
        {
            //Reset the info.
            s_rIError       = null;
            s_rITestConsole = null;

            //Remove listeners
            s_rLTMConsole = null;
        }
コード例 #2
0
ファイル: cerror.cs プロジェクト: ChuangYang/corefx
        static internal void Dispose()
        {
            //Reset the info.  
            s_rIError = null;
            s_rITestConsole = null;

            //Remove listeners
            s_rLTMConsole = null;
        }
コード例 #3
0
 public AppRunnerResult(int exitCode, AppRunner runner,
                        CommandContext commandContext, ITestConsole testConsole,
                        TestConfig config, Exception?escapedException = null)
 {
     ExitCode         = exitCode;
     Runner           = runner;
     CommandContext   = commandContext;
     Console          = testConsole;
     Config           = config;
     EscapedException = escapedException;
 }
コード例 #4
0
        /// <summary>Run the console in memory and get the results that would be output to the shell</summary>
        public static AppRunnerResult RunInMem(this AppRunner runner,
                                               string[] args,
                                               Action <string?>?logLine = null,
                                               Func <ITestConsole, string>?onReadLine = null,
                                               IEnumerable <string>?pipedInput        = null,
                                               IPromptResponder?promptResponder       = null,
                                               TestConfig?config = null)
        {
            logLine ??= Console.WriteLine;
            config ??= TestConfig.Default;

            IDisposable appInfo = config.AppInfoOverride is null
                ? new DisposableAction(() => { })
                : AppInfo.SetResolver(() => config.AppInfoOverride);

            IDisposable logProvider = config.PrintCommandDotNetLogs
                ? TestToolsLogProvider.InitLogProvider(logLine)
                : new DisposableAction(() => { });

            using (appInfo)
                using (logProvider)
                {
                    ITestConsole testConsole = null !;
                    runner.Configure(c =>
                    {
                        c.Console = testConsole = c.Console as ITestConsole
                                                  ?? c.Services.GetOrDefault <ITestConsole>()
                                                  ?? new TestConsole(!config.SkipTrimEndOfConsoleOutputs);
                    });

                    if (onReadLine != null)
                    {
                        testConsole.Mock(onReadLine);
                    }
                    if (pipedInput != null)
                    {
                        testConsole.Mock(pipedInput);
                    }
                    if (promptResponder != null)
                    {
                        testConsole.Mock(promptResponder.OnReadKey);
                    }

                    CommandContext?context = null;
                    Task <int> CaptureCommandContext(CommandContext commandContext, ExecutionDelegate next)
                    {
                        context = commandContext;
                        return(next(commandContext));
                    }

                    runner.Configure(c => c.UseMiddleware(CaptureCommandContext, MiddlewareSteps.DebugDirective - 100));

                    try
                    {
                        var exitCode = runner.Run(args);
                        return(new AppRunnerResult(exitCode, runner, context !, testConsole, config)
                               .LogResult(logLine)
                               .VerifyAfterRunAssertions());
                    }
                    catch (Exception e)
                    {
                        var result = new AppRunnerResult(1, runner, context !, testConsole, config, e);
                        if (config.OnError.CaptureAndReturnResult)
                        {
                            testConsole.Error.WriteLine(e.Message);
                            logLine(e.Message);
                            logLine(e.StackTrace);
                        }

                        result
                        .LogResult(logLine, onError: true)
                        .VerifyAfterRunAssertions();
                        throw;
                    }
                }
        }