Пример #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 defaultOutput = new TestOutputFormats.NewOutput(logWriter);

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

            TestOutput junitOutput = new TestOutputFormats.JUnitOutput(logDir);

            var testOutputs = new List <TestOutput>()
            {
                defaultOutput,
                junitOutput,
            };

            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(testOutputs, cancellationTokenSource);

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

            return(exitCode);
        }
Пример #2
0
 private async Task <PartialResult> TestProjectAsync(CancellationToken token)
 {
     return(ProcessResultToPartialResult(await DotNet.TestAsync(Directory, token)));
 }