Example #1
0
    static async Task Main(string[] args)
    {
        try
        {
            var runner = new TestRunner(HelixTestRunnerOptions.Parse(args));

            var keepGoing = runner.SetupEnvironment();
            if (keepGoing)
            {
                keepGoing = await runner.InstallDotnetToolsAsync();
            }

            if (keepGoing)
            {
                if (runner.Options.InstallPlaywright)
                {
                    keepGoing = runner.InstallPlaywright();
                }
                else
                {
                    ProcessUtil.PrintMessage("Playwright install skipped.");
                }
            }

            runner.DisplayContents();

            if (keepGoing)
            {
                if (!await runner.CheckTestDiscoveryAsync())
                {
                    ProcessUtil.PrintMessage("RunTest stopping due to test discovery failure.");
                    Environment.Exit(1);
                    return;
                }

                ProcessUtil.PrintMessage("Start running tests");
                var exitCode = await runner.RunTestsAsync();

                ProcessUtil.PrintMessage("Running tests complete");

                ProcessUtil.PrintMessage("Uploading test results");
                runner.UploadResults();
                ProcessUtil.PrintMessage("Test results uploaded");

                ProcessUtil.PrintMessage($"Completed Helix job with exit code '{exitCode}'");
                Environment.Exit(exitCode);
            }

            ProcessUtil.PrintMessage("Tests were not run due to previous failures. Exit code=1");
            Environment.Exit(1);
        }
        catch (Exception e)
        {
            ProcessUtil.PrintMessage($"HelixTestRunner uncaught exception: {e.ToString()}");
            Environment.Exit(1);
        }
    }
    public static HelixTestRunnerOptions Parse(string[] args)
    {
        var command = new RootCommand()
        {
            new Option(
                aliases: new string[] { "--target", "-t" },
                description: "The test dll to run")
            {
                Argument = new Argument <string>(), Required = true
            },

            new Option(
                aliases: new string[] { "--runtime" },
                description: "The version of the ASP.NET runtime being installed and used")
            {
                Argument = new Argument <string>(), Required = true
            },

            new Option(
                aliases: new string[] { "--queue" },
                description: "The name of the Helix queue being run on")
            {
                Argument = new Argument <string>(), Required = true
            },

            new Option(
                aliases: new string[] { "--arch" },
                description: "The architecture being run on")
            {
                Argument = new Argument <string>(), Required = true
            },

            new Option(
                aliases: new string[] { "--playwright" },
                description: "Whether to install Microsoft.Playwright browsers or not")
            {
                Argument = new Argument <bool>(), Required = true
            },

            new Option(
                aliases: new string[] { "--quarantined" },
                description: "Whether quarantined tests should run or not")
            {
                Argument = new Argument <bool>(), Required = true
            },

            new Option(
                aliases: new string[] { "--helixTimeout" },
                description: "The timeout duration of the Helix job")
            {
                Argument = new Argument <string>(), Required = true
            },

            new Option(
                aliases: new string[] { "--source" },
                description: "The restore sources to use during testing")
            {
                Argument = new Argument <string>()
                {
                    Arity = ArgumentArity.ZeroOrMore
                }, Required = true
            }
        };

        var parseResult     = command.Parse(args);
        var sharedFxVersion = parseResult.ValueForOption <string>("--runtime");
        var options         = new HelixTestRunnerOptions
        {
            Architecture      = parseResult.ValueForOption <string>("--arch"),
            HelixQueue        = parseResult.ValueForOption <string>("--queue"),
            InstallPlaywright = parseResult.ValueForOption <bool>("--playwright"),
            Quarantined       = parseResult.ValueForOption <bool>("--quarantined"),
            RuntimeVersion    = sharedFxVersion,
            Target            = parseResult.ValueForOption <string>("--target"),
            Timeout           = TimeSpan.Parse(parseResult.ValueForOption <string>("--helixTimeout"), CultureInfo.InvariantCulture),

            // When targeting pack builds, it has exactly the same version as the shared framework.
            AspNetRef     = $"Microsoft.AspNetCore.App.Ref.{sharedFxVersion}.nupkg",
            AspNetRuntime = $"Microsoft.AspNetCore.App.Runtime.win-x64.{sharedFxVersion}.nupkg",

            DotnetRoot          = Environment.GetEnvironmentVariable("DOTNET_ROOT"),
            HELIX_WORKITEM_ROOT = Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT"),
            Path = Environment.GetEnvironmentVariable("PATH"),
        };

        return(options);
    }
Example #3
0
 public TestRunner(HelixTestRunnerOptions options)
 {
     Options = options;
     EnvironmentVariables = new Dictionary <string, string>();
 }