Skip to content

Commit

Permalink
Support errors without location (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Sep 11, 2021
1 parent cc37841 commit b51a8f4
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Exercism.TestRunner.CSharp/TestRunParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public static class Fake
{
public static int Add(int x, int y) => x + y;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files": {
"solution": ["Fake.cs"],
"test": ["FakeTests.cs"],
"example": [".meta/Example.cs"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public static class Fake
{
public static int Add(int x, int y) => x + y;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="Exercism.Tests" Version="0.1.0-alpha" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 3,
"status": "error",
"message": "error CS8805: Program using top-level statements must be an executable.",
"tests": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit b51a8f4

Please sign in to comment.