Example #1
0
        public static async Task <int> Run(string testRoot,
                                           bool verbose,
                                           bool compatible,
                                           string logDirectory,
                                           string additionalFeed,
                                           int timeout)
        {
            TimeSpan timeoutForEachTest;

            if (timeout == 0)
            {
                timeoutForEachTest = new TimeSpan(hours: 0, minutes: 5, seconds: 0);
            }
            else
            {
                timeoutForEachTest = new TimeSpan(hours: 0, minutes: 0, seconds: timeout);
            }

            var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

            DirectoryInfo logDir;

            if (string.IsNullOrEmpty(logDirectory))
            {
                logDir = currentDirectory;
            }
            else
            {
                logDir = new DirectoryInfo(logDirectory);
            }

            DirectoryInfo testRootDirectory;

            if (string.IsNullOrEmpty(testRoot))
            {
                testRootDirectory = currentDirectory;
            }
            else
            {
                testRootDirectory = new DirectoryInfo(testRoot);
                if (!testRootDirectory.Exists)
                {
                    Console.WriteLine($"error: Test root '{testRootDirectory.FullName}' does not exist");
                    return(1);
                }
            }
            Console.WriteLine($"Testing everything under {testRootDirectory.FullName}");

            LogWriter logWriter = new LogWriter(logDir);

            Cleaner cleaner = new Cleaner();

            DotNet dotnet = new DotNet();

            TestOutput outputFormat = new TestOutputFormats.NewOutput(logWriter);

            if (compatible)
            {
                outputFormat = new TestOutputFormats.DotNetBunnyOutput(logWriter);
            }

            List <string> platformIds = new PlatformId().CurrentIds;

            Console.WriteLine($"Current platform is: {string.Join(", ", platformIds)}");

            SystemUnderTest system = new SystemUnderTest(
                runtimeVersion: dotnet.LatestRuntimeVersion,
                sdkVersion: dotnet.LatestSdkVersion,
                platformIds: platformIds
                );

            Version packageVersion = dotnet.LatestRuntimeVersion;
            string  nuGetConfig    = await GenerateNuGetConfigIfNeededAsync(additionalFeed, packageVersion);

            TestRunner runner = new TestRunner(
                cleaner: cleaner,
                system: system,
                root: testRootDirectory,
                verboseOutput: verbose,
                nuGetConfig: nuGetConfig);

            var cancellationTokenSource = new Func <CancellationTokenSource>(() => new CancellationTokenSource(timeoutForEachTest));
            var results = await runner.ScanAndRunAsync(outputFormat, cancellationTokenSource);

            int exitCode = (results.Failed == 0) ? 0 : 1;

            return(exitCode);
        }
Example #2
0
 public TestRunner(SystemUnderTest system, DirectoryInfo root, bool verboseOutput, Cleaner cleaner, string nuGetConfig)
 {
     this.root          = root;
     this.system        = system;
     this.verboseOutput = verboseOutput;
     this.cleaner       = cleaner;
     this.nuGetConfig   = nuGetConfig;
 }