public void Parse_EmptyString_EmptyResults()
        {
            var parser = new ErrorMessageParser("", BaseDir);
            parser.Parse();

            parser.ErrorMessage.Should().Be("");
            parser.ErrorStackTrace.Should().Be("");
        }
        public void Parse_EmptyString_EmptyResults()
        {
            ErrorMessageParser parser = new ErrorMessageParser("", BaseDir);

            parser.Parse();

            Assert.AreEqual("", parser.ErrorMessage);
            Assert.AreEqual("", parser.ErrorStackTrace);
        }
Пример #3
0
        public void Parse_EmptyString_EmptyResults()
        {
            var parser = new ErrorMessageParser("");

            parser.Parse();

            parser.ErrorMessage.Should().Be("");
            parser.ErrorStackTrace.Should().Be("");
        }
        public void Parse_SingleErrorMessage_MessageIsParsedWithoutLink()
        {
            string errorString = $"{FullPathOfDummyExecutable}:42: error: Expected: Foo\nActual: Bar";

            var parser = new ErrorMessageParser(errorString, BaseDir);
            parser.Parse();

            parser.ErrorMessage.Should().Be("Expected: Foo\nActual: Bar");
            parser.ErrorStackTrace.Should().Contain($"{DummyExecutable}:42");
        }
        public void Parse_SingleUnparsableErrorMessage_MessageIsPassed()
        {
            string errorString = "Some weird error message";

            var parser = new ErrorMessageParser(errorString, BaseDir);
            parser.Parse();

            parser.ErrorMessage.Should().Be("Some weird error message");
            parser.ErrorStackTrace.Should().BeEmpty();
        }
Пример #6
0
        private TestResult ParseTestResult(XmlNode testcaseNode)
        {
            string className     = testcaseNode.Attributes["classname"].InnerText;
            string testCaseName  = testcaseNode.Attributes["name"].InnerText;
            string qualifiedName = className + "." + testCaseName;

            TestCase testCase = _testCasesRun.FindTestcase(qualifiedName);

            if (testCase == null)
            {
                return(null);
            }

            var testResult = new TestResult(testCase)
            {
                ComputerName = Environment.MachineName,
                DisplayName  = testCase.DisplayName
            };

            string duration = testcaseNode.Attributes["time"].InnerText;

            testResult.Duration = ParseDuration(duration);

            string testCaseStatus = testcaseNode.Attributes["status"].InnerText;

            switch (testCaseStatus)
            {
            case "run":
                XmlNodeList failureNodes = testcaseNode.SelectNodes("failure");
                if (failureNodes.Count == 0)
                {
                    testResult.Outcome = TestOutcome.Passed;
                }
                else
                {
                    var parser = new ErrorMessageParser(failureNodes, _baseDir);
                    parser.Parse();
                    testResult.Outcome         = TestOutcome.Failed;
                    testResult.ErrorMessage    = parser.ErrorMessage;
                    testResult.ErrorStackTrace = parser.ErrorStackTrace;
                }
                break;

            case "notrun":
                testResult.Outcome = TestOutcome.Skipped;
                break;

            default:
                string msg = "Unknown testcase status: " + testCaseStatus;
                _testEnvironment.LogError(msg);
                throw new Exception(msg);
            }

            return(testResult);
        }
