Skip to content

Commit 1f27ac9

Browse files
Improve unskipping support (#53)
* Unskip all types of attributes * Don't remove custom attributes
1 parent 04c3881 commit 1f27ac9

File tree

7 files changed

+136
-6
lines changed

7 files changed

+136
-6
lines changed

src/Exercism.TestRunner.FSharp/Rewrite.fs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,24 @@ type EnableAllTests() =
2121
inherit SyntaxVisitor()
2222

2323
override _.VisitSynAttribute(attr: SynAttribute) : SynAttribute =
24-
match attr.TypeName with
25-
| LongIdentWithDots ([ ident ], _) when ident.idText = "Fact" ->
26-
base.VisitSynAttribute
27-
{ attr with
28-
ArgExpr = SynExpr.Const(SynConst.Unit, attr.ArgExpr.Range) }
24+
let isSkipExpr expr =
25+
match expr with
26+
| SynExpr.App(_, _,
27+
SynExpr.App(_, _, _, SynExpr.Ident(ident), _), _, _) -> ident.idText = "Skip"
28+
| _ -> false
29+
30+
match attr.ArgExpr with
31+
| SynExpr.Paren(expr, leftParenRange, rightParenRange, range) ->
32+
match expr with
33+
| SynExpr.App _ when isSkipExpr expr ->
34+
let newExpr = SynExpr.Const(SynConst.Unit, attr.ArgExpr.Range)
35+
base.VisitSynAttribute({ attr with ArgExpr = newExpr })
36+
| SynExpr.Tuple(iStruct, exprs, commaRanges, tplRange) ->
37+
let newExpr =
38+
SynExpr.Paren(
39+
SynExpr.Tuple(iStruct, exprs |> List.filter (isSkipExpr >> not), commaRanges, tplRange), leftParenRange, rightParenRange, range)
40+
base.VisitSynAttribute({ attr with ArgExpr = newExpr })
41+
| _ -> base.VisitSynAttribute(attr)
2942
| _ -> base.VisitSynAttribute(attr)
3043

3144
type CaptureConsoleOutput() =

src/Exercism.TestRunner.FSharp/Testing.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,14 @@ module TestResults =
105105
|> Option.map truncate
106106

107107
let private findTestMethodBinding (originalTestTree: ParsedInput) (xmlUnitTestResult: XmlUnitTestResult) =
108+
// For FsCheck tests, the generated test name includes the generic type of the arguments, which we need to strip
109+
let openBracketIndex = xmlUnitTestResult.TestName.LastIndexOf('<')
110+
let startIndex = xmlUnitTestResult.TestName.IndexOf('.') + 1
108111
let originalTestName =
109-
$"[{xmlUnitTestResult.TestName.[xmlUnitTestResult.TestName.IndexOf('.') + 1..]}]"
112+
if openBracketIndex = -1 then
113+
$"[{xmlUnitTestResult.TestName.[startIndex..]}]"
114+
else
115+
$"[{xmlUnitTestResult.TestName.[startIndex..openBracketIndex - 1]}]"
110116

111117
let mutable testMethodBinding = None
112118

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Fake
2+
3+
let add x y = x + y
4+
5+
let sub x y = x - y
6+
7+
let mul x y = x * y
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Compile Include="Fake.fs" />
11+
<Compile Include="FakeTests.fs" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
16+
<PackageReference Include="xunit" Version="2.4.1" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
18+
<PackageReference Include="FsUnit.xUnit" Version="4.0.4" />
19+
<PackageReference Include="FsCheck" Version="2.16.3" />
20+
<PackageReference Include="FsCheck.Xunit" Version="2.16.3" />
21+
<PackageReference Include="Exercism.Tests" Version="0.1.0-alpha" />
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module FakeTests
2+
3+
open System
4+
open System.Threading.Tasks
5+
open Xunit
6+
open FsUnit.Xunit
7+
open FsCheck
8+
open FsCheck.Xunit
9+
open Exercism.Tests
10+
open Fake
11+
12+
type CustomPropertyAttribute() =
13+
inherit PropertyAttribute()
14+
15+
[<Fact>]
16+
let ``Add should add numbers`` () = add 1 1 |> should equal 2
17+
18+
[<Fact(Skip = "Remove this Skip property to run this test")>]
19+
let ``Add should add more numbers`` () = add 2 3 |> should equal 5
20+
21+
[<Fact(Timeout = 20, Skip = "Remove this Skip property to run this test")>]
22+
let ``Add should add more numbers with timeout`` (): Task =
23+
Task.Delay(TimeSpan.FromMilliseconds(100.0))
24+
25+
[<Theory(Skip = "Remove this Skip property to run this test")>]
26+
[<InlineData(4, 7, 3)>]
27+
let ``Sub should subtract numbers`` (expected, x, y) = sub x y |> should equal expected
28+
29+
[<CustomPropertyAttribute(Skip = "Remove this Skip property to run this test")>]
30+
let ``Mul should multiply numbers`` (x, y) = mul x y |> should equal (x * y)
31+
32+
[<Property(Skip = "Remove this Skip property to run this test")>]
33+
let ``Div should divide numbers`` (x) : Property =
34+
Prop.throws<DivideByZeroException, int> (new Lazy<int>(fun () -> x / 0))
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"version": 3,
3+
"status": "fail",
4+
"tests": [
5+
{
6+
"name": "FakeTests.Add should add numbers",
7+
"status": "pass",
8+
"test_code": "add 1 1 |\u003E should equal 2"
9+
},
10+
{
11+
"name": "FakeTests.Add should add more numbers",
12+
"status": "pass",
13+
"test_code": "add 2 3 |\u003E should equal 5"
14+
},
15+
{
16+
"name": "FakeTests.Add should add more numbers with timeout",
17+
"status": "fail",
18+
"message": "Test execution timed out after 20 milliseconds",
19+
"test_code": "Task.Delay(TimeSpan.FromMilliseconds(100.0))"
20+
},
21+
{
22+
"name": "FakeTests.Sub should subtract numbers\u003CInt32\u003E(expected: 4, x: 7, y: 3)",
23+
"status": "pass",
24+
"test_code": "sub x y |\u003E should equal expected"
25+
},
26+
{
27+
"name": "FakeTests.Mul should multiply numbers",
28+
"status": "pass",
29+
"output": "Ok, passed 100 tests.",
30+
"test_code": "mul x y |\u003E should equal (x * y)"
31+
},
32+
{
33+
"name": "FakeTests.Div should divide numbers",
34+
"status": "pass",
35+
"output": "Ok, passed 100 tests.",
36+
"test_code": "Prop.throws\u003CDivideByZeroException, int\u003E (new Lazy\u003Cint\u003E(fun () -\u003E x / 0))"
37+
}
38+
]
39+
}

test/Exercism.TestRunner.FSharp.IntegrationTests/Tests.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Exercism.TestRunner.FSharp.IntegrationTests.Tests
22

33
open System
44
open System.IO
5+
open System.Threading
6+
open System.Threading.Tasks
57
open Xunit
68
open FsUnit.Xunit
79

@@ -145,3 +147,8 @@ let ``Some tests with task`` () =
145147
[<Fact>]
146148
let ``UseCulture attribute`` () =
147149
assertSolutionHasExpectedResults "UseCultureAttribute"
150+
151+
[<Fact>]
152+
let ``Different types of tests`` () =
153+
assertSolutionHasExpectedResults "DifferentTypesOfTests"
154+

0 commit comments

Comments
 (0)