Skip to content

Commit 4df8f8e

Browse files
Move fsharpqa/Libraries/Core/Collections test cases to NUnit (#9292)
* Moved some test cased to NUnit * Moved List.head and List.tail test cases to NUnit * Split tests into multiple files * Moved IEnumerable test cases to NUnit * Removed migrated test cases * Fixed positions in List tests
1 parent f422dc3 commit 4df8f8e

11 files changed

Lines changed: 151 additions & 101 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
7+
[<TestFixture>]
8+
module ``Array2D Tests`` =
9+
10+
[<Test>]
11+
let ``Iter should not throw on non-zero based 2D arrays``() =
12+
// Regression for FSHARP1.0: 5919
13+
// bug in array2D functions would cause iter to blow up
14+
15+
let a = Array2D.createBased 1 5 10 10 0.0
16+
let testDelegate = TestDelegate (fun _ -> a |> Array2D.iter (printf "%f"))
17+
18+
Assert.DoesNotThrow testDelegate
19+
20+
[<Test>]
21+
let ``Iteri should not throw on non-zero based 2D arrays``() =
22+
// Regression for FSHARP1.0: 5919
23+
// bug in array2D functions would cause iteri to blow up
24+
25+
let a = Array2D.createBased 1 5 10 10 0.0
26+
let testDelegate = TestDelegate (fun _ -> a |> Array2D.iteri (fun _ _ x -> printf "%f" x))
27+
28+
Assert.DoesNotThrow testDelegate
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
7+
[<TestFixture>]
8+
module ``IEnumerable Tests`` =
9+
10+
// Regression test for FSHARP1.0:4726
11+
// Makes sure that the .Dispose() method, if available, in invoked on IEnumerable
12+
13+
let mutable dispose_called_in_E = 0 // we expect this to be incremented 3 times
14+
let mutable dispose_called_in_C = 0 // we expect this to be incremented once (=this is what the bug was about, i.e. .Dispose() was never invoked)
15+
16+
type E(_c:int) = class
17+
interface System.IDisposable with
18+
member __.Dispose () = dispose_called_in_E <- dispose_called_in_E + 1
19+
end
20+
21+
type C() = class
22+
let mutable i = 0
23+
interface System.Collections.IEnumerator with
24+
member __.Current with get () = new E(i) :> obj
25+
member __.MoveNext () =
26+
i <- i+1
27+
i<4
28+
member __.Reset () = i <- 0
29+
interface System.Collections.IEnumerable with
30+
member x.GetEnumerator () = x :> System.Collections.IEnumerator
31+
32+
interface System.IDisposable with
33+
member __.Dispose () = dispose_called_in_C <- dispose_called_in_C + 1
34+
end
35+
end
36+
37+
[<Test>]
38+
let ``Dispose``() =
39+
let _ = Seq.cast (new C()) |> Seq.map (fun x -> use o = x;
40+
o) |> Seq.length
41+
42+
Assert.areEqual 3 dispose_called_in_E
43+
Assert.areEqual 1 dispose_called_in_C
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
open FSharp.Compiler.SourceCodeServices
7+
8+
[<TestFixture>]
9+
module ``List Tests`` =
10+
11+
[<Test>]
12+
let ``List hd should not exist``() =
13+
// Regression test for FSharp1.0:5641
14+
// Title: List.hd/tl --> List.head/tail
15+
16+
CompilerAssert.TypeCheckSingleError
17+
"""
18+
List.hd [1] |> ignore
19+
"""
20+
FSharpErrorSeverity.Error
21+
39
22+
(2, 6, 2, 8)
23+
"The value, constructor, namespace or type 'hd' is not defined."
24+
25+
26+
27+
[<Test>]
28+
let ``List tl should not exist``() =
29+
// Regression test for FSharp1.0:5641
30+
// Title: List.hd/tl --> List.head/tail
31+
32+
CompilerAssert.TypeCheckSingleError
33+
"""
34+
List.tl [1] |> ignore
35+
"""
36+
FSharpErrorSeverity.Error
37+
39
38+
(2, 6, 2, 8)
39+
"The value, constructor, namespace or type 'tl' is not defined."
40+
41+
[<Test>]
42+
let ``List head of empty list``() =
43+
let testDelegate = TestDelegate (fun _ -> (List.head [] |> ignore))
44+
45+
Assert.Throws<System.ArgumentException> testDelegate |> ignore
46+
47+
[<Test>]
48+
let ``List tail of empty list``() =
49+
let testDelegate = TestDelegate (fun _ -> (List.tail [] |> ignore))
50+
51+
Assert.Throws<System.ArgumentException> testDelegate |> ignore
52+
53+
[<Test>]
54+
let ``List head and tail``() =
55+
Assert.areEqual 1 (List.head [1 .. 10])
56+
Assert.areEqual "a" (List.head ["a"])
57+
Assert.areEqual [2 .. 10] (List.tail [1 .. 10])
58+
Assert.areEqual [] (List.tail [1])
59+
Assert.areEqual (List.head (List.tail ['a'; 'a'])) (List.head ['a'; 'a'])
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
7+
[<TestFixture>]
8+
module ``Map Tests`` =
9+
10+
[<Test>]
11+
let ``Equality should be implemented on map``() =
12+
// Dev11:19569 - this used to throw an ArgumentException saying Object didn't implement IComparable
13+
14+
let m = Map.ofArray [| 1, obj() |]
15+
let testDelegate = TestDelegate (fun _ -> (m = m) |> ignore)
16+
17+
Assert.DoesNotThrow testDelegate

tests/fsharp/FSharpSuite.Tests.fsproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
<Compile Include="Compiler\Stress\LargeExprTests.fs" />
7979
<Compile Include="Compiler\Regressions\IndexerRegressionTests.fs" />
8080
<Compile Include="Compiler\Regressions\ForInDoMutableRegressionTest.fs" />
81+
<Compile Include="Compiler\Libraries\Core\Collections\IEnumerableTests.fs" />
82+
<Compile Include="Compiler\Libraries\Core\Collections\MapTests.fs" />
83+
<Compile Include="Compiler\Libraries\Core\Collections\CollectionTests.fs" />
84+
<Compile Include="Compiler\Libraries\Core\Collections\ListTests.fs" />
8185
<None Include="app.config" />
8286
<None Include="update.base.line.with.actuals.fsx" />
8387

tests/fsharpqa/Source/Libraries/Core/Collections/Array2DIter01.fs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/fsharpqa/Source/Libraries/Core/Collections/Array2DIter02.fs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/fsharpqa/Source/Libraries/Core/Collections/EqualityOnMap01.fs

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/fsharpqa/Source/Libraries/Core/Collections/Seq_Cast_Dispose01.fs

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/fsharpqa/Source/Libraries/Core/Collections/env.lst

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)