Пример #7
0
        private TestResult CreateTestResult(int indexOfTestcase)
        {
            int currentLineIndex = indexOfTestcase;

            string   line = _consoleOutput[currentLineIndex++];
            string   qualifiedTestname = RemovePrefix(line).Trim();
            TestCase testCase          = FindTestcase(qualifiedTestname);

            if (testCase == null)
            {
                _logger.DebugWarning($"No known test case for test result of line '{line}' - are you repeating a test run, but tests have changed in the meantime?");
                return(null);
            }

            if (currentLineIndex >= _consoleOutput.Count)
            {
                CrashedTestCase = testCase;
                return(CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), CrashText, ""));
            }

            line = _consoleOutput[currentLineIndex];
            SplitLineIfNecessary(ref line, currentLineIndex);
            currentLineIndex++;


            string errorMsg = "";

            while (!(IsFailedLine(line) || IsPassedLine(line) || IsSkippedLine(line)) && currentLineIndex <= _consoleOutput.Count)
            {
                errorMsg += line + "\n";
                line      = currentLineIndex < _consoleOutput.Count ? _consoleOutput[currentLineIndex] : "";
                SplitLineIfNecessary(ref line, currentLineIndex);
                currentLineIndex++;
            }
            if (IsFailedLine(line))
            {
                ErrorMessageParser parser = new ErrorMessageParser(errorMsg);
                parser.Parse();
                return(CreateFailedTestResult(testCase, ParseDuration(line), parser.ErrorMessage, parser.ErrorStackTrace));
            }
            if (IsPassedLine(line))
            {
                return(CreatePassedTestResult(testCase, ParseDuration(line)));
            }
            if (IsSkippedLine(line))
            {
                return(CreateSkippedTestResult(testCase, ParseDuration(line)));
            }

            CrashedTestCase = testCase;
            string message = CrashText;

            message += errorMsg == "" ? "" : "\nTest output:\n\n" + errorMsg;
            return(CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), message, ""));
        }
Пример #8
0
        public void Parse_SingleErrorMessage_MessageIsParsedWithoutLink()
        {
            string errorString = $"{FullPathOfDummyExecutable}:42: error: Expected: Foo\nActual: Bar";

            var parser = new ErrorMessageParser(errorString);

            parser.Parse();

            parser.ErrorMessage.Should().Be("Expected: Foo\nActual: Bar");
            parser.ErrorStackTrace.Should().Contain($"{DummyExecutable}:42");
        }
        public void Parse_SingleErrorMessage_MessageIsParsedWithoutLink()
        {
            string errorString = $"{FullPathOfDummyExecutable}:42: error: Expected: Foo\nActual: Bar";

            ErrorMessageParser parser = new ErrorMessageParser(errorString, BaseDir);

            parser.Parse();

            Assert.AreEqual("Expected: Foo\nActual: Bar", parser.ErrorMessage);
            Assert.IsTrue(parser.ErrorStackTrace.Contains($"{DummyExecutable}:42"));
        }
        private TestResult ParseTestResult(XmlNode testcaseNode)
        {
            string qualifiedName = GetQualifiedName(testcaseNode);

            TestCase testCase;

            if (!_testCasesMap.TryGetValue(qualifiedName, out testCase) &&
                !_workaroundMapLazy.Value.TryGetValue(qualifiedName, out testCase))
            {
                return(null);
            }

            var testResult = new TestResult(testCase)
            {
                ComputerName = Environment.MachineName,
                DisplayName  = testCase.DisplayName
            };

            string duration = testcaseNode.Attributes["time"].InnerText;

            testResult.Duration = ParseDuration(duration);

            string testCaseStatus = testcaseNode.Attributes["status"].InnerText;

            switch (testCaseStatus)
            {
            case "run":
                XmlNodeList failureNodes = testcaseNode.SelectNodes("failure");
                if (failureNodes.Count == 0)
                {
                    testResult.Outcome = TestOutcome.Passed;
                }
                else
                {
                    var parser = new ErrorMessageParser(failureNodes);
                    parser.Parse();
                    testResult.Outcome         = TestOutcome.Failed;
                    testResult.ErrorMessage    = parser.ErrorMessage;
                    testResult.ErrorStackTrace = parser.ErrorStackTrace;
                }
                break;

            case "notrun":
                testResult.Outcome = TestOutcome.Skipped;
                break;

            default:
                string msg = "Unknown testcase status: " + testCaseStatus;
                _logger.LogError(msg);
                throw new Exception(msg);
            }

            return(testResult);
        }
