Skip to content

Commit

Permalink
Fix test runner failing for test classes with constructor (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Sep 9, 2021
1 parent effa7bb commit 3ce6f21
Show file tree
Hide file tree
Showing 16 changed files with 316 additions and 156 deletions.
328 changes: 174 additions & 154 deletions src/Exercism.TestRunner.CSharp/TestsRewriter.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 3,
"status": "error",
"message": "FakeTests.cs(5,66): error CS0117: \u0027Fake\u0027 does not contain a definition for \u0027Add\u0027\nFakeTests.cs(7,66): error CS0117: \u0027Fake\u0027 does not contain a definition for \u0027Sub\u0027",
"message": "FakeTests.cs(6,66): error CS0117: \u0027Fake\u0027 does not contain a definition for \u0027Add\u0027\nFakeTests.cs(8,66): error CS0117: \u0027Fake\u0027 does not contain a definition for \u0027Sub\u0027",
"tests": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Add should add numbers",
"status": "pass",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n\n Output was truncated. Please limit to 500 chars.",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n\n Output was truncated. Please limit to 500 chars.",
"test_code": "Assert.Equal(2, Fake.Add(1, 1))"
},
{
Expand Down
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 class Fake
{
public 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,16 @@
using Xunit;
using System.Globalization;
using System.Threading;

public class FakeTests
{
public FakeTests()
{
var enUsCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = enUsCulture;
Thread.CurrentThread.CurrentUICulture = enUsCulture;
}

[Fact]
public void Add_should_add_numbers() => Assert.Equal(2, new Fake().Add(1, 1));
}
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
@@ -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 class Fake
{
public 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,22 @@
using System;

using Xunit;
using System.IO;

public class FakeTests : IDisposable
{
private FileStream _file;

public FakeTests()
{
_file = File.Open("tmp.txt", FileMode.Create);
}

[Fact]
public void Add_should_add_numbers() => Assert.Equal(2, new Fake().Add(1, 1));

public void Dispose()
{
_file.Dispose();
}
}
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 @@ -129,5 +129,19 @@ public void WithExample()
var testRun = TestSolutionRunner.Run("WithExample");
Assert.Equal(testRun.Expected, testRun.Actual);
}

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

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

0 comments on commit 3ce6f21

Please sign in to comment.