Skip to content

Commit c2a4dac

Browse files
authored
Merge PR #679 from knocte/simplifySelfCheck
Simplify SelfCheck & cleanup some tests.
2 parents 5fdbf5d + 411e995 commit c2a4dac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1122
-682
lines changed

build.fsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,8 @@ Target.create "SelfCheck" (fun _ ->
212212
let srcDir = Path.Combine(rootDir.FullName, "src") |> DirectoryInfo
213213

214214
let consoleProj = Path.Combine(srcDir.FullName, "FSharpLint.Console", "FSharpLint.Console.fsproj") |> FileInfo
215-
printfn "Checking %s..." consoleProj.FullName
216-
exec "dotnet" (sprintf "run lint %s" consoleProj.FullName) consoleProj.Directory.FullName
217-
218-
let coreProj = Path.Combine(srcDir.FullName, "FSharpLint.Core", "FSharpLint.Core.fsproj") |> FileInfo
219-
printfn "Checking %s..." coreProj.FullName
220-
exec "dotnet" (sprintf "run lint %s" coreProj.FullName) consoleProj.Directory.FullName
215+
let sol = Path.Combine(rootDir.FullName, "FSharpLint.sln") |> FileInfo
216+
exec "dotnet" (sprintf "run lint %s" sol.FullName) consoleProj.Directory.FullName
221217
)
222218

223219
// --------------------------------------------------------------------------------------

tests/FSharpLint.Core.Tests/Framework/TestAbstractSyntaxArray.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ open TestUtils
1111

