From 72d4e18e2d74ec442a3bae8f81d62e287a7e8bb8 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Fri, 10 Sep 2021 10:32:20 +0200 Subject: [PATCH] Support running on downloaded solution (#55) --- src/Exercism.TestRunner.CSharp/FilesParser.cs | 7 ++++++- .../DownloadedSolution/.exercism/Example.cs | 4 ++++ .../DownloadedSolution/.exercism/config.json | 7 +++++++ .../Solutions/DownloadedSolution/Fake.cs | 4 ++++ .../Solutions/DownloadedSolution/Fake.csproj | 18 ++++++++++++++++++ .../Solutions/DownloadedSolution/FakeTests.cs | 6 ++++++ .../DownloadedSolution/expected_results.json | 11 +++++++++++ .../TestRunnerTests.cs | 7 +++++++ 8 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/.exercism/Example.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/.exercism/config.json create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/Fake.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/Fake.csproj create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/FakeTests.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/expected_results.json diff --git a/src/Exercism.TestRunner.CSharp/FilesParser.cs b/src/Exercism.TestRunner.CSharp/FilesParser.cs index 4d18b1d..1f03e1f 100644 --- a/src/Exercism.TestRunner.CSharp/FilesParser.cs +++ b/src/Exercism.TestRunner.CSharp/FilesParser.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; @@ -16,7 +17,11 @@ private static string ConfigJson(Options options) => File.ReadAllText(options.ConfigJsonPath()); private static string ConfigJsonPath(this Options options) => - Path.Combine(options.InputDirectory, ".meta", "config.json"); + new[] + { + Path.Combine(options.InputDirectory, ".meta", "config.json"), + Path.Combine(options.InputDirectory, ".exercism", "config.json") + }.First(File.Exists); } internal class Files diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/.exercism/Example.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/.exercism/Example.cs new file mode 100644 index 0000000..bfbf44e --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/.exercism/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/DownloadedSolution/.exercism/config.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/.exercism/config.json new file mode 100644 index 0000000..b6395cc --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/.exercism/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/DownloadedSolution/Fake.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/Fake.cs new file mode 100644 index 0000000..bfbf44e --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/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/DownloadedSolution/Fake.csproj b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/Fake.csproj new file mode 100644 index 0000000..d6a2c1b --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/Fake.csproj @@ -0,0 +1,18 @@ + + + + net5.0 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/FakeTests.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/FakeTests.cs new file mode 100644 index 0000000..fecec13 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/FakeTests.cs @@ -0,0 +1,6 @@ +using Xunit; +public class FakeTests +{ + [Fact] + public void Add_should_add_numbers() => Assert.Equal(2, Fake.Add(1, 1)); +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/expected_results.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/expected_results.json new file mode 100644 index 0000000..56365e0 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DownloadedSolution/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 7bd4bdf..a8a85c7 100644 --- a/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs @@ -150,5 +150,12 @@ public void UseCultureAttribute() var testRun = TestSolutionRunner.Run("UseCultureAttribute"); Assert.Equal(testRun.Expected, testRun.Actual); } + + [Fact] + public void DownloadedSolution() + { + var testRun = TestSolutionRunner.Run("DownloadedSolution"); + Assert.Equal(testRun.Expected, testRun.Actual); + } } } \ No newline at end of file