From deaf5ff84bb121297279624da107d21f3882012e Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Fri, 1 Oct 2021 12:24:21 +0200 Subject: [PATCH] Unskip all tests (#67) --- .../TestsRewriter.cs | 4 +-- .../DifferentTypesOfTests/.meta/config.json | 7 ++++ .../Solutions/DifferentTypesOfTests/Fake.cs | 12 +++++++ .../DifferentTypesOfTests/Fake.csproj | 20 +++++++++++ .../DifferentTypesOfTests/FakeTests.cs | 33 +++++++++++++++++++ .../expected_results.json | 33 +++++++++++++++++++ .../TestRunnerTests.cs | 7 ++++ 7 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/.meta/config.json create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/Fake.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/Fake.csproj create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/FakeTests.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/expected_results.json diff --git a/src/Exercism.TestRunner.CSharp/TestsRewriter.cs b/src/Exercism.TestRunner.CSharp/TestsRewriter.cs index 72a5e1f..0d9b064 100644 --- a/src/Exercism.TestRunner.CSharp/TestsRewriter.cs +++ b/src/Exercism.TestRunner.CSharp/TestsRewriter.cs @@ -26,8 +26,8 @@ private static SyntaxNode CaptureConsoleOutput(this SyntaxNode testsRoot) => private class UnskipTestsRewriter : CSharpSyntaxRewriter { - public override SyntaxNode VisitAttribute(AttributeSyntax node) => - base.VisitAttribute(node.Name.ToString() == "Fact" ? node.WithArgumentList(null) : node); + public override SyntaxNode VisitAttributeArgument(AttributeArgumentSyntax node) => + node.NameEquals?.Name.Identifier.Text == "Skip" ? null : base.VisitAttributeArgument(node); } private class CaptureConsoleOutputRewriter : CSharpSyntaxRewriter diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/.meta/config.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/.meta/config.json new file mode 100644 index 0000000..b6395cc --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/.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/DifferentTypesOfTests/Fake.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/Fake.cs new file mode 100644 index 0000000..5ea6c75 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/Fake.cs @@ -0,0 +1,12 @@ +public static class Fake +{ + public static int Identity(int x) => x; + + public static int Add(int x, int y) => x + y; + + public static int Sub(int x, int y) => x - y; + + public static int Mul(int x, int y) => x * y; + + public static int Div(int x, int y) => x / y; +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/Fake.csproj b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/Fake.csproj new file mode 100644 index 0000000..7701016 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/Fake.csproj @@ -0,0 +1,20 @@ + + + + net5.0 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/FakeTests.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/FakeTests.cs new file mode 100644 index 0000000..7a8a40d --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/FakeTests.cs @@ -0,0 +1,33 @@ +using System; + +using Xunit; +using FsCheck.Xunit; +using FsCheck; + +public class FakeTests +{ + [Fact] + public void Identity() => + Assert.Equal(2, Fake.Identity(2)); + + [Fact(Skip = "Remove this Skip property to run this test")] + public void Add_should_add_numbers() => + Assert.Equal(2, Fake.Add(1, 1)); + + [Theory(Skip = "Remove this Skip property to run this test")] + [InlineData(4, 7, 3)] + public void Sub_should_subtract_numbers(int expected, int x, int y) => + Assert.Equal(expected, Fake.Sub(x, y)); + + [CustomPropertyAttribute(Skip = "Remove this Skip property to run this test")] + public void Mul_should_multiply_numbers(int x, int y) => + Assert.Equal(x * y, Fake.Mul(x, y)); + + [Property(Skip = "Remove this Skip property to run this test")] + public Property Div_should_divide_numbers(int x) => + Prop.Throws(new Lazy(() => x / 0)); +} + +public class CustomPropertyAttribute : PropertyAttribute +{ +} diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/expected_results.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/expected_results.json new file mode 100644 index 0000000..68e6c1f --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/DifferentTypesOfTests/expected_results.json @@ -0,0 +1,33 @@ +{ + "version": 3, + "status": "pass", + "tests": [ + { + "name": "Identity", + "status": "pass", + "test_code": "Assert.Equal(2, Fake.Identity(2))" + }, + { + "name": "Add should add numbers", + "status": "pass", + "test_code": "Assert.Equal(2, Fake.Add(1, 1))" + }, + { + "name": "Sub should subtract numbers", + "status": "pass", + "test_code": "Assert.Equal(expected, Fake.Sub(x, y))" + }, + { + "name": "Mul should multiply numbers", + "status": "pass", + "output": "Ok, passed 100 tests.", + "test_code": "Assert.Equal(x * y, Fake.Mul(x, y))" + }, + { + "name": "Div should divide numbers", + "status": "pass", + "output": "Ok, passed 100 tests.", + "test_code": "Prop.Throws\u003CDivideByZeroException, int\u003E(new Lazy\u003Cint\u003E(() =\u003E x / 0))" + } + ] +} \ 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 7379015..e032fbd 100644 --- a/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs @@ -192,5 +192,12 @@ public void UseTimeZones() var testRun = TestSolutionRunner.Run("UseTimeZones"); Assert.Equal(testRun.Expected, testRun.Actual); } + + [Fact] + public void DifferentTypesOfTests() + { + var testRun = TestSolutionRunner.Run("DifferentTypesOfTests"); + Assert.Equal(testRun.Expected, testRun.Actual); + } } } \ No newline at end of file