Пример #11
0
        public void Parse_SingleUnparsableErrorMessage_MessageIsPassed()
        {
            string errorString = "Some weird error message";

            var parser = new ErrorMessageParser(errorString);

            parser.Parse();

            parser.ErrorMessage.Should().Be("Some weird error message");
            parser.ErrorStackTrace.Should().BeEmpty();
        }
Пример #12
0
        public void Parse_MessageWithSourceLocationInDifferentFormat()
        {
            string errorString = @"unknown file: error: C++ exception with description ""Assertion failed in c:\users\chris\git\googletestadapter\sampletests\tests\basictests.cpp:-179"" thrown in the test body.";

            var parser = new ErrorMessageParser(errorString);

            parser.Parse();

            parser.ErrorStackTrace.Should().BeEmpty();
            parser.ErrorMessage.Should().Contain(@"c:\users\chris\git\googletestadapter\sampletests\tests\basictests.cpp:-179");
        }
        public void Parse_TwoErrorMessages_BothMessagesAreParsedWithLinks()
        {
            string errorString = $"{FullPathOfDummyExecutable}:37: error: Expected: Yes\nActual: Maybe";
            errorString += $"\n{FullPathOfDummyExecutable}:42: Failure\nExpected: Foo\nActual: Bar";

            var parser = new ErrorMessageParser(errorString, BaseDir);
            parser.Parse();

            parser.ErrorMessage.Should().Be("#1 - Expected: Yes\nActual: Maybe\n#2 - Expected: Foo\nActual: Bar");
            parser.ErrorStackTrace.Should().Contain($"#1 - {DummyExecutable}:37");
            parser.ErrorStackTrace.Should().Contain($"#2 - {DummyExecutable}:42");
        }
        public void Parse_DifferentlyFormattedErrorMessages_BothMessagesAreParsedInCorrectOrder()
        {
            string errorString = $"{FullPathOfDummyExecutable}(37): error: Expected: Yes\nActual: Maybe";
            errorString += $"\n{FullPathOfDummyExecutable}:42: error: Expected: Foo\nActual: Bar";

            var parser = new ErrorMessageParser(errorString, BaseDir);
            parser.Parse();

            parser.ErrorMessage.Should().Be("#1 - Expected: Yes\nActual: Maybe\n#2 - Expected: Foo\nActual: Bar");
            parser.ErrorStackTrace.Should().Contain($"#1 - {DummyExecutable}:37");
            parser.ErrorStackTrace.Should().Contain($"#2 - {DummyExecutable}:42");
        }
        public void Parse_DifferentlyFormattedErrorMessages_BothMessagesAreParsedInCorrectOrder()
        {
            string errorString = $"{FullPathOfDummyExecutable}(37): error: Expected: Yes\nActual: Maybe";

            errorString += $"\n{FullPathOfDummyExecutable}:42: error: Expected: Foo\nActual: Bar";

            ErrorMessageParser parser = new ErrorMessageParser(errorString, BaseDir);

            parser.Parse();

            Assert.AreEqual("#1 - Expected: Yes\nActual: Maybe\n#2 - Expected: Foo\nActual: Bar", parser.ErrorMessage);
            Assert.IsTrue(parser.ErrorStackTrace.Contains($"#1 - {DummyExecutable}:37"));
            Assert.IsTrue(parser.ErrorStackTrace.Contains($"#2 - {DummyExecutable}:42"));
        }
        public void Parse_TwoErrorMessages_BothMessagesAreParsedWithLinks()
        {
            string errorString = $"{FullPathOfDummyExecutable}:37: error: Expected: Yes\nActual: Maybe";

            errorString += $"\n{FullPathOfDummyExecutable}:42: Failure\nExpected: Foo\nActual: Bar";

            ErrorMessageParser parser = new ErrorMessageParser(errorString, BaseDir);

            parser.Parse();

            Assert.AreEqual("#1 - Expected: Yes\nActual: Maybe\n#2 - Expected: Foo\nActual: Bar", parser.ErrorMessage);
            Assert.IsTrue(parser.ErrorStackTrace.Contains($"#1 - {DummyExecutable}:37"));
            Assert.IsTrue(parser.ErrorStackTrace.Contains($"#2 - {DummyExecutable}:42"));
        }
