Skip to content

Commit 282b3b6

Browse files
committed
Enable and add v0.3.0 NuGet tests
1 parent 480cf84 commit 282b3b6

File tree

2 files changed

+78
-20
lines changed

2 files changed

+78
-20
lines changed

src/FSharp.Control.TaskSeq.SmokeTests/FSharp.Control.TaskSeq.SmokeTests.fsproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@
77
<GenerateProgramFile>false</GenerateProgramFile>
88
</PropertyGroup>
99

10+
<ItemGroup>
11+
<Content Remove="C:\Users\Abel\.nuget\packages\fsharp.control.taskseq\0.3.0\contentFiles\any\netstandard2.1\release-notes.txt" />
12+
</ItemGroup>
13+
1014
<ItemGroup>
1115
<Compile Include="SmokeTests.fs" />
1216
<Compile Include="Program.fs" />
1317
</ItemGroup>
1418

1519
<ItemGroup>
16-
<PackageReference Include="FSharp.Control.TaskSeq" Version="0.2.2" />
20+
<PackageReference Include="FSharp.Control.TaskSeq" Version="0.3.0" />
21+
<PackageReference Include="FsUnit.xUnit" Version="5.1.0" />
1722
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
18-
<PackageReference Include="xunit" Version="2.4.1" />
23+
<PackageReference Include="xunit" Version="2.4.2" />
1924
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
2025
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2126
<PrivateAssets>all</PrivateAssets>

src/FSharp.Control.TaskSeq.SmokeTests/SmokeTests.fs

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,35 @@ open System
44
open System.Threading.Tasks
55
open Xunit
66
open FSharp.Control
7+
open FsUnit.Xunit
8+
9+
//
10+
// this file can be used to hand-test NuGet deploys
11+
// esp. when there are changes in the surface area
12+
//
13+
// This project gets compiled in CI, but is not part
14+
// of the structured test reports currently.
15+
// However, a compile error will fail the CI pipeline.
16+
//
17+
18+
19+
type private MultiDispose(disposed: int ref) =
20+
member _.Get1() = 1
21+
22+
interface IDisposable with
23+
member _.Dispose() = disposed.Value <- 1
24+
25+
interface IAsyncDisposable with
26+
member _.DisposeAsync() = ValueTask(task { do disposed.Value <- -1 })
727

828
[<Fact>]
9-
let ``Use and execute a taskSeq from nuget`` () =
29+
let ``Use and execute a minimal taskSeq from nuget`` () =
1030
taskSeq { yield 10 }
1131
|> TaskSeq.toArray
1232
|> fun x -> Assert.Equal<int array>(x, [| 10 |])
1333

1434
[<Fact>]
15-
let ``Use and execute a taskSeq from nuget with multiple keywords`` () =
35+
let ``Use taskSeq from nuget with multiple keywords v0.2.2`` () =
1636
taskSeq {
1737
do! task { do! Task.Delay 10 }
1838
let! x = task { return 1 }
@@ -26,19 +46,52 @@ let ``Use and execute a taskSeq from nuget with multiple keywords`` () =
2646

2747
// from version 0.3.0:
2848

29-
//[<Fact>]
30-
//let ``Use and execute a taskSeq from nuget with multiple keywords v0.3.0`` () =
31-
// taskSeq {
32-
// do! task { do! Task.Delay 10 }
33-
// do! Task.Delay 10 // only in 0.3
34-
// let! x = task { return 1 } :> Task // only in 0.3
35-
// yield 1
36-
// let! vt = ValueTask<int> ( task { return 2 } )
37-
// yield vt
38-
// let! vt = ValueTask ( task { return 2 } ) // only in 0.3
39-
// do! ValueTask ( task { return 2 } ) // only in 0.3
40-
// yield 3
41-
// yield 10
42-
// }
43-
// |> TaskSeq.toArray
44-
// |> fun x -> Assert.Equal<int array>(x, [| 1; 2; 3; 10 |])
49+
[<Fact>]
50+
let ``Use taskSeq from nuget with multiple keywords v0.3.0`` () =
51+
taskSeq {
52+
do! task { do! Task.Delay 10 }
53+
do! Task.Delay 10 // only in 0.3
54+
let! x = task { return 1 } :> Task // only in 0.3
55+
yield 1
56+
let! vt = ValueTask<int>(task { return 2 })
57+
yield vt
58+
let! vt = ValueTask(task { return 2 }) // only in 0.3
59+
do! ValueTask(task { return 2 }) // only in 0.3
60+
yield 3
61+
yield 10
62+
}
63+
|> TaskSeq.toArray
64+
|> fun x -> Assert.Equal<int array>(x, [| 1; 2; 3; 10 |])
65+
66+
[<Fact>]
67+
let ``Use taskSeq when type implements IDisposable and IAsyncDisposable`` () =
68+
let disposed = ref 0
69+
70+
let ts = taskSeq {
71+
use! x = task { return new MultiDispose(disposed) } // Used to fail to compile (see #97, fixed in v0.3.0)
72+
yield x.Get1()
73+
}
74+
75+
ts
76+
|> TaskSeq.length
77+
|> Task.map (should equal 1)
78+
|> Task.map (fun _ -> disposed.Value |> should equal -1) // must favor IAsyncDisposable, not IDisposable
79+
80+
[<Fact>]
81+
let ``Use taskSeq as part of an F# task CE`` () = task {
82+
let ts = taskSeq { yield! [ 0..99 ] }
83+
let ra = ResizeArray()
84+
85+
// loop through a taskSeq, support added in v0.3.0
86+
for v in ts do
87+
ra.Add v
88+
89+
ra.ToArray() |> should equal [| 0..99 |]
90+
}
91+
92+
[<Fact>]
93+
let ``New surface area functions availability tests v0.3.0`` () = task {
94+
let ts = TaskSeq.singleton 10 // added in v0.3.0
95+
let! ls = TaskSeq.toListAsync ts
96+
List.exactlyOne ls |> should equal 10
97+
}

0 commit comments

Comments
 (0)