Skip to content

Commit

Permalink
Provide clear message for file-level errors like file not found
Browse files Browse the repository at this point in the history
  • Loading branch information
CharliePoole committed Feb 26, 2021
1 parent 6d52e0d commit 63d6965
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions NUnitConsole.sln
Expand Up @@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
CONTRIBUTING.md = CONTRIBUTING.md
src\Directory.Build.props = src\Directory.Build.props
LICENSE.txt = LICENSE.txt
NetFXTests.nunit = NetFXTests.nunit
NOTICES.txt = NOTICES.txt
NuGet.config = NuGet.config
nunit.ico = nunit.ico
Expand Down
31 changes: 29 additions & 2 deletions test-results.cake
Expand Up @@ -76,10 +76,12 @@ public class TestReport

var expected = test.ExpectedResult;

ReportMissingFiles();

if (result.OverallResult == null)
Errors.Add("The test-run element has no result attribute.");
Errors.Add(" The test-run element has no result attribute.");
else if (expected.OverallResult != result.OverallResult)
Errors.Add($" Expected: Overall Result = {expected.OverallResult}\n But was: {result.OverallResult}");
Errors.Add($" Expected: Overall Result = {expected.OverallResult}\n But was: {result.OverallResult}");
CheckCounter("Test Count", expected.Total, result.Total);
CheckCounter("Passed", expected.Passed, result.Passed);
CheckCounter("Failed", expected.Failed, result.Failed);
Expand Down Expand Up @@ -109,11 +111,36 @@ public class TestReport
: "\n ERROR: Test Result not as expected!");
}

private void ReportMissingFiles()
{
var suites = Result.Xml.SelectNodes(
"//test-suite[@type='Unknown'] | //test-suite[@type='Project'] | //test-suite[@type='Assembly']");
if (suites.Count == 0)
Errors.Add(" No top-level suites! Possible empty command-line or misformed project.");

foreach (XmlNode suite in suites)
{
string suiteResult = GetAttribute(suite, "result");
string label = GetAttribute(suite, "label");
string site = suite.Attributes["site"]?.Value ?? "Test";
if (suiteResult == "Failed" && site == "Test" && label == "Invalid")
{
string message = suite.SelectSingleNode("reason/message")?.InnerText;
Errors.Add($" {message}");
}
}
}

private void CheckCounter(string label, int expected, int actual)
{
if (expected > 0 && expected != actual)
Errors.Add($" Expected: {label} = {expected}\n But was: {actual}");
}

private string GetAttribute(XmlNode node, string name)
{
return node.Attributes[name]?.Value;
}
}

public class ResultReporter
Expand Down

0 comments on commit 63d6965

Please sign in to comment.