From 7832fd53ba01e03d79292fb55429c9f240155b9c Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Sat, 11 Sep 2021 17:18:34 +0200 Subject: [PATCH] Support editor files (#57) --- src/Exercism.TestRunner.CSharp/FilesParser.cs | 8 ++++++-- .../TestCompilation.cs | 3 ++- .../Solutions/EditorFiles/.meta/config.json | 8 ++++++++ .../Solutions/EditorFiles/Fake.cs | 4 ++++ .../Solutions/EditorFiles/Fake.csproj | 18 ++++++++++++++++++ .../Solutions/EditorFiles/FakeTests.cs | 6 ++++++ .../Solutions/EditorFiles/FakeTestsHelper.cs | 7 +++++++ .../EditorFiles/expected_results.json | 11 +++++++++++ .../TestRunnerTests.cs | 7 +++++++ 9 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/.meta/config.json create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/Fake.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/Fake.csproj create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/FakeTests.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/FakeTestsHelper.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/expected_results.json diff --git a/src/Exercism.TestRunner.CSharp/FilesParser.cs b/src/Exercism.TestRunner.CSharp/FilesParser.cs index 1f03e1f..c290dd9 100644 --- a/src/Exercism.TestRunner.CSharp/FilesParser.cs +++ b/src/Exercism.TestRunner.CSharp/FilesParser.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Linq; using System.Text.Json; @@ -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(); [JsonPropertyName("test")] - public string[] Test { get; set; } + public string[] Test { get; set; } = Array.Empty(); + + [JsonPropertyName("editor")] + public string[] Editor { get; set; } = Array.Empty(); } internal class Configuration diff --git a/src/Exercism.TestRunner.CSharp/TestCompilation.cs b/src/Exercism.TestRunner.CSharp/TestCompilation.cs index 703ae2c..77a2ae2 100644 --- a/src/Exercism.TestRunner.CSharp/TestCompilation.cs +++ b/src/Exercism.TestRunner.CSharp/TestCompilation.cs @@ -21,9 +21,10 @@ public static Compilation Compile(Options options, Files files) => private static IEnumerable 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) diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/.meta/config.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/.meta/config.json new file mode 100644 index 0000000..4ab51d3 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/.meta/config.json @@ -0,0 +1,8 @@ +{ + "files": { + "solution": ["Fake.cs"], + "test": ["FakeTests.cs"], + "editor": ["FakeTestsHelper.cs"], + "example": [".meta/Example.cs"] + } +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/Fake.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/Fake.cs new file mode 100644 index 0000000..bfbf44e --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/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/EditorFiles/Fake.csproj b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/Fake.csproj new file mode 100644 index 0000000..d6a2c1b --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/Fake.csproj @@ -0,0 +1,18 @@ + + + + net5.0 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/FakeTests.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/FakeTests.cs new file mode 100644 index 0000000..b8ae572 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/FakeTests.cs @@ -0,0 +1,6 @@ +using Xunit; +public class FakeTests +{ + [Fact] + public void Add_should_add_numbers() => FakeTestsHelper.AssertAdd(2, 1, 1); +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/FakeTestsHelper.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/FakeTestsHelper.cs new file mode 100644 index 0000000..aecb0d5 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/FakeTestsHelper.cs @@ -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)); +} diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/expected_results.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/expected_results.json new file mode 100644 index 0000000..56365e0 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/EditorFiles/expected_results.json @@ -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))" + } + ] +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs index a8a85c7..8499428 100644 --- a/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs @@ -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); + } } } \ No newline at end of file