diff --git a/TestAdapter/CatchTestCase.cs b/TestAdapter/CatchTestCase.cs index c87e1d1..f642ccf 100644 --- a/TestAdapter/CatchTestCase.cs +++ b/TestAdapter/CatchTestCase.cs @@ -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))] diff --git a/TestAdapter/TestExecutor.cs b/TestAdapter/TestExecutor.cs index 5c9aa08..5e9fcad 100644 --- a/TestAdapter/TestExecutor.cs +++ b/TestAdapter/TestExecutor.cs @@ -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) { @@ -213,6 +241,11 @@ protected virtual void ComposeResults(IList output_text, IList 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) diff --git a/TestAdapterTest/Common.cs b/TestAdapterTest/Common.cs index d3847f0..605e5d7 100644 --- a/TestAdapterTest/Common.cs +++ b/TestAdapterTest/Common.cs @@ -22,6 +22,6 @@ static class Common public static List ReferenceExeList { get; } = new List() { ReferenceExe }; // The number of tests in the reference project. - public const int ReferenceTestCount = 4; + public const int ReferenceTestCount = 6; } } diff --git a/TestAdapterTest/ReferenceCatchProject/Tests.cpp b/TestAdapterTest/ReferenceCatchProject/Tests.cpp index 998b80e..6e21854 100644 --- a/TestAdapterTest/ReferenceCatchProject/Tests.cpp +++ b/TestAdapterTest/ReferenceCatchProject/Tests.cpp @@ -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." ); - } -} \ No newline at end of file + 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); +} diff --git a/TestAdapterTest/TestTestExecutor.cs b/TestAdapterTest/TestTestExecutor.cs index 7d46cf5..af43510 100644 --- a/TestAdapterTest/TestTestExecutor.cs +++ b/TestAdapterTest/TestTestExecutor.cs @@ -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 resultsByName = new Dictionary(); + 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() { diff --git a/source.extension.vsixmanifest b/source.extension.vsixmanifest index 5166371..4475769 100644 --- a/source.extension.vsixmanifest +++ b/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + CatchTestAdapter Test Adapter for the Catch C++ unit test framework LICENSE.txt