Beispiel #1
0
        private void RunTestSuite(ITestResultLogger logger, string directoryName)
        {
            var project = new Project(Path.Combine(directoryName, Path.GetFileName(directoryName) + ".unoproj"));

            project.MutablePackageReferences.Add(new PackageReference(project.Source, "Uno.Testing"));
            project.MutableProjectReferences.Add(new ProjectReference(project.Source, "../_Outracks.UnoTest.InternalHelpers/_Outracks.UnoTest.InternalHelpers.unoproj"));

            logger.ProjectStarting(project.Name, BuildTargets.Default.Identifier);
            var tests = new List <Test>();

            foreach (var file in Directory.GetFiles(directoryName, "*.uno").Where(x => x.EndsWith(".uno")))
            {
                var filePath = Path.GetFullPath(file);
                project.MutableIncludeItems.Clear();
                var fileName = Path.GetFileName(filePath);
                project.MutableIncludeItems.Add(new IncludeItem(project.Source, IncludeItemType.Source, fileName));

                var test = new Test(fileName);
                tests.Add(test);

                var expectations = ParseAssertComment(filePath).ToList();
                var ignores      = expectations.Where(e => e.Type == ErrorType.Ignore).ToList();
                expectations = expectations.Except(ignores).ToList();

                foreach (var ignore in ignores)
                {
                    logger.TestIgnored(new Test(ignore.ToString()));
                }

                var output           = RunBuild(project);
                var errors           = ParseOutput(output);
                var unexpectedErrors = errors.Except(expectations, new ErrorItemComparer()).ToList();
                var notGivenErrors   = expectations.Except(errors, new ErrorItemComparer()).ToList();

                foreach (var error in unexpectedErrors)
                {
                    test.Asserted(new Assertion(error.Source.FullPath, error.Source.Line, null, "(Got an unexpected error)", error.ToString(), error.Expression));
                    logger.TestAsserted(test);
                }

                foreach (var error in notGivenErrors)
                {
                    test.Asserted(new Assertion(error.Source.FullPath, error.Source.Line, null, error.ToString(), "(Missed an expected error)", error.Expression));
                    logger.TestAsserted(test);
                }

                if (!unexpectedErrors.Any() && !notGivenErrors.Any())
                {
                    test.Passed();
                    logger.TestPassed(test);
                }
            }

            logger.ProjectEnded(tests);
            logger.Log("");
        }
Beispiel #2
0
        public void EventOccured(NameValueCollection eventDetails)
        {
            lock (_lock)
            {
                var eventType = eventDetails.Get("event");
                if (eventType == "ready")
                {
                    if (CurrentState != State.WaitingForReady)
                    {
                        throw new InvalidOperationException("Unexpected 'ready'-event");
                    }

                    _testCount = int.Parse(eventDetails.Get("testCount"));

                    _currentState = State.Ready;
                    return;
                }

                if (CurrentState < State.Ready)
                {
                    throw new InvalidOperationException(string.Format("Unexpected '{0}'-event", eventType));
                }

                var testName = eventDetails.Get("testName");
                var us       = eventDetails["us"] != null?int.Parse(eventDetails["us"]) : -1;

                switch (eventType)
                {
                case "testStarted":
                    if (CurrentState != State.Ready)
                    {
                        throw new InvalidOperationException("Unexpected 'testStarted'-event");
                    }

                    var test = new Test(testName);
                    _tests.Add(test);
                    _currentState = State.Running;

                    CurrentTest.Started();
                    break;

                case "testPassed":
                    if (CurrentState != State.Running)
                    {
                        throw new InvalidOperationException("Unexpected 'testPassed'-event");
                    }

                    if (!CurrentTest.Name.Equals(testName))
                    {
                        throw new InvalidOperationException("Event for wrong test");
                    }

                    CurrentTest.Passed(us);
                    _logger.TestPassed(CurrentTest);

                    _currentState = State.Ready;
                    break;

                case "testIgnored":
                    if (CurrentState != State.Running)
                    {
                        throw new InvalidOperationException("Unexpected 'testIgnored'-event");
                    }

                    if (!CurrentTest.Name.Equals(testName))
                    {
                        throw new InvalidOperationException("Event for wrong test");
                    }

                    CurrentTest.Ignored(eventDetails.Get("reason"));
                    _logger.TestIgnored(CurrentTest);

                    _currentState = State.Ready;
                    break;

                case "testAsserted":
                    if (CurrentState != State.Running)
                    {
                        throw new InvalidOperationException("Unexpected 'testAsserted'-event");
                    }

                    if (!CurrentTest.Name.Equals(testName))
                    {
                        throw new InvalidOperationException("Event for wrong test");
                    }

                    CurrentTest.Asserted(Assertion.From(eventDetails));
                    _logger.TestAsserted(CurrentTest);

                    _currentState = State.Ready;
                    break;

                case "testThrew":
                    if (CurrentState != State.Running)
                    {
                        throw new InvalidOperationException("Unexpected 'testThrew'-event");
                    }

                    if (!CurrentTest.Name.Equals(testName))
                    {
                        throw new InvalidOperationException("Event for wrong test");
                    }

                    CurrentTest.Threw(eventDetails.Get("message"));
                    _logger.TestThrew(CurrentTest);

                    _currentState = State.Ready;
                    break;

                case "internalError":
                    _logger.InternalError(eventDetails.Get("message"));
                    break;

                default:
                    throw new Exception(string.Format("Internal Error: Unknown event '{0}' (name={1})", eventType, testName));
                }

                if (_tests.Count == _testCount && _currentState == State.Ready)
                {
                    End();
                }
            }
        }