Skip to content

Commit

Permalink
Improves how is dealt with problematic test case names.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyHendriks committed Sep 17, 2018
1 parent 682c59b commit 0086d4e
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 109 deletions.
1 change: 1 addition & 0 deletions Docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changes are relative to v1.0.0
### Extended Features

- Improve Additional info output with respect to section. Is now more like standard Catch2 output.
- Improve how is dealt with problematic test case names. Tests with such names are now marked as skipped, with an error message that suggests a possible solution.

### Bug fixes

Expand Down
4 changes: 3 additions & 1 deletion Docs/Capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ Here `<Category>` may have several "." delimiters. This scheme helps me to keep

### Special characters

Be aware that trailing spaces are automatically removed from a test case name. Also, names ending in a backslash ("\\") cannot be called specifically by the **Test Adapter for Catch2**. As of v1.3.0 a workaround is used where basically the backslashes are stripped from the end of the name. Subsequently all tests that start with the remaining test name are called. So there is a chance more than one test case will be called. This is handled in the same way as test case names that differ only in case (see [below](#catch2-specific)).
Be aware that names ending in a backslash ("\\") cannot be called specifically by the **Test Adapter for Catch2**. As of v1.3.0 a workaround is used where basically the backslashes are stripped from the end of the name. Subsequently all tests that start with the remaining test name are called. So there is a chance more than one test case will be called. This is handled in the same way as test case names that differ only in case (see [below](#catch2-specific)).

If you want to call a specific test case from the command line you need to escape any comma, double quote, open square bracket and backslash characters (_i.e._, use "\\,", "\\"", "\\[" and "\\\\"). This is basically what the **Test Adapter for Catch2** does internally when it calls a test. Otherwise any printable ASCII character can be safely used in a test case name. No guarantees are given for the use of other characters (_e.g._, UTF-8).

During test case name discovery trailing spaces are automatically removed from a test case name. Consequently, test cases with names that end in a space character cannot be specifically run by the **Test Adapter for Catch2**.

### Catch2 specific

Test case names are semi case sensitive. Test cases which only differ in case are separate test cases as far as Catch2 is concerned. However, they cannot be called individually via the command line. As such, when such a test is called, all tests with the same case insensitive name are run. As of version 1.3 of the **Test Adapter for Catch2** this situation is handled more gracefully and at least the correct test results is shown for the test case. The assertion statistics shown for the test case are those of all the run tests, including the ones with only differ in case. As a result, it is possible that a passed test case contains failed assertions in the shown assertion statistics. For clarity a note is added to the test case result message to indicate this. Before version 1.3 of the **Test Adapter for Catch2** this corner case was not handled well and therefore could report the wrong result for those test cases.
2 changes: 1 addition & 1 deletion Libraries/Catch2Interface/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public TestResult Run(string testname, string source)
LogDebug(output.Result);
Log = _logbuilder.ToString();

// Process testrun output (should have result from a single testcase)
// Process testrun output
return new TestResult(output.Result, testname, _settings);
}
}
Expand Down
65 changes: 45 additions & 20 deletions Libraries/Catch2Interface/TestResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
namespace Catch2Interface
{

/*YAML
Enum :
Description : >
This enum represents the test result outcomes.
*/
public enum TestOutcomes
{
Cancelled,
Failed,
Passed,
Skipped,
Timedout
}

/*YAML
Class :
Description : >
Expand Down Expand Up @@ -53,7 +67,7 @@ public class TestResult

public TestResult()
{
Cancelled = true;
Outcome = TestOutcomes.Cancelled;
}

public TestResult(string xmloutput, string testname, Settings settings)
Expand All @@ -68,8 +82,8 @@ public TestResult( TimeSpan duration
, string msg
, string standardout )
{
TimedOut = true;
Duration = duration;
Outcome = TestOutcomes.Timedout;
StandardOut = standardout;
}
#endregion // Costructor
Expand All @@ -87,10 +101,7 @@ public TestResult( TimeSpan duration
public string StandardOut { get; private set; }
public string StandardError { get; private set; }

public bool Cancelled { get; private set; } = false;
public bool TimedOut { get; private set; } = false;

public bool Success { get; private set; } = false;
public TestOutcomes Outcome { get; private set; }

#endregion // Properties

Expand Down Expand Up @@ -365,25 +376,39 @@ void ExtractTestResult(XmlNode nodeGroup)
var nodesTestCases = nodeGroup.SelectNodes("TestCase");

_testcasecount = nodesTestCases.Count;
foreach (XmlNode nodeTestCase in nodesTestCases)

if(_testcasecount == 0)
{
var testcase = new Reporter.TestCase(nodeTestCase);
if(_testcasecount != 1 && testcase.Name != _testname) continue;
// Special case. It appears the used test case name could not be found by Catch2.
// As such the test case is effectively skipped.
// This is an edge case that can typically be resolved by changing the test case name.
// So tell the user about it.
Outcome = TestOutcomes.Skipped;
ErrorMessage = $"Testcase could not be run. Probably the used testcase name is the cause. Change the testcase name and try again. Typically, this problem is encountered when the last character of the testcase name is a space.";
return;
}
else
{
foreach (XmlNode nodeTestCase in nodesTestCases)
{
var testcase = new Reporter.TestCase(nodeTestCase);
if(_testcasecount != 1 && testcase.Name != _testname) continue;

_testcase = testcase;
_testcase = testcase;

Success = _testcase.OverallResult.Success;
Duration = _testcase.OverallResult.Duration;
StandardOut = _testcase.OverallResult.StdOut;
StandardError = _testcase.OverallResult.StdErr;
Outcome = _testcase.OverallResult.Success ? TestOutcomes.Passed : TestOutcomes.Failed;
Duration = _testcase.OverallResult.Duration;
StandardOut = _testcase.OverallResult.StdOut;
StandardError = _testcase.OverallResult.StdErr;

ExtractMessages();
ExtractMessages();

// Statistics
ExtractOverallResults(nodeGroup);
// Statistics
ExtractOverallResults(nodeGroup);

GenerateMessages();
return;
GenerateMessages();
return;
}
}

SetInvalidTestRunnerOutput();
Expand Down Expand Up @@ -475,7 +500,7 @@ private string GenerateAssertionInfo()
}
private void SetInvalidTestRunnerOutput()
{
Success = false;
Outcome = TestOutcomes.Failed;
OverallResults = new Reporter.OverallResults();
ErrorMessage = $"Invalid test runner output.{Environment.NewLine}"
+ $"-------------------------------------------------------------------------------{Environment.NewLine}"
Expand Down
75 changes: 43 additions & 32 deletions Libraries/Catch2TestAdapter/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,39 +201,50 @@ private TestResult RunTest(TestCase test)
}

// Process test results
if( testresult.TimedOut )
switch (testresult.Outcome)
{
LogVerbose(TestMessageLevel.Warning, "Time out");
result.Outcome = TestOutcome.Skipped;
result.ErrorMessage = testresult.ErrorMessage;
result.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, testresult.StandardOut));
result.Duration = testresult.Duration;
}
else if( testresult.Cancelled )
{
result.Outcome = TestOutcome.None;
}
else
{
result.Outcome = testresult.Success ? TestOutcome.Passed : TestOutcome.Failed;
result.Duration = testresult.Duration;
result.ErrorMessage = testresult.ErrorMessage;
result.ErrorStackTrace = testresult.ErrorStackTrace;

if( !string.IsNullOrEmpty(testresult.StandardOut) )
{
result.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, testresult.StandardOut ));
}

if( !string.IsNullOrEmpty(testresult.StandardError) )
{
result.Messages.Add(new TestResultMessage(TestResultMessage.StandardErrorCategory, testresult.StandardError ));
}

if( !string.IsNullOrEmpty(testresult.AdditionalInfo) )
{
result.Messages.Add(new TestResultMessage(TestResultMessage.AdditionalInfoCategory, testresult.AdditionalInfo ));
}
case Catch2Interface.TestOutcomes.Timedout:
LogVerbose(TestMessageLevel.Warning, "Time out");
result.Outcome = TestOutcome.Skipped;
result.ErrorMessage = testresult.ErrorMessage;
result.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, testresult.StandardOut));
result.Duration = testresult.Duration;
break;
case Catch2Interface.TestOutcomes.Cancelled:
result.Outcome = TestOutcome.None;
break;
case Catch2Interface.TestOutcomes.Skipped:
result.Outcome = TestOutcome.Skipped;
result.ErrorMessage = testresult.ErrorMessage;
break;
default:
if( testresult.Outcome == Catch2Interface.TestOutcomes.Passed)
{
result.Outcome = TestOutcome.Passed;
}
else
{
result.Outcome = TestOutcome.Failed;
}
result.Duration = testresult.Duration;
result.ErrorMessage = testresult.ErrorMessage;
result.ErrorStackTrace = testresult.ErrorStackTrace;

if (!string.IsNullOrEmpty(testresult.StandardOut))
{
result.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, testresult.StandardOut));
}

if (!string.IsNullOrEmpty(testresult.StandardError))
{
result.Messages.Add(new TestResultMessage(TestResultMessage.StandardErrorCategory, testresult.StandardError));
}

if (!string.IsNullOrEmpty(testresult.AdditionalInfo))
{
result.Messages.Add(new TestResultMessage(TestResultMessage.AdditionalInfoCategory, testresult.AdditionalInfo));
}
break;
}
}

Expand Down
Loading

0 comments on commit 0086d4e

Please sign in to comment.