diff --git a/src/Exercism.TestRunner.CSharp/TestRunParser.cs b/src/Exercism.TestRunner.CSharp/TestRunParser.cs index 1c9b606..255bba6 100644 --- a/src/Exercism.TestRunner.CSharp/TestRunParser.cs +++ b/src/Exercism.TestRunner.CSharp/TestRunParser.cs @@ -38,7 +38,9 @@ private static string NormalizeLogLine(this Diagnostic diagnostic) => diagnostic.ToString().RemovePath(diagnostic).UseUnixNewlines().Trim(); private static string RemovePath(this string logLine, Diagnostic diagnostic) => - logLine.Replace(diagnostic.Location.SourceTree.FilePath, + diagnostic.Location == Location.None + ? logLine + : logLine.Replace(diagnostic.Location.SourceTree!.FilePath, Path.GetFileName(diagnostic.Location.SourceTree.FilePath)); } } \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/.meta/Example.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/.meta/Example.cs new file mode 100644 index 0000000..bfbf44e --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/.meta/Example.cs @@ -0,0 +1,4 @@ +public static class Fake +{ + public static int Add(int x, int y) => x + y; +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/.meta/config.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/.meta/config.json new file mode 100644 index 0000000..b6395cc --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/.meta/config.json @@ -0,0 +1,7 @@ +{ + "files": { + "solution": ["Fake.cs"], + "test": ["FakeTests.cs"], + "example": [".meta/Example.cs"] + } +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/Fake.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/Fake.cs new file mode 100644 index 0000000..bfbf44e --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/Fake.cs @@ -0,0 +1,4 @@ +public static class Fake +{ + public static int Add(int x, int y) => x + y; +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/Fake.csproj b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/Fake.csproj new file mode 100644 index 0000000..d6a2c1b --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/Fake.csproj @@ -0,0 +1,18 @@ + + + + net5.0 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/FakeTests.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/FakeTests.cs new file mode 100644 index 0000000..07a8118 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/FakeTests.cs @@ -0,0 +1,11 @@ +using Xunit; +public class FakeTests +{ + [Fact] + public void Add_should_add_numbers() => Assert.Equal(2, Fake.Add(1, 1)); +} + +public FakeHelper +{ + +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/expected_results.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/expected_results.json new file mode 100644 index 0000000..a090ed4 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/CompileErrorWithoutLocation/expected_results.json @@ -0,0 +1,6 @@ +{ + "version": 3, + "status": "error", + "message": "error CS8805: Program using top-level statements must be an executable.", + "tests": [] +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunResultReader.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunResultReader.cs index be8d0f5..f7ad8ef 100644 --- a/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunResultReader.cs +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunResultReader.cs @@ -29,6 +29,9 @@ private static string ReadFile(TestSolution solution, string fileName) => private static void NormalizeTestRunResult(TestRunResult testRunResult) { + if (testRunResult.Tests == null) + return; + static int Comparison(TestResult x, TestResult y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal); Array.Sort(testRunResult.Tests, Comparison); } diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs index a9081cc..209205f 100644 --- a/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs @@ -158,6 +158,13 @@ public void DownloadedSolution() Assert.Equal(testRun.Expected, testRun.Actual); } + [Fact] + public void CompileErrorWithoutLocation() + { + var testRun = TestSolutionRunner.Run("CompileErrorWithoutLocation"); + Assert.Equal(testRun.Expected, testRun.Actual); + } + [Fact] public void WithNonTestClasses() {