Skip to content

Commit

Permalink
Support editor files (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Sep 11, 2021
1 parent 39900b4 commit 7832fd5
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Exercism.TestRunner.CSharp/FilesParser.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Linq;
using System.Text.Json;
Expand Down Expand Up @@ -27,10 +28,13 @@ private static string ConfigJsonPath(this Options options) =>
internal class Files
{
[JsonPropertyName("solution")]
public string[] Solution { get; set; }
public string[] Solution { get; set; } = Array.Empty<string>();

[JsonPropertyName("test")]
public string[] Test { get; set; }
public string[] Test { get; set; } = Array.Empty<string>();

[JsonPropertyName("editor")]
public string[] Editor { get; set; } = Array.Empty<string>();
}

internal class Configuration
Expand Down
3 changes: 2 additions & 1 deletion src/Exercism.TestRunner.CSharp/TestCompilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public static Compilation Compile(Options options, Files files) =>
private static IEnumerable<SyntaxTree> SyntaxTrees(Options options, Files files)
{
var solutionFiles = files.Solution.Select(file => ParseSyntaxTree(file, options));
var editorFiles = files.Editor.Select(file => ParseSyntaxTree(file, options));
var testFiles = files.Test.Select(file => ParseSyntaxTree(file, options).Rewrite());

return solutionFiles.Concat(testFiles);
return solutionFiles.Concat(editorFiles).Concat(testFiles);
}

private static SyntaxTree ParseSyntaxTree(string file, Options options)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": {
"solution": ["Fake.cs"],
"test": ["FakeTests.cs"],
"editor": ["FakeTestsHelper.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,6 @@
using Xunit;
public class FakeTests
{
[Fact]
public void Add_should_add_numbers() => FakeTestsHelper.AssertAdd(2, 1, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Xunit;

public static class FakeTestsHelper
{
public static void AssertAdd(int expected, int x, int y) =>
Assert.Equal(expected, Fake.Add(x, y));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 3,
"status": "pass",
"tests": [
{
"name": "Add should add numbers",
"status": "pass",
"test_code": "Assert.Equal(2, Fake.Add(1, 1))"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,12 @@ public void DownloadedSolution()
var testRun = TestSolutionRunner.Run("DownloadedSolution");
Assert.Equal(testRun.Expected, testRun.Actual);
}

[Fact]
public void EditorFiles()
{
var testRun = TestSolutionRunner.Run("EditorFiles");
Assert.Equal(testRun.Expected, testRun.Actual);
}
}
}

0 comments on commit 7832fd5

Please sign in to comment.