1212
[<TestFixture>]
1313
type TestAst() =
14-
let unionCaseName (x:'a) =
15-
match FSharpValue.GetUnionFields(x, typeof<'a>) with
14+
let unionCaseName (x:'T) =
15+
match FSharpValue.GetUnionFields(x, typeof<'T>) with
1616
| case, _ -> case.Name
1717

1818
let astToExpr ast =

tests/FSharpLint.Core.Tests/Rules/Binding/FavourIgnoreOverLetWild.fs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ type TestBindingFavourIgnoreOverLetWild() =
1212
this.Parse """
1313
module Program
1414
15-
let _ = ()"""
15+
let _ = ()
16+
"""
1617

1718
Assert.IsTrue(this.ErrorExistsAt(4, 4))
1819

@@ -22,8 +23,9 @@ let _ = ()"""
2223
module Program
2324
2425
let (_) =
25-
let x = 4 + 4
26-
()"""
26+
let x = 4 + 4
27+
()
28+
"""
2729

2830
Assert.IsTrue(this.ErrorExistsAt(4, 4))
2931

@@ -32,7 +34,8 @@ let (_) =
3234
this.Parse """
3335
module Program
3436
35-
let ((((_)))) = List.iter (fun x -> ()) []"""
37+
let ((((_)))) = List.iter (fun x -> ()) []
38+
"""
3639

3740
Assert.IsTrue(this.ErrorExistsAt(4, 4))
3841

@@ -41,7 +44,8 @@ let ((((_)))) = List.iter (fun x -> ()) []"""
4144
this.Parse """
4245
module Program
4346
44-
let a = List.iter (fun x -> ()) []"""
47+
let a = List.iter (fun x -> ()) []
48+
"""
4549

4650
Assert.IsFalse(this.ErrorsExist)
4751

tests/FSharpLint.Core.Tests/Rules/Binding/FavourTypedIgnore.fs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ type TestBindingFavourTypedIgnore() =
1111
member this.``typed ignore has no error``() =
1212
this.Parse
1313
"""
14-
Console.ReadLine() |> ignore<string>"""
14+
Console.ReadLine() |> ignore<string>
15+
"""
1516

1617
this.AssertNoWarnings()
1718

1819
[<Test>]
1920
member this.``typed ignore has no error (without pipe)``() =
2021
this.Parse
2122
"""
22-
ignore<string>(Console.ReadLine())"""
23+
ignore<string>(Console.ReadLine())
24+
"""
2325

2426
this.AssertNoWarnings()
2527

@@ -28,7 +30,8 @@ Console.ReadLine() |> ignore<string>"""
2830
this.Parse
2931
"""
3032
Console.ReadLine()
31-
|> ignore"""
33+
|> ignore
34+
"""
3235

3336
Assert.IsTrue(this.ErrorsExist)
3437
Assert.IsTrue(this.ErrorExistsAt(2, 0))
@@ -39,7 +42,8 @@ Console.ReadLine()
3942
"""
4043
ignore(
4144
Console.ReadLine()
42-
)"""
45+
)
46+
"""
4347

4448
Assert.IsTrue(this.ErrorsExist)
4549
Assert.IsTrue(this.ErrorExistsAt(2, 0))

tests/FSharpLint.Core.Tests/Rules/Binding/TupleOfWildcards.fs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ module Program
1515
type Cat = | Persian of int * int
1616
1717
match Persian(1, 3) with
18-
| Persian(_, _) -> ()"""
18+
| Persian(_, _) -> ()
19+
"""
1920

20-
Assert.IsTrue(this.ErrorExistsAt(7, 14))
21+
Assert.IsTrue(this.ErrorExistsAt(7, 10))
2122

2223
[<Test>]
2324
member this.``Method's parameter list of wildcards should not be treated as tuple of wildcards.``() =
2425
this.Parse """
2526
module Program
2627
2728
type Cat() =
28-
member __.Persian(_, _) = ()"""
29+
member __.Persian(_, _) = ()
30+
"""
2931

3032
Assert.IsFalse(this.ErrorsExist)
3133

@@ -37,7 +39,8 @@ module Program
3739
type Cat() =
3840
new(_, _) = Cat()
3941
40-
member __.Persian(_) = ()"""
42+
member __.Persian(_) = ()
43+
"""
4144

4245
Assert.IsFalse(this.ErrorsExist)
4346

@@ -47,7 +50,8 @@ type Cat() =
4750
module Program
4851
4952
type Cat() =
50-
member __.Persian<'t>(_, _) = ()"""
53+
member __.Persian<'t>(_, _) = ()
54+
"""
5155

5256
Assert.IsFalse(this.ErrorsExist)
5357

@@ -61,6 +65,7 @@ type I =
6165
6266
let x =
6367
{ new I with
64-
member __.Two(_, _) = false }"""
68+
member __.Two(_, _) = false }
69+
"""
6570

6671
Assert.IsFalse(this.ErrorsExist)

tests/FSharpLint.Core.Tests/Rules/Binding/UselessBinding.fs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ type TestBindingUselessBinding() =
99

1010
[<Test>]
1111
member this.UselessBinding() =
12-
this.Parse("""
12+
this.Parse """
1313
module Program
1414
1515
let a = 10
16-
let a = a""")
16+
let a = a
17+
"""
1718

1819
Assert.IsTrue(this.ErrorExistsAt(5, 4))
1920

@@ -23,7 +24,8 @@ let a = a""")
2324
module Program
2425
2526
let mutable a = 10
26-
let a = a"""
27+
let a = a
28+
"""
2729

2830
Assert.IsFalse(this.ErrorsExist)
2931

@@ -33,30 +35,33 @@ let a = a"""
3335
module Program
3436
3537
let a = 10
36-
let mutable a = a"""
38+
let mutable a = a
39+
"""
3740

3841
Assert.IsFalse(this.ErrorsExist)
3942

4043
[<Test>]
4144
member this.UselessBindingWithParens() =
42-
this.Parse("""
45+
this.Parse """
4346
module Program
4447
4548
let a = 10
46-
let ((a)) = ((a))""")
49+
let ((a)) = ((a))
50+
"""
4751

4852
Assert.IsTrue(this.ErrorExistsAt(5, 4))
4953

5054
/// Regression test for https://github.com/fsprojects/FSharpLint/issues/101
5155
/// (a use binding will dispose the value so is not useless)
5256
[<Test>]
5357
member this.UseBindingWithSameNameDoesNotCauseUselessBindingError() =
54-
this.Parse("""
58+
this.Parse """
5559
module Program
5660
5761
type Cat() =
5862
static member CreateList(reader:TextReader) =
5963
use reader = reader
60-
reader.ReadToEnd()""")
64+
reader.ReadToEnd()
65+
"""
6166

6267
Assert.IsFalse(this.ErrorsExist)

tests/FSharpLint.Core.Tests/Rules/Binding/WildcardNamedWithAsPattern.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ type TestBindingWildcardNamedWithAsPattern() =
1313
module Program
1414
1515
match [] with
16-
| _ as x -> ()"""
16+
| _ as x -> ()
17+
"""
1718

18-
Assert.IsTrue(this.ErrorExistsAt(5, 6))
19+
Assert.IsTrue(this.ErrorExistsAt(5, 2))
1920

2021
[<Test>]
2122
member this.NamedPattern() =
2223
this.Parse """
2324
module Program
2425
2526
match [] with
26-
| x -> ()"""
27+
| x -> ()
28+
"""
2729

2830
Assert.IsFalse(this.ErrorsExist)
2931

@@ -33,7 +35,8 @@ match [] with
3335
module Program
3436
3537
match [] with
36-
| _ -> ()"""
38+
| _ -> ()
39+
"""
3740