Пример #17
0
        public void Parse_NullBaseDir()
        {
            string errorString = $"{FullPathOfDummyExecutable}:37: error: Expected: Yes\nActual: Maybe";

            errorString += $"\n{FullPathOfDummyExecutable}:42: Failure\nExpected: Foo\nActual: Bar";

            var parser = new ErrorMessageParser(errorString);

            parser.Parse();

            parser.ErrorMessage.Should().Be("#1 - Expected: Yes\nActual: Maybe\n#2 - Expected: Foo\nActual: Bar");
            parser.ErrorStackTrace.Should().Contain($"#1 - {DummyExecutable}:37");
            parser.ErrorStackTrace.Should().Contain($"#2 - {DummyExecutable}:42");
        }
Пример #18
0
        public void Parse_DifferentlyFormattedErrorMessages_BothMessagesAreParsedInCorrectOrder()
        {
            string errorString = $"{FullPathOfDummyExecutable}(37): error: Expected: Yes\nActual: Maybe";

            errorString += $"\n{FullPathOfDummyExecutable}:42: error: Expected: Foo\nActual: Bar";

            var parser = new ErrorMessageParser(errorString);

            parser.Parse();

            parser.ErrorMessage.Should().Be("#1 - Expected: Yes\nActual: Maybe\n#2 - Expected: Foo\nActual: Bar");
            parser.ErrorStackTrace.Should().Contain($"#1 - {DummyExecutable}:37");
            parser.ErrorStackTrace.Should().Contain($"#2 - {DummyExecutable}:42");
        }
Пример #19
0
        private TestResult CreateFailedTestResult(TestCase testCase, TimeSpan duration, bool crashed, string errorMessage)
        {
            if (crashed)
            {
                CrashedTestCase = testCase;
            }

            ErrorMessageParser parser = new ErrorMessageParser(errorMessage, BaseDir);

            parser.Parse();
            return(new TestResult(testCase)
            {
                ComputerName = Environment.MachineName,
                DisplayName = testCase.DisplayName,
                Outcome = TestOutcome.Failed,
                ErrorMessage = crashed ? CrashText : parser.ErrorMessage,
                ErrorStackTrace = parser.ErrorStackTrace,
                Duration = duration
            });
        }
