Skip to content

Commit

Permalink
Show the WARN and INFO message in the test output.
Browse files Browse the repository at this point in the history
  • Loading branch information
xkbeyer committed Jul 28, 2018
1 parent 17c6467 commit b218f6c
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 32 deletions.
8 changes: 4 additions & 4 deletions TestAdapter/CatchTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public Expression[] Expressions {
get { return _expressions; }
set { if (value != null) _expressions = value; }
}
[XmlElement("Warning")]
public string Warning { get; set; } = "";
[XmlElement("Info")]
public string Info { get; set; } = "";
[XmlElement("Warning", typeof(string))]
public string[] Warning { get; set; } = new string[] { };
[XmlElement("Info",typeof(string))]
public string[] Info { get; set; } = new string[] { };
[XmlElement("Failure", typeof(Failure))]
public Failure Failure { get; set; }
[XmlElement("Section", typeof(TestCase))]
Expand Down
33 changes: 33 additions & 0 deletions TestAdapter/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,34 @@ void TryGetFailure(Tests.TestCase element, string name)
}
}

if( element.Warning != null )
{
foreach (var s in element.Warning)
{
var res = new FlatResult()
{
SectionPath = name,
Expression = $"WARN: {s.Trim()}{ Environment.NewLine }",
FilePath = TestDiscoverer.ResolvePath(element.Filename, SolutionDirectory)
};
result.Add(res);
}
}

if (element.Info != null)
{
foreach(var s in element.Info)
{
var res = new FlatResult()
{
SectionPath = name,
Expression = $"INFO: {s.Trim()}{ Environment.NewLine }",
FilePath = TestDiscoverer.ResolvePath(element.Filename, SolutionDirectory)
};
result.Add(res);
}
}

// Try to find the failure from a subsection of this element.
foreach (var section in element.Sections)
{
Expand Down Expand Up @@ -213,6 +241,11 @@ protected virtual void ComposeResults(IList<string> output_text, IList<TestCase>
for (int i = 1; i <= failures.Count; ++i)
{
var failure = failures[i - 1];
if (failure.Expression.Contains("WARN:") || failure.Expression.Contains("INFO:"))
{
testResult.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, failure.Expression));
continue;
}
// Populate the error message.
var newline = failure.SectionPath.IndexOf("\n");
if (newline != -1)
Expand Down
2 changes: 1 addition & 1 deletion TestAdapterTest/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ static class Common
public static List<string> ReferenceExeList { get; } = new List<String>() { ReferenceExe };

// The number of tests in the reference project.
public const int ReferenceTestCount = 4;
public const int ReferenceTestCount = 6;
}
}
66 changes: 40 additions & 26 deletions TestAdapterTest/ReferenceCatchProject/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,55 @@
#include "catch.hpp"

// Test case with no tags.
TEST_CASE( "No tags" )
TEST_CASE("No tags")
{
SECTION( "Success" )
{
REQUIRE( true );
}
SECTION("Success")
{
REQUIRE(true);
}
}


// Test case with tags.
TEST_CASE( "With tags", "[tag][neat]" )
TEST_CASE("With tags", "[tag][neat]")
{
SECTION( "Success" )
{
REQUIRE( true );
}
SECTION("Success")
{
REQUIRE(true);
}
}

TEST_CASE( "Has failure", "[tag]" )
TEST_CASE("Has failure", "[tag]")
{
SECTION( "First works" )
{
REQUIRE( true );
}

SECTION( "Second fails" )
{
REQUIRE( false );
}
SECTION("First works")
{
REQUIRE(true);
}

SECTION("Second fails")
{
REQUIRE(false);
}
}

TEST_CASE("Has forced failure", "[tag]")
{
SECTION("Forced failure section")
{
FAIL("This message should be in the failure report.");
}
}

TEST_CASE( "Has forced failure", "[tag]" )
TEST_CASE("Warn", "[Logging]")
{
SECTION( "Forced failure section" )
{
FAIL( "This message should be in the failure report." );
}
}
WARN("This is a warning message"); // Always logged
CHECK(false); // to see something in TestExplorer
}

TEST_CASE("Info", "[Logging]")
{
INFO("This is a info message");
CHECK(false); // Info is logged here
INFO("This info message is not displayed"); // This one is ignored
CHECK(true);
}
31 changes: 31 additions & 0 deletions TestAdapterTest/TestTestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,37 @@ public void ForcedFailureHasMessage()
Assert.IsTrue( forcedFailure.ErrorMessage.Contains( "This message should be in the failure report." ) );
}

[TestMethod]
public void WarningAndInfoMessage()
{
// Set up a fake testing context.
var framework = new MockFrameworkHandle();

// Execute all tests.
TestExecutor executor = new TestExecutor();
executor.RunTests(Common.ReferenceExeList, new MockRunContext(), framework);

// Map the tests by name.
Dictionary<string, TestResult> resultsByName = new Dictionary<string, TestResult>();
foreach (var result in framework.Results)
{
resultsByName[result.TestCase.FullyQualifiedName] = result;
}

TestResult testResult = resultsByName["Warn"];
Assert.AreEqual(TestOutcome.Failed, testResult.Outcome);
Assert.IsTrue(testResult.ErrorMessage.Contains("#1 - CHECK(false) with expansion: (false)"));
Assert.AreEqual(1, testResult.Messages.Count);
Assert.IsTrue(testResult.Messages[0].Text.Contains("WARN: This is a warning message"));

testResult = resultsByName["Info"];
Assert.AreEqual(TestOutcome.Failed, testResult.Outcome);
Assert.IsTrue(testResult.ErrorMessage.Contains("#1 - CHECK(false) with expansion: (false)"));
Assert.AreEqual(1, testResult.Messages.Count);
Assert.IsTrue(testResult.Messages[0].Text.Contains("INFO: This is a info message"));

}

[TestMethod]
public void BrokenXmlWithSingleTest()
{
Expand Down
2 changes: 1 addition & 1 deletion source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="CatchTestAdapter.xkBeyer.f56db3ea-257e-4f65-a52c-a6160aa8e329" Version="1.4.2" Language="en-US" Publisher="xkbeyer" />
<Identity Id="CatchTestAdapter.xkBeyer.f56db3ea-257e-4f65-a52c-a6160aa8e329" Version="1.4.3" Language="en-US" Publisher="xkbeyer" />
<DisplayName>CatchTestAdapter</DisplayName>
<Description xml:space="preserve">Test Adapter for the Catch C++ unit test framework</Description>
<License>LICENSE.txt</License>
Expand Down

0 comments on commit b218f6c

Please sign in to comment.