Пример #1
0
        static void Main(string[] args)
        {
            var options = ArgumentsAndOptions.Parse(args);

            if (options == null)
            {
                PrintUsage(Console.Error);
                Environment.Exit(1);
            }

            var dotnet   = new DotNet(options.DotNetHome);
            var testRoot = new DirectoryInfo(options.TestRoot);

            if (!dotnet.IsValid)
            {
                Console.Error.WriteLine(dotnet + " does not look like a .NET Core home directory");
                PrintUsage(Console.Error);
                Environment.Exit(2);
            }

            var workingDirectory = new DirectoryInfo(
                Path.Combine(Directory.GetCurrentDirectory(), "dntr." + DateTimeOffset.Now.ToUnixTimeMilliseconds()));

            if (!workingDirectory.Exists)
            {
                workingDirectory.Create();
            }
            var reportFile = new FileInfo(Path.Combine(workingDirectory.FullName, "report.txt"));

            Console.WriteLine("Testing: " + dotnet);
            Console.WriteLine("Running tests at: " + testRoot);
            Console.WriteLine("Working directory: " + workingDirectory);
            Console.WriteLine("Full report at: " + reportFile);
            Console.WriteLine();

            var tests   = FindTests(dotnet, testRoot, Console.Out);
            var results = TestRunner.ExecuteTests(dotnet,
                                                  workingDirectory,
                                                  tests,
                                                  (test) => PrintTestResult(test, Console.Out));

            PrintSummary(results, Console.Out, Console.Error);
            WriteReport(dotnet, results, reportFile);

            Environment.Exit(0);
        }
        /// <summary>
        /// Returns null if it can't parse the arguments properly
        /// </summary>
        public static ArgumentsAndOptions Parse(string[] arguments)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }
            if (arguments.Count() == 0)
            {
                return(null);
            }

            var result = new ArgumentsAndOptions();

            var toProcess = arguments.ToList();

            if (toProcess.Contains("--verbose"))
            {
                result.Verbose = true;
                toProcess.Remove("--verbose");
            }

            if (toProcess.Count() < 1)
            {
                return(null);
            }

            result.TestRoot = Path.GetFullPath(toProcess[0]);
            toProcess.RemoveAt(0);

            if (toProcess.Count > 0)
            {
                result.DotNetHome = toProcess[0];
            }
            else
            {
                result.DotNetHome = DotNet.SystemDotNetPath;
            }

            return(result);
        }