Skip to content

Commit

Permalink
Merge pull request #262 from csoltenborn/#260_GTEST_SKIP
Browse files Browse the repository at this point in the history
added preliminary support for new gtest macro GTEST_SKIP()
  • Loading branch information
csoltenborn authored Feb 5, 2019
2 parents bf2bcaf + a725f05 commit bee333f
Show file tree
Hide file tree
Showing 19 changed files with 580 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,62 @@ public class StandardOutputTestResultParserTests : TestsBase
@"[ PASSED ] 2 test.",
};

/// <summary>
/// <see cref="https://github.com/csoltenborn/GoogleTestAdapter/issues/260"/>
/// </summary>
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');

/// <summary>
/// <see cref="https://github.com/csoltenborn/GoogleTestAdapter/issues/260"/>
/// </summary>
private string[] ConsoleOutputWithSkippedTestAsLastTest { 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.Fail
C:\...\test.cpp(14): error: Value of: false
Actual: false
Expected: true
[ FAILED ] Test.Fail (0 ms)
[ RUN ] Test.Skip
[ SKIPPED ] Test.Skip (1 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<string> CrashesImmediately { get; set; }
private List<string> CrashesAfterErrorMsg { get; set; }
Expand Down Expand Up @@ -139,7 +195,7 @@ public override void SetUp()
[TestCategory(Unit)]
public void GetTestResults_CompleteOutput_ParsedCorrectly()
{
List<TestResult> results = ComputeTestResults(Complete);
var results = ComputeTestResults(Complete);

results.Should().HaveCount(3);

Expand All @@ -165,7 +221,7 @@ public void GetTestResults_CompleteOutput_ParsedCorrectly()
[TestCategory(Unit)]
public void GetTestResults_OutputWithImmediateCrash_CorrectResultHasCrashText()
{
List<TestResult> results = ComputeTestResults(CrashesImmediately);
var results = ComputeTestResults(CrashesImmediately);

results.Should().HaveCount(2);

Expand All @@ -186,7 +242,7 @@ public void GetTestResults_OutputWithImmediateCrash_CorrectResultHasCrashText()
[TestCategory(Unit)]
public void GetTestResults_OutputWithCrashAfterErrorMessage_CorrectResultHasCrashText()
{
List<TestResult> results = ComputeTestResults(CrashesAfterErrorMsg);
var results = ComputeTestResults(CrashesAfterErrorMsg);

results.Should().HaveCount(3);

Expand All @@ -212,7 +268,7 @@ public void GetTestResults_OutputWithCrashAfterErrorMessage_CorrectResultHasCras
[TestCategory(Unit)]
public void GetTestResults_OutputWithInvalidDurationUnit_DefaultDurationIsUsedAndWarningIsProduced()
{
List<TestResult> results = ComputeTestResults(WrongDurationUnit);
var results = ComputeTestResults(WrongDurationUnit);

results.Should().ContainSingle();
results[0].TestCase.FullyQualifiedName.Should().Be("TestMath.AddFails");
Expand All @@ -231,7 +287,7 @@ public void GetTestResults_OutputWithThousandsSeparatorInDuration_ParsedCorrectl
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
try
{
List<TestResult> results = ComputeTestResults(ThousandsSeparatorInDuration);
var results = ComputeTestResults(ThousandsSeparatorInDuration);

results.Should().ContainSingle();
results[0].TestCase.FullyQualifiedName.Should().Be("TestMath.AddFails");
Expand All @@ -247,7 +303,7 @@ public void GetTestResults_OutputWithThousandsSeparatorInDuration_ParsedCorrectl
[TestCategory(Unit)]
public void GetTestResults_OutputWithConsoleOutput_ConsoleOutputIsIgnored()
{
List<TestResult> results = ComputeTestResults(PassingTestProducesConsoleOutput);
var results = ComputeTestResults(PassingTestProducesConsoleOutput);

results.Should().ContainSingle();
results[0].TestCase.FullyQualifiedName.Should().Be("TestMath.AddPasses");
Expand Down Expand Up @@ -276,6 +332,62 @@ public void GetTestResults_OutputWithPrefixingTest_BothTestsAreFound()
XmlTestResultParserTests.AssertTestResultIsPassed(results[1]);
}

[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_OutputWithSkippedTest_AllResultsAreFound()
{
var cases = new List<TestCase>
{
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 GetTestResults_OutputWithSkippedTestAsLastTest_AllResultsAreFound()
{
var cases = new List<TestCase>
{
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, ConsoleOutputWithSkippedTestAsLastTest, 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.Fail");
XmlTestResultParserTests.AssertTestResultIsFailure(result);

result = results[2];
result.TestCase.FullyQualifiedName.Should().Be("Test.Skip");
XmlTestResultParserTests.AssertTestResultIsSkipped(result);
}

[TestMethod]
[TestCategory(Unit)]
public void OutputHandling_OutputManyLinesWithNewlines_IsParsedCorrectly()
Expand Down Expand Up @@ -357,7 +469,7 @@ private IList<TestResult> GetTestResultsFromCompleteOutputFile()
}


private List<TestResult> ComputeTestResults(List<string> consoleOutput)
private IList<TestResult> ComputeTestResults(List<string> consoleOutput)
{
var cases = new List<TestCase>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,62 @@ public class StreamingStandardOutputTestResultParserTests : TestsBase
@"[ PASSED ] 2 test.",
};

/// <summary>
/// <see cref="https://github.com/csoltenborn/GoogleTestAdapter/issues/260"/>
/// </summary>
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');

/// <summary>
/// <see cref="https://github.com/csoltenborn/GoogleTestAdapter/issues/260"/>
/// </summary>
private string[] ConsoleOutputWithSkippedTestAsLastTest { 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.Fail
C:\...\test.cpp(14): error: Value of: false
Actual: false
Expected: true
[ FAILED ] Test.Fail (0 ms)
[ RUN ] Test.Skip
[ SKIPPED ] Test.Skip (1 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<string> CrashesImmediately { get; set; }
private List<string> CrashesAfterErrorMsg { get; set; }
Expand Down Expand Up @@ -312,8 +368,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.Should().HaveCount(2);
results[0].TestCase.FullyQualifiedName.Should().Be("Test.AB");
Expand All @@ -322,6 +380,68 @@ public void GetTestResults_OutputWithPrefixingTest_BothTestsAreFound()
XmlTestResultParserTests.AssertTestResultIsPassed(results[1]);
}

[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_OutputWithSkippedTest_AllResultsAreFound()
{
var cases = new List<TestCase>
{
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 GetTestResults_OutputWithSkippedTestAsLastTest_AllResultsAreFound()
{
var cases = new List<TestCase>
{
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);
ConsoleOutputWithSkippedTestAsLastTest.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.Fail");
XmlTestResultParserTests.AssertTestResultIsFailure(result);

result = results[2];
result.TestCase.FullyQualifiedName.Should().Be("Test.Skip");
XmlTestResultParserTests.AssertTestResultIsSkipped(result);
}

[TestMethod]
[TestCategory(Unit)]
public void OutputHandling_OutputManyLinesWithNewlines_IsParsedCorrectly()
Expand Down
Loading

0 comments on commit bee333f

Please sign in to comment.