コード例 #1
0
ファイル: CarnaConsoleRunner.cs プロジェクト: averrunci/Carna
    /// <summary>
    /// Runs with the specified arguments of the command line.
    /// </summary>
    /// <param name="args">The arguments of the command line.</param>
    /// <param name="runnerName">The assembly name of the runner.</param>
    /// <param name="commandLineParser">The command line parser.</param>
    /// <returns>The value that indicates the running result.</returns>
    public static int Run(string[] args, string?runnerName = null, ICarnaRunnerCommandLineParser?commandLineParser = null)
    {
        try
        {
            WriteHeader();

            var options = (commandLineParser ?? new CarnaRunnerCommandLineParser()).Parse(args);
            if (options.HasHelp)
            {
                WriteUsage(runnerName);
                return(CarnaConsoleRunnerResult.Success.Value());
            }

            if (options.CanPause)
            {
                Pause();
            }

            return(ConsoleFixtureEngine.Start(options) ? CarnaConsoleRunnerResult.Success.Value() : CarnaConsoleRunnerResult.Failed.Value());
        }
        catch (InvalidCommandLineOptionException exc)
        {
            CarnaConsole.WriteLine(exc.Message);
            CarnaConsole.WriteLine($@"
For option syntax, type ""{(string.IsNullOrEmpty(runnerName) ? string.Empty : Name + " ")}--help""
");
            return(CarnaConsoleRunnerResult.InvalidCommandLineOption.Value());
        }
        catch (Exception exc)
        {
            CarnaConsole.WriteLine(exc);
            return(CarnaConsoleRunnerResult.Error.Value());
        }
    }
コード例 #2
0
    /// <summary>
    /// Reports the failed information of the specified fixture running results.
    /// </summary>
    /// <param name="results">The fixture running results.</param>
    protected virtual void ReportFailedInformation(IEnumerable <FixtureResult> results)
    {
        results.ForEach(result =>
        {
            if (result.Exception is not null)
            {
                EnsureFailureTitle();
                CarnaConsole.WriteFailure($"{++FailureCount}) ");
                CarnaConsole.WriteLineFailure(result.Exception);
                CarnaConsole.WriteLine();
            }

            if (result.StepExceptions.Any())
            {
                ++FailureCount;
            }

            result.StepExceptions.ForEachWithIndex((exception, index) =>
            {
                EnsureFailureTitle();
                CarnaConsole.WriteFailure($"{FailureCount}-{index + 1}) ");
                CarnaConsole.WriteLineFailure(exception);
                CarnaConsole.WriteLine();
            });

            ReportFailedInformation(result.Results);
        });
    }
コード例 #3
0
ファイル: Program.cs プロジェクト: averrunci/Carna
 private static int Main(string[] args)
 {
     AppDomain.CurrentDomain.UnhandledException += (_, e) =>
     {
         CarnaConsole.WriteLine(e.ExceptionObject as Exception);
         Environment.Exit(CarnaConsoleRunnerResult.Error.Value());
     };
     return(CarnaConsoleRunner.Run(args, CarnaConsoleRunner.Name));
 }
コード例 #4
0
    /// <summary>
    /// Reports the specified fixture running result.
    /// </summary>
    /// <param name="result">The fixture running result.</param>
    /// <param name="level">The level of the fixture running result.</param>
    protected override void Report(FixtureResult result, int level)
    {
        var nextLevel = ReportFixtureTitle(result, level);

        ReportFixtureStep(result, nextLevel);
        result.Results.ForEach(subResult => Report(subResult, nextLevel));

        if (result.FixtureDescriptor.FixtureAttributeType == typeof(AssemblyFixtureAttribute))
        {
            CarnaConsole.WriteLine();
        }
    }
コード例 #5
0
    /// <summary>
    /// Reports the summary of the specified fixture running results.
    /// </summary>
    /// <param name="results">The fixture running results.</param>
    protected virtual void ReportSummary(IEnumerable <FixtureResult> results)
    {
        var fixtureResults = results.ToList();

        ReportRunSummary(fixtureResults);

        if (fixtureResults.IsEmpty())
        {
            CarnaConsole.WriteLine();
            return;
        }

        ReportExecutionTimeSummary(fixtureResults);
    }
コード例 #6
0
    private void ReportExecutionTimeSummary(IList <FixtureResult> results)
    {
        var startTime = results.StartTime();
        var endTime   = results.EndTime();

        CarnaConsole.WriteItem("  Start Time: ");
        CarnaConsole.WriteLineValue($"{startTime:u}");

        CarnaConsole.WriteItem("    End Time: ");
        CarnaConsole.WriteLineValue($"{endTime:u}");

        CarnaConsole.WriteItem("    Duration: ");
        CarnaConsole.WriteLineValue($"{(endTime - startTime).TotalSeconds:0.000} seconds");
        CarnaConsole.WriteLine();
    }
コード例 #7
0
    private void ReportRunSummary(IList <FixtureResult> results)
    {
        CarnaConsole.WriteLineHeader("Run Summary");
        CarnaConsole.WriteItem("  ");

        ReportTotalCount(results.TotalCount());
        CarnaConsole.WriteItem(", ");

        ReportPassedCount(results.PassedCount());
        CarnaConsole.WriteItem(", ");

        ReportPendingCount(results.PendingCount());
        CarnaConsole.WriteItem(", ");

        ReportFailedCount(results.FailedCount());
        CarnaConsole.WriteLine();
    }
コード例 #8
0
    /// <summary>
    /// Reports the specified status of the fixture step running.
    /// </summary>
    /// <param name="status">The status of the fixture step running.</param>
    /// <param name="lineBreak">
    /// <c>true</c> if a line break is required; otherwise, <c>false</c>.
    /// </param>
    protected virtual void ReportStatus(FixtureStepStatus status, bool lineBreak = false)
    {
        switch (status)
        {
        case FixtureStepStatus.Ready: ReportStatus(status, CarnaConsole.WriteReady); break;

        case FixtureStepStatus.Pending: ReportStatus(status, CarnaConsole.WritePending); break;

        case FixtureStepStatus.Failed: ReportStatus(status, CarnaConsole.WriteFailure); break;

        case FixtureStepStatus.Passed: ReportStatus(status, CarnaConsole.WriteSuccess); break;
        }

        if (lineBreak)
        {
            CarnaConsole.WriteLine();
        }
    }
コード例 #9
0
    /// <summary>
    /// Reports the specified value with the specified status of the fixture step running.
    /// </summary>
    /// <param name="value">The value to be reported.</param>
    /// <param name="status">The status of the fixture step running.</param>
    /// <param name="lineBreak">
    /// <c>true</c> if a line break is required; otherwise, <c>false</c>.
    /// </param>
    protected virtual void ReportValue(string value, FixtureStepStatus status, bool lineBreak = false)
    {
        switch (status)
        {
        case FixtureStepStatus.Ready: CarnaConsole.WriteReady(value); break;

        case FixtureStepStatus.Pending: CarnaConsole.WritePending(value); break;

        case FixtureStepStatus.Failed: CarnaConsole.WriteFailure(value); break;

        case FixtureStepStatus.None: CarnaConsole.WriteNote(value); break;

        default: CarnaConsole.WriteValue(value); break;
        }

        if (lineBreak)
        {
            CarnaConsole.WriteLine();
        }
    }
コード例 #10
0
ファイル: CarnaConsoleRunner.cs プロジェクト: averrunci/Carna
    private static void WriteUsage(string?runnerName)
    {
        CarnaConsole.WriteLine($@"Usage:

  {(string.IsNullOrEmpty(runnerName) ? string.Empty : Name + " ")}[options] [assembly file]

Description:

  Runs the fixtures in the specified assemblies.
  If an assembly or settings file is not specified,
  {Name} searches the current working
  directory for a settings file that has a file name
  that is 'carna-runner-settings.json' and uses that
  file.

Options:");
        CarnaRunnerCommandLineOptions.RegisteredOptions
        .Where(option => !string.IsNullOrEmpty(option.Description))
        .OrderBy(option => option.Order)
        .ForEach(option => CarnaConsole.WriteLine(option.Description));
        CarnaConsole.WriteLine();
    }