From 19b26cc6fd36c390d37a2c2fefceb31fd79d2bb9 Mon Sep 17 00:00:00 2001 From: Christian Soltenborn Date: Sat, 2 Feb 2019 10:52:17 +0100 Subject: [PATCH 1/2] added preliminary support for new gtest macro GTEST_SKIP() (not yet released) --- .../StandardOutputTestResultParserTests.cs | 56 ++++++++++++++++ ...mingStandardOutputTestResultParserTests.cs | 65 ++++++++++++++++++- .../TestResults/XmlTestResultParserTests.cs | 2 +- .../StandardOutputTestResultParser.cs | 23 ++++++- ...StreamingStandardOutputTestResultParser.cs | 9 ++- 5 files changed, 150 insertions(+), 5 deletions(-) diff --git a/GoogleTestAdapter/Core.Tests/TestResults/StandardOutputTestResultParserTests.cs b/GoogleTestAdapter/Core.Tests/TestResults/StandardOutputTestResultParserTests.cs index ab0a51f1f..03fbf548e 100644 --- a/GoogleTestAdapter/Core.Tests/TestResults/StandardOutputTestResultParserTests.cs +++ b/GoogleTestAdapter/Core.Tests/TestResults/StandardOutputTestResultParserTests.cs @@ -102,6 +102,34 @@ public class StandardOutputTestResultParserTests : TestsBase @"[ PASSED ] 2 test.", }; + /// + /// + /// + private string[] ConsoleOutputWithSkippedTest { get; } = @"[==========] Running 3 tests from 1 test suite. +[----------] Global test environment set-up. +[----------] 3 tests from Test +[ RUN ] Test.Succeed +[ OK ] Test.Succeed (0 ms) +[ RUN ] Test.Skip +[ SKIPPED ] Test.Skip (1 ms) +[ RUN ] Test.Fail +C:\...\test.cpp(14): error: Value of: false + Actual: false +Expected: true +[ FAILED ] Test.Fail (0 ms) +[----------] 3 tests from Test (3 ms total) + +[----------] Global test environment tear-down +[==========] 3 tests from 1 test suite ran. (6 ms total) +[ PASSED ] 1 test. +[ SKIPPED ] 1 test, listed below: +[ SKIPPED ] Test.Skip +[ FAILED ] 1 test, listed below: +[ FAILED ] Test.Fail + + 1 FAILED TEST +".Split('\n'); + private List CrashesImmediately { get; set; } private List CrashesAfterErrorMsg { get; set; } @@ -276,6 +304,34 @@ public void GetTestResults_OutputWithPrefixingTest_BothTestsAreFound() XmlTestResultParserTests.AssertTestResultIsPassed(results[1]); } + [TestMethod] + [TestCategory(Unit)] + public void GetTestResults_OutputWithSkippedTest_AllResultsAreFound() + { + var cases = new List + { + TestDataCreator.ToTestCase("Test.Succeed", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"), + TestDataCreator.ToTestCase("Test.Skip", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"), + TestDataCreator.ToTestCase("Test.Fail", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"), + }; + + var results = new StandardOutputTestResultParser(cases, ConsoleOutputWithSkippedTest, TestEnvironment.Logger).GetTestResults(); + + results.Should().HaveCount(3); + + var result = results[0]; + result.TestCase.FullyQualifiedName.Should().Be("Test.Succeed"); + XmlTestResultParserTests.AssertTestResultIsPassed(result); + + result = results[1]; + result.TestCase.FullyQualifiedName.Should().Be("Test.Skip"); + XmlTestResultParserTests.AssertTestResultIsSkipped(result); + + result = results[2]; + result.TestCase.FullyQualifiedName.Should().Be("Test.Fail"); + XmlTestResultParserTests.AssertTestResultIsFailure(result); + } + [TestMethod] [TestCategory(Unit)] public void OutputHandling_OutputManyLinesWithNewlines_IsParsedCorrectly() diff --git a/GoogleTestAdapter/Core.Tests/TestResults/StreamingStandardOutputTestResultParserTests.cs b/GoogleTestAdapter/Core.Tests/TestResults/StreamingStandardOutputTestResultParserTests.cs index 9793c055a..6b3c25422 100644 --- a/GoogleTestAdapter/Core.Tests/TestResults/StreamingStandardOutputTestResultParserTests.cs +++ b/GoogleTestAdapter/Core.Tests/TestResults/StreamingStandardOutputTestResultParserTests.cs @@ -114,6 +114,34 @@ public class StreamingStandardOutputTestResultParserTests : TestsBase @"[ PASSED ] 2 test.", }; + /// + /// + /// + private string[] ConsoleOutputWithSkippedTest { get; } = @"[==========] Running 3 tests from 1 test suite. +[----------] Global test environment set-up. +[----------] 3 tests from Test +[ RUN ] Test.Succeed +[ OK ] Test.Succeed (0 ms) +[ RUN ] Test.Skip +[ SKIPPED ] Test.Skip (1 ms) +[ RUN ] Test.Fail +C:\...\test.cpp(14): error: Value of: false + Actual: false +Expected: true +[ FAILED ] Test.Fail (0 ms) +[----------] 3 tests from Test (3 ms total) + +[----------] Global test environment tear-down +[==========] 3 tests from 1 test suite ran. (6 ms total) +[ PASSED ] 1 test. +[ SKIPPED ] 1 test, listed below: +[ SKIPPED ] Test.Skip +[ FAILED ] 1 test, listed below: +[ FAILED ] Test.Fail + + 1 FAILED TEST +".Split('\n'); + private List CrashesImmediately { get; set; } private List CrashesAfterErrorMsg { get; set; } @@ -313,8 +341,10 @@ public void GetTestResults_OutputWithPrefixingTest_BothTestsAreFound() @"c:\users\chris\documents\visual studio 2015\projects\consoleapplication1\consoleapplication1tests\source.cpp") }; - var results = new StandardOutputTestResultParser(cases, ConsoleOutputWithPrefixingTest, TestEnvironment.Logger) - .GetTestResults(); + var parser = new StreamingStandardOutputTestResultParser(cases, TestEnvironment.Logger, MockFrameworkReporter.Object); + ConsoleOutputWithPrefixingTest.ToList().ForEach(parser.ReportLine); + parser.Flush(); + var results = parser.TestResults; results.Count.Should().Be(2); results[0].TestCase.FullyQualifiedName.Should().Be("Test.AB"); @@ -323,6 +353,37 @@ public void GetTestResults_OutputWithPrefixingTest_BothTestsAreFound() XmlTestResultParserTests.AssertTestResultIsPassed(results[1]); } + [TestMethod] + [TestCategory(Unit)] + public void GetTestResults_OutputWithSkippedTest_AllResultsAreFound() + { + var cases = new List + { + TestDataCreator.ToTestCase("Test.Succeed", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"), + TestDataCreator.ToTestCase("Test.Skip", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"), + TestDataCreator.ToTestCase("Test.Fail", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"), + }; + + var parser = new StreamingStandardOutputTestResultParser(cases, TestEnvironment.Logger, MockFrameworkReporter.Object); + ConsoleOutputWithSkippedTest.ToList().ForEach(parser.ReportLine); + parser.Flush(); + var results = parser.TestResults; + + results.Should().HaveCount(3); + + var result = results[0]; + result.TestCase.FullyQualifiedName.Should().Be("Test.Succeed"); + XmlTestResultParserTests.AssertTestResultIsPassed(result); + + result = results[1]; + result.TestCase.FullyQualifiedName.Should().Be("Test.Skip"); + XmlTestResultParserTests.AssertTestResultIsSkipped(result); + + result = results[2]; + result.TestCase.FullyQualifiedName.Should().Be("Test.Fail"); + XmlTestResultParserTests.AssertTestResultIsFailure(result); + } + [TestMethod] [TestCategory(Unit)] public void OutputHandling_OutputManyLinesWithNewlines_IsParsedCorrectly() diff --git a/GoogleTestAdapter/Core.Tests/TestResults/XmlTestResultParserTests.cs b/GoogleTestAdapter/Core.Tests/TestResults/XmlTestResultParserTests.cs index ae800120c..4eeb007b3 100644 --- a/GoogleTestAdapter/Core.Tests/TestResults/XmlTestResultParserTests.cs +++ b/GoogleTestAdapter/Core.Tests/TestResults/XmlTestResultParserTests.cs @@ -171,7 +171,7 @@ public static void AssertTestResultIsPassed(Model.TestResult testResult) testResult.ErrorMessage.Should().BeNull(); } - private void AssertTestResultIsSkipped(Model.TestResult testResult) + public static void AssertTestResultIsSkipped(Model.TestResult testResult) { testResult.Outcome.Should().Be(Model.TestOutcome.Skipped); testResult.ErrorMessage.Should().BeNull(); diff --git a/GoogleTestAdapter/Core/TestResults/StandardOutputTestResultParser.cs b/GoogleTestAdapter/Core/TestResults/StandardOutputTestResultParser.cs index 7e7bf0df3..db939da1b 100644 --- a/GoogleTestAdapter/Core/TestResults/StandardOutputTestResultParser.cs +++ b/GoogleTestAdapter/Core/TestResults/StandardOutputTestResultParser.cs @@ -15,6 +15,7 @@ public class StandardOutputTestResultParser private const string Run = "[ RUN ]"; public const string Failed = "[ FAILED ]"; public const string Passed = "[ OK ]"; + public const string Skipped = "[ SKIPPED ]"; public const string FailedFixture = "SetUpTestSuite or TearDownTestSuite"; public static readonly string CrashText = Resources.CrashText; @@ -80,7 +81,7 @@ private TestResult CreateTestResult(int indexOfTestcase) string errorMsg = ""; - while (!(IsFailedLine(line) || IsPassedLine(line)) && currentLineIndex <= _consoleOutput.Count) + while (!(IsFailedLine(line) || IsPassedLine(line) || IsSkippedLine(line)) && currentLineIndex <= _consoleOutput.Count) { errorMsg += line + "\n"; line = currentLineIndex < _consoleOutput.Count ? _consoleOutput[currentLineIndex] : ""; @@ -97,6 +98,10 @@ private TestResult CreateTestResult(int indexOfTestcase) { return CreatePassedTestResult(testCase, ParseDuration(line)); } + if (IsSkippedLine(line)) + { + return CreateSkippedTestResult(testCase, ParseDuration(line)); + } CrashedTestCase = testCase; string message = CrashText; @@ -163,6 +168,17 @@ public static TestResult CreatePassedTestResult(TestCase testCase, TimeSpan dura }; } + public static TestResult CreateSkippedTestResult(TestCase testCase, TimeSpan duration) + { + return new TestResult(testCase) + { + ComputerName = Environment.MachineName, + DisplayName = testCase.DisplayName, + Outcome = TestOutcome.Skipped, + Duration = duration + }; + } + public static TestResult CreateFailedTestResult(TestCase testCase, TimeSpan duration, string errorMessage, string errorStackTrace) { return new TestResult(testCase) @@ -215,6 +231,11 @@ public static bool IsFailedLine(string line) return line.StartsWith(Failed, StringComparison.Ordinal); } + public static bool IsSkippedLine(string line) + { + return line.StartsWith(Skipped); + } + public static string RemovePrefix(string line) { return line.Substring(Run.Length); diff --git a/GoogleTestAdapter/Core/TestResults/StreamingStandardOutputTestResultParser.cs b/GoogleTestAdapter/Core/TestResults/StreamingStandardOutputTestResultParser.cs index b38de8583..9b9c9a737 100644 --- a/GoogleTestAdapter/Core/TestResults/StreamingStandardOutputTestResultParser.cs +++ b/GoogleTestAdapter/Core/TestResults/StreamingStandardOutputTestResultParser.cs @@ -177,7 +177,8 @@ private TestResult CreateTestResult() string errorMsg = ""; while ( !(StandardOutputTestResultParser.IsFailedLine(line) - || StandardOutputTestResultParser.IsPassedLine(line)) + || StandardOutputTestResultParser.IsPassedLine(line) + || StandardOutputTestResultParser.IsSkippedLine(line)) && currentLineIndex <= _consoleOutput.Count) { errorMsg += line + "\n"; @@ -229,6 +230,12 @@ private TestResult CreateTestResult() testCase, StandardOutputTestResultParser.ParseDuration(line, _logger)); } + if (StandardOutputTestResultParser.IsSkippedLine(line)) + { + return StandardOutputTestResultParser.CreateSkippedTestResult( + testCase, + StandardOutputTestResultParser.ParseDuration(line, _logger)); + } CrashedTestCase = testCase; string message = StandardOutputTestResultParser.CrashText; From 6925952f9649148005b3fff480477f4ead0c05a2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Boivin Date: Thu, 8 May 2025 15:25:26 -0400 Subject: [PATCH 2/2] Adapt Streaming tests to Microsoft fork --- .../StreamingStandardOutputTestResultParserTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GoogleTestAdapter/Core.Tests/TestResults/StreamingStandardOutputTestResultParserTests.cs b/GoogleTestAdapter/Core.Tests/TestResults/StreamingStandardOutputTestResultParserTests.cs index 6b3c25422..ec7148db0 100644 --- a/GoogleTestAdapter/Core.Tests/TestResults/StreamingStandardOutputTestResultParserTests.cs +++ b/GoogleTestAdapter/Core.Tests/TestResults/StreamingStandardOutputTestResultParserTests.cs @@ -341,7 +341,7 @@ public void GetTestResults_OutputWithPrefixingTest_BothTestsAreFound() @"c:\users\chris\documents\visual studio 2015\projects\consoleapplication1\consoleapplication1tests\source.cpp") }; - var parser = new StreamingStandardOutputTestResultParser(cases, TestEnvironment.Logger, MockFrameworkReporter.Object); + var parser = new StreamingStandardOutputTestResultParser(cases, MockLogger.Object, MockFrameworkReporter.Object, String.Empty); ConsoleOutputWithPrefixingTest.ToList().ForEach(parser.ReportLine); parser.Flush(); var results = parser.TestResults; @@ -364,7 +364,7 @@ public void GetTestResults_OutputWithSkippedTest_AllResultsAreFound() TestDataCreator.ToTestCase("Test.Fail", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"), }; - var parser = new StreamingStandardOutputTestResultParser(cases, TestEnvironment.Logger, MockFrameworkReporter.Object); + var parser = new StreamingStandardOutputTestResultParser(cases, MockLogger.Object, MockFrameworkReporter.Object, String.Empty); ConsoleOutputWithSkippedTest.ToList().ForEach(parser.ReportLine); parser.Flush(); var results = parser.TestResults;