/// <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());
        }
    }
Exemple #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);
        });
    }
    private static void Pause()
    {
        CarnaConsole.Write("Please enter any key to run fixtures...");
        var cursorLeft = CarnaConsole.CursorLeft;

        CarnaConsole.ReadKey();
        CarnaConsole.Backspace();
        CarnaConsole.BackspaceToHome(cursorLeft);
    }
Exemple #4
0
    /// <summary>
    /// Ensures the failure title.
    /// </summary>
    protected virtual void EnsureFailureTitle()
    {
        if (FailureCount > 0)
        {
            return;
        }

        CarnaConsole.WriteLineFailure("Failures");
    }
Exemple #5
0
 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));
 }
    private static void WriteHeader()
    {
        var assembly = typeof(CarnaConsoleRunner).GetTypeInfo().Assembly;

        CarnaConsole.WriteLineTitle(
            $@"--------------------------------------------
  {assembly.GetCustomAttribute<AssemblyProductAttribute>()?.Product} {assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version}
--------------------------------------------
");
    }
Exemple #7
0
 private void ReportFailedCount(int failedCount)
 {
     CarnaConsole.WriteItem("Failed: ");
     if (failedCount == 0)
     {
         CarnaConsole.WriteValue(failedCount);
     }
     else
     {
         CarnaConsole.WriteFailure(failedCount);
     }
 }
    /// <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();
        }
    }
Exemple #9
0
 private void ReportPendingCount(int pendingCount)
 {
     CarnaConsole.WriteItem("Pending: ");
     if (pendingCount == 0)
     {
         CarnaConsole.WriteValue(pendingCount);
     }
     else
     {
         CarnaConsole.WritePending(pendingCount);
     }
 }
Exemple #10
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);
    }
Exemple #11
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();
    }
Exemple #12
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();
    }
    /// <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();
        }
    }
    /// <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();
        }
    }
Exemple #15
0
    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();
    }
Exemple #16
0
 private void ReportTotalCount(int totalCount)
 {
     CarnaConsole.WriteItem("Total Count: ");
     CarnaConsole.WriteValue(totalCount);
 }
Exemple #17
0
 private void ReportPassedCount(int passedCount)
 {
     CarnaConsole.WriteItem("Passed: ");
     CarnaConsole.WriteValue(passedCount);
 }