Пример #20
0
        private TestResult CreateTestResult(int indexOfTestcase)
        {
            int currentLineIndex = indexOfTestcase;

            string   line = _consoleOutput[currentLineIndex++];
            string   qualifiedTestname = RemovePrefix(line).Trim();
            TestCase testCase          = FindTestcase(qualifiedTestname);

            if (currentLineIndex >= _consoleOutput.Count)
            {
                CrashedTestCase = testCase;
                return(CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), CrashText, ""));
            }

            line = _consoleOutput[currentLineIndex++];

            string errorMsg = "";

            while (!(IsFailedLine(line) || IsPassedLine(line)) && currentLineIndex <= _consoleOutput.Count)
            {
                errorMsg += line + "\n";
                line      = currentLineIndex < _consoleOutput.Count ? _consoleOutput[currentLineIndex] : "";
                currentLineIndex++;
            }
            if (IsFailedLine(line))
            {
                ErrorMessageParser parser = new ErrorMessageParser(errorMsg, _baseDir);
                parser.Parse();
                return(CreateFailedTestResult(testCase, ParseDuration(line), parser.ErrorMessage, parser.ErrorStackTrace));
            }
            if (IsPassedLine(line))
            {
                return(CreatePassedTestResult(testCase, ParseDuration(line)));
            }

            CrashedTestCase = testCase;
            string message = CrashText;

            message += errorMsg == "" ? "" : "\nTest output:\n\n" + errorMsg;
            return(CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), message, ""));
        }
        private TestResult CreateTestResult(int indexOfTestcase)
        {
            int currentLineIndex = indexOfTestcase;

            string line = _consoleOutput[currentLineIndex++];
            string qualifiedTestname = RemovePrefix(line).Trim();
            TestCase testCase = FindTestcase(qualifiedTestname);

            if (currentLineIndex >= _consoleOutput.Count)
            {
                CrashedTestCase = testCase;
                return CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), CrashText, "");
            }

            line = _consoleOutput[currentLineIndex++];

            string errorMsg = "";
            while (!(IsFailedLine(line) || IsPassedLine(line)) && currentLineIndex <= _consoleOutput.Count)
            {
                errorMsg += line + "\n";
                line = currentLineIndex < _consoleOutput.Count ? _consoleOutput[currentLineIndex] : "";
                currentLineIndex++;
            }
            if (IsFailedLine(line))
            {
                ErrorMessageParser parser = new ErrorMessageParser(errorMsg, _baseDir);
                parser.Parse();
                return CreateFailedTestResult(testCase, ParseDuration(line), parser.ErrorMessage, parser.ErrorStackTrace);
            }
            if (IsPassedLine(line))
            {
                return CreatePassedTestResult(testCase, ParseDuration(line));
            }

            CrashedTestCase = testCase;
            string message = CrashText;
            message += errorMsg == "" ? "" : "\nTest output:\n\n" + errorMsg;
            return CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), message, "");
        }
Пример #22
0
        private TestResult CreateTestResult()
        {
            int currentLineIndex = 0;

            while (currentLineIndex < _consoleOutput.Count &&
                   !StandardOutputTestResultParser.IsRunLine(_consoleOutput[currentLineIndex]))
            {
                currentLineIndex++;
            }
            if (currentLineIndex >= _consoleOutput.Count)
            {
                return(null);
            }

            string   line = _consoleOutput[currentLineIndex++];
            string   qualifiedTestname = StandardOutputTestResultParser.RemovePrefix(line).Trim();
            TestCase testCase          = StandardOutputTestResultParser.FindTestcase(qualifiedTestname, _testCasesRun);

            if (currentLineIndex >= _consoleOutput.Count)
            {
                CrashedTestCase = testCase;
                return(StandardOutputTestResultParser.CreateFailedTestResult(
                           testCase,
                           TimeSpan.FromMilliseconds(0),
                           StandardOutputTestResultParser.CrashText,
                           ""));
            }

            line = _consoleOutput[currentLineIndex++];

            string errorMsg = "";

            while (
                !(StandardOutputTestResultParser.IsFailedLine(line) ||
                  StandardOutputTestResultParser.IsPassedLine(line)) &&
                currentLineIndex <= _consoleOutput.Count)
            {
                errorMsg += line + "\n";
                line      = currentLineIndex < _consoleOutput.Count ? _consoleOutput[currentLineIndex] : "";
                currentLineIndex++;
            }
            if (StandardOutputTestResultParser.IsFailedLine(line))
            {
                ErrorMessageParser parser = new ErrorMessageParser(errorMsg, _baseDir);
                parser.Parse();
                return(StandardOutputTestResultParser.CreateFailedTestResult(
                           testCase,
                           StandardOutputTestResultParser.ParseDuration(line, _logger),
                           parser.ErrorMessage,
                           parser.ErrorStackTrace));
            }
            if (StandardOutputTestResultParser.IsPassedLine(line))
            {
                return(StandardOutputTestResultParser.CreatePassedTestResult(
                           testCase,
                           StandardOutputTestResultParser.ParseDuration(line, _logger)));
            }

            CrashedTestCase = testCase;
            string message = StandardOutputTestResultParser.CrashText;

            message += errorMsg == "" ? "" : $"\nTest output:\n\n{errorMsg}";
            TestResult result = StandardOutputTestResultParser.CreateFailedTestResult(
                testCase,
                TimeSpan.FromMilliseconds(0),
                message,
                "");

            return(result);
        }
        private TestResult ParseTestResult(XmlNode testcaseNode)
        {
            string qualifiedName = GetQualifiedName(testcaseNode);

            TestCase testCase;
            if (!_testCasesMap.TryGetValue(qualifiedName, out testCase))
                return null;

            var testResult = new TestResult(testCase)
            {
                ComputerName = Environment.MachineName,
                DisplayName = testCase.DisplayName
            };

            string duration = testcaseNode.Attributes["time"].InnerText;
            testResult.Duration = ParseDuration(duration);

            string testCaseStatus = testcaseNode.Attributes["status"].InnerText;
            switch (testCaseStatus)
            {
                case "run":
                    XmlNodeList failureNodes = testcaseNode.SelectNodes("failure");
                    if (failureNodes.Count == 0)
                    {
                        testResult.Outcome = TestOutcome.Passed;
                    }
                    else
                    {
                        var parser = new ErrorMessageParser(failureNodes, _baseDir);
                        parser.Parse();
                        testResult.Outcome = TestOutcome.Failed;
                        testResult.ErrorMessage = parser.ErrorMessage;
                        testResult.ErrorStackTrace = parser.ErrorStackTrace;
                    }
                    break;
                case "notrun":
                    testResult.Outcome = TestOutcome.Skipped;
                    break;
                default:
                    string msg = "Unknown testcase status: " + testCaseStatus;
                    _testEnvironment.LogError(msg);
                    throw new Exception(msg);
            }

            return testResult;
        }
        private TestResult CreateTestResult()
        {
            int currentLineIndex = 0;

            while (currentLineIndex < _consoleOutput.Count &&
                   !IsRunLine(_consoleOutput[currentLineIndex]))
            {
                currentLineIndex++;
            }

            if (currentLineIndex == _consoleOutput.Count)
            {
                return(null);
            }

            string   line = _consoleOutput[currentLineIndex++];
            string   qualifiedTestname = RemovePrefix(line).Trim();
            TestCase testCase          = FindTestcase(qualifiedTestname, _testCasesRun);

            if (testCase == null)
            {
                _logger.DebugWarning(String.Format(Resources.NoKnownTestCaseMessage, line));
                return(null);
            }

            if (currentLineIndex == _consoleOutput.Count)
            {
                CrashedTestCase = testCase;
                return(CreateFailedTestResult(
                           testCase,
                           TimeSpan.FromMilliseconds(0),
                           CrashText,
                           ""));
            }

            line = _consoleOutput[currentLineIndex++];

            string errorMsg = "";

            while (!(IsFailedLine(line) || IsPassedLine(line) || IsSkippedLine(line)) &&
                   currentLineIndex <= _consoleOutput.Count)
            {
                errorMsg += line + "\n";
                line      = currentLineIndex < _consoleOutput.Count ? _consoleOutput[currentLineIndex] : "";
                currentLineIndex++;
            }
            if (IsFailedLine(line))
            {
                ErrorMessageParser parser = new ErrorMessageParser(errorMsg);
                parser.Parse();
                return(CreateFailedTestResult(
                           testCase,
                           ParseDuration(line, _logger),
                           parser.ErrorMessage,
                           parser.ErrorStackTrace));
            }
            if (IsPassedLine(line))
            {
                return(CreatePassedTestResult(testCase, ParseDuration(line, _logger)));
            }
            if (IsSkippedLine(line))
            {
                return(CreateSkippedTestResult(testCase, ParseDuration(line, _logger)));
            }

            CrashedTestCase = testCase;
            string message = CrashText;

            message += errorMsg == "" ? "" : ("\n" + Resources.TestOutput + $"\n\n{errorMsg}");
            TestResult result = CreateFailedTestResult(
                testCase,
                TimeSpan.FromMilliseconds(0),
                message,
                "");

            return(result);
        }