3841
Assert.IsFalse(this.ErrorsExist)
3942

tests/FSharpLint.Core.Tests/Rules/Conventions/AsyncExceptionWithoutReturn.fs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ type TestAsyncExceptionWithoutReturn() =
1111
[<Test>]
1212
member this.AsyncRaiseWithoutReturn() =
1313
this.Parse("""
14-
namespace Program
14+
module Program
1515
16-
let someAsyncFunction =
16+
let someAsyncFunction () =
1717
async {
1818
raise (new System.Exception("An error occurred."))
1919
return true
@@ -24,9 +24,9 @@ let someAsyncFunction =
2424
[<Test>]
2525
member this.AsyncRaiseWithReturn() =
2626
this.Parse("""
27-
namespace Program
27+
module Program
2828
29-
let someAsyncFunction =
29+
let someAsyncFunction () =
3030
async {
3131
return raise (new System.Exception("An error occurred."))
3232
}""")
@@ -36,9 +36,9 @@ let someAsyncFunction =
3636
[<Test>]
3737
member this.AsyncFailWithWithoutReturn() =
3838
this.Parse("""
39-
namespace Program
39+
module Program
4040
41-
let someAsyncFunction =
41+
let someAsyncFunction () =
4242
async {
4343
failwith "An error occurred."
4444
return true
@@ -47,11 +47,11 @@ let someAsyncFunction =
4747
Assert.IsTrue this.ErrorsExist
4848

4949
[<Test>]
50-
member this.AsyncFailwithfWithoutReturn_1() =
50+
member this.AsyncFailwithfWithoutReturn1() =
5151
this.Parse("""
52-
namespace Program
52+
module Program
5353
54-
let someAsyncFunction =
54+
let someAsyncFunction () =
5555
async {
5656
let errCode = 78
5757
failwithf "Dummy Error Message: %i" errCode
@@ -61,11 +61,11 @@ let someAsyncFunction =
6161
Assert.IsTrue this.ErrorsExist
6262

6363
[<Test>]
64-
member this.AsyncFailwithfWithoutReturn_2() =
64+
member this.AsyncFailwithfWithoutReturn2() =
6565
this.Parse("""
66-
namespace Program
66+
module Program
6767
68-
let someAsyncFunction =
68+
let someAsyncFunction () =
6969
async {
7070
let errCode = 78
7171
failwithf "Dummy Error Message: %i" errCode
@@ -76,9 +76,9 @@ let someAsyncFunction =
7676
[<Test>]
7777
member this.AsyncFailwithWithReturn() =
7878
this.Parse("""
79-
namespace Program
79+
module Program
8080
81-
let someAsyncFunction =
81+
let someAsyncFunction () =
8282
async {
8383
return failwith "An error occurred."
8484
}""")
@@ -88,9 +88,9 @@ let someAsyncFunction =
8888
[<Test>]
8989
member this.AsyncFailwithfWithReturn() =
9090
this.Parse("""
91-
namespace Program
91+
module Program
9292
93-
let someAsyncFunction =
93+
let someAsyncFunction () =
9494
async {
9595
let errCode = 78
9696
return failwithf "Dummy Error Message: %i" errCode
@@ -101,9 +101,9 @@ let someAsyncFunction =
101101
[<Test>]
102102
member this.AsyncRaiseWithReturnInnerExpression() =
103103
this.Parse("""
104-
namespace Program
104+
module Program
105105
106-
let someAsyncFunction =
106+
let someAsyncFunction () =
107107
async {
108108
if 2 = 2 then
109109
return raise (new System.Exception("An error occurred."))
@@ -116,9 +116,9 @@ let someAsyncFunction =
116116
[<Test>]
117117
member this.AsyncRaiseWithoutReturnInnerExpression() =
118118
this.Parse("""
119-
namespace Program
119+
module Program
120120
121-
let someAsyncFunction =
121+
let someAsyncFunction () =
122122
async {
123123
if 2 = 2 then
124124
raise (new System.Exception("An error occurred."))

tests/FSharpLint.Core.Tests/Rules/Conventions/AvoidSinglePipeOperator.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type CustomerName(firstName) =
5959
member this.someFunc someParam =
6060
someParam
6161
|> someOtherFunc
62-
"""
62+
"""
6363

6464
Assert.IsTrue <| this.ErrorExistsAt(5, 8)
6565

@@ -71,7 +71,7 @@ type CustomerName(firstName) =
7171
someParam
7272
|> someOtherFunc
7373
|> yetAnotherFunc
74-
"""
74+
"""
7575

7676
Assert.IsFalse this.ErrorsExist
7777

0 commit comments

Comments
 (0)