Exemplo n.º 1
0
        private void PrintFailure(TestResultWrapper result)
        {
            var r = result.TestResult;

            if (result.Exceptions.Any())
            {
                writer.WriteLine(ColorStyle.Error, string.Format("FATAL ERROR: {0}", r.DisplayName));
            }
            else
            {
                writer.WriteLine(ColorStyle.Failure, string.Format("Violated: {0}", r.DisplayName));
            }
            foreach (var msg in r.Messages)
            {
                writer.WriteLine(ColorStyle.Failure, msg);
            }
            writer.WriteLine();
            foreach (var e in result.Exceptions)
            {
                writer.WriteLine(ColorStyle.Error, e.StackTrace);
            }
        }
Exemplo n.º 2
0
        int Execute()
        {
            var designTimeFullyQualifiedNames = SetupSinks(args);

            var results = new List <TestResultWrapper>();

            foreach (var assembly in args.Inputs)
            {
                var assemblyPath = Path.GetFullPath(assembly);
                var testAssembly = LoadAssembly(assemblyPath);
                var libraryPath  = Path.Combine(Path.GetDirectoryName(assemblyPath), "Persimmon.dll");
                var library      = LoadAssembly(libraryPath);

                var driver = new PersimmonDriver(library, testAssembly);
                var tests  = driver.CollectTests();

                if (args.DesignTime && designTimeFullyQualifiedNames.Any())
                {
                    tests = tests.Where(t => designTimeFullyQualifiedNames.Contains(t.Test.FullyQualifiedName));
                }

                if (args.List)
                {
                    foreach (var test in tests)
                    {
                        testDiscoverySink.SendTestFound(test.Test);
                    }
                }
                else
                {
                    Action <object> before = testCase =>
                    {
                        if (args.DesignTime)
                        {
                            testExecutionSink.SendTestStarted(new TestCaseWrapper(testCase).Test);
                        }
                    };
                    Action <object> progress = result =>
                    {
                        var wrapper = new TestResultWrapper(result);
                        // TODO: send async
                        //if (args.DesignTime)
                        //{
                        //    testExecutionSink.SendTestResult(wrapper.TestResult);
                        //}
                        //else
                        if (!args.DesignTime)
                        {
                            switch (wrapper.TestResult.Outcome)
                            {
                            case TestOutcome.Passed:
                                Console.Write(".");
                                break;

                            case TestOutcome.Failed:
                                if (wrapper.Exceptions.Any())
                                {
                                    Console.Write("E");
                                }
                                else
                                {
                                    Console.Write("x");
                                }
                                break;

                            case TestOutcome.Skipped:
                                Console.Write("_");
                                break;

                            default:
                                break;
                            }
                        }
                        results.Add(wrapper);
                    };
                    driver.RunTests(tests.Select(t => t.Test.FullyQualifiedName).ToArray(), before, progress);
                }
            }

            // TODO: remove after implement `send async`
            if (args.DesignTime)
            {
                foreach (var wrapper in results)
                {
                    testExecutionSink.SendTestResult(wrapper.TestResult);
                }
            }

            if (args.List)
            {
                if (args.DesignTime)
                {
                    testDiscoverySink.SendTestCompleted();
                }
                return(0);
            }

            if (args.DesignTime)
            {
                testExecutionSink.SendTestCompleted();
                return(0);
            }

            var reporter = new Reporter(results, ColorConsole);

            reporter.Report();

            return(results.Where(r => r.TestResult.Outcome == TestOutcome.Failed).Count());
        }