Skip to content

Commit b218f6c

Browse files
committed
Show the WARN and INFO message in the test output.
1 parent 17c6467 commit b218f6c

File tree

6 files changed

+110
-32
lines changed

6 files changed

+110
-32
lines changed

TestAdapter/CatchTestCase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public Expression[] Expressions {
3434
get { return _expressions; }
3535
set { if (value != null) _expressions = value; }
3636
}
37-
[XmlElement("Warning")]
38-
public string Warning { get; set; } = "";
39-
[XmlElement("Info")]
40-
public string Info { get; set; } = "";
37+
[XmlElement("Warning", typeof(string))]
38+
public string[] Warning { get; set; } = new string[] { };
39+
[XmlElement("Info",typeof(string))]
40+
public string[] Info { get; set; } = new string[] { };
4141
[XmlElement("Failure", typeof(Failure))]
4242
public Failure Failure { get; set; }
4343
[XmlElement("Section", typeof(TestCase))]

TestAdapter/TestExecutor.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ void TryGetFailure(Tests.TestCase element, string name)
9393
}
9494
}
9595

96+
if( element.Warning != null )
97+
{
98+
foreach (var s in element.Warning)
99+
{
100+
var res = new FlatResult()
101+
{
102+
SectionPath = name,
103+
Expression = $"WARN: {s.Trim()}{ Environment.NewLine }",
104+
FilePath = TestDiscoverer.ResolvePath(element.Filename, SolutionDirectory)
105+
};
106+
result.Add(res);
107+
}
108+
}
109+
110+
if (element.Info != null)
111+
{
112+
foreach(var s in element.Info)
113+
{
114+
var res = new FlatResult()
115+
{
116+
SectionPath = name,
117+
Expression = $"INFO: {s.Trim()}{ Environment.NewLine }",
118+
FilePath = TestDiscoverer.ResolvePath(element.Filename, SolutionDirectory)
119+
};
120+
result.Add(res);
121+
}
122+
}
123+
96124
// Try to find the failure from a subsection of this element.
97125
foreach (var section in element.Sections)
98126
{
@@ -213,6 +241,11 @@ protected virtual void ComposeResults(IList<string> output_text, IList<TestCase>
213241
for (int i = 1; i <= failures.Count; ++i)
214242
{
215243
var failure = failures[i - 1];
244+
if (failure.Expression.Contains("WARN:") || failure.Expression.Contains("INFO:"))
245+
{
246+
testResult.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, failure.Expression));
247+
continue;
248+
}
216249
// Populate the error message.
217250
var newline = failure.SectionPath.IndexOf("\n");
218251
if (newline != -1)

TestAdapterTest/Common.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ static class Common
2222
public static List<string> ReferenceExeList { get; } = new List<String>() { ReferenceExe };
2323

2424
// The number of tests in the reference project.
25-
public const int ReferenceTestCount = 4;
25+
public const int ReferenceTestCount = 6;
2626
}
2727
}

TestAdapterTest/ReferenceCatchProject/Tests.cpp

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,55 @@
33
#include "catch.hpp"
44

55
// Test case with no tags.
6-
TEST_CASE( "No tags" )
6+
TEST_CASE("No tags")
77
{
8-
SECTION( "Success" )
9-
{
10-
REQUIRE( true );
11-
}
8+
SECTION("Success")
9+
{
10+
REQUIRE(true);
11+
}
1212
}
1313

1414

1515
// Test case with tags.
16-
TEST_CASE( "With tags", "[tag][neat]" )
16+
TEST_CASE("With tags", "[tag][neat]")
1717
{
18-
SECTION( "Success" )
19-
{
20-
REQUIRE( true );
21-
}
18+
SECTION("Success")
19+
{
20+
REQUIRE(true);
21+
}
2222
}
2323

24-
TEST_CASE( "Has failure", "[tag]" )
24+
TEST_CASE("Has failure", "[tag]")
2525
{
26-
SECTION( "First works" )
27-
{
28-
REQUIRE( true );
29-
}
30-
31-
SECTION( "Second fails" )
32-
{
33-
REQUIRE( false );
34-
}
26+
SECTION("First works")
27+
{
28+
REQUIRE(true);
29+
}
30+
31+
SECTION("Second fails")
32+
{
33+
REQUIRE(false);
34+
}
35+
}
36+
37+
TEST_CASE("Has forced failure", "[tag]")
38+
{
39+
SECTION("Forced failure section")
40+
{
41+
FAIL("This message should be in the failure report.");
42+
}
3543
}
3644

37-
TEST_CASE( "Has forced failure", "[tag]" )
45+
TEST_CASE("Warn", "[Logging]")
3846
{
39-
SECTION( "Forced failure section" )
40-
{
41-
FAIL( "This message should be in the failure report." );
42-
}
43-
}
47+
WARN("This is a warning message"); // Always logged
48+
CHECK(false); // to see something in TestExplorer
49+
}
50+
51+
TEST_CASE("Info", "[Logging]")
52+
{
53+
INFO("This is a info message");
54+
CHECK(false); // Info is logged here
55+
INFO("This info message is not displayed"); // This one is ignored
56+
CHECK(true);
57+
}

TestAdapterTest/TestTestExecutor.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,37 @@ public void ForcedFailureHasMessage()
103103
Assert.IsTrue( forcedFailure.ErrorMessage.Contains( "This message should be in the failure report." ) );
104104
}
105105

106+
[TestMethod]
107+
public void WarningAndInfoMessage()
108+
{
109+
// Set up a fake testing context.
110+
var framework = new MockFrameworkHandle();
111+
112+
// Execute all tests.
113+
TestExecutor executor = new TestExecutor();
114+
executor.RunTests(Common.ReferenceExeList, new MockRunContext(), framework);
115+
116+
// Map the tests by name.
117+
Dictionary<string, TestResult> resultsByName = new Dictionary<string, TestResult>();
118+
foreach (var result in framework.Results)
119+
{
120+
resultsByName[result.TestCase.FullyQualifiedName] = result;
121+
}
122+
123+
TestResult testResult = resultsByName["Warn"];
124+
Assert.AreEqual(TestOutcome.Failed, testResult.Outcome);
125+
Assert.IsTrue(testResult.ErrorMessage.Contains("#1 - CHECK(false) with expansion: (false)"));
126+
Assert.AreEqual(1, testResult.Messages.Count);
127+
Assert.IsTrue(testResult.Messages[0].Text.Contains("WARN: This is a warning message"));
128+
129+
testResult = resultsByName["Info"];
130+
Assert.AreEqual(TestOutcome.Failed, testResult.Outcome);
131+
Assert.IsTrue(testResult.ErrorMessage.Contains("#1 - CHECK(false) with expansion: (false)"));
132+
Assert.AreEqual(1, testResult.Messages.Count);
133+
Assert.IsTrue(testResult.Messages[0].Text.Contains("INFO: This is a info message"));
134+
135+
}
136+
106137
[TestMethod]
107138
public void BrokenXmlWithSingleTest()
108139
{

source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<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">
33
<Metadata>
4-
<Identity Id="CatchTestAdapter.xkBeyer.f56db3ea-257e-4f65-a52c-a6160aa8e329" Version="1.4.2" Language="en-US" Publisher="xkbeyer" />
4+
<Identity Id="CatchTestAdapter.xkBeyer.f56db3ea-257e-4f65-a52c-a6160aa8e329" Version="1.4.3" Language="en-US" Publisher="xkbeyer" />
55
<DisplayName>CatchTestAdapter</DisplayName>
66
<Description xml:space="preserve">Test Adapter for the Catch C++ unit test framework</Description>
77
<License>LICENSE.txt</License>

0 commit comments

Comments
 (0)