Skip to content

Commit a74591b

Browse files
authored
Merge branch 'main' into feature/test-coverage-asyncseqextensions-seq
2 parents 214eea2 + d8cbc9e commit a74591b

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,69 @@ let ``async.For with exception in AsyncSeq should propagate``() =
18191819
}
18201820
|> Async.RunSynchronously
18211821

1822+
// ----------------------------------------------------------------------------
1823+
// Tests for previously uncovered modules to improve coverage
1824+
1825+
[<Test>]
1826+
let ``AsyncSeqExtensions - async.For with AsyncSeq`` () =
1827+
let mutable result = []
1828+
let computation = async {
1829+
for item in asyncSeq { yield 1; yield 2; yield 3 } do
1830+
result <- item :: result
1831+
}
1832+
computation |> Async.RunSynchronously
1833+
Assert.AreEqual([3; 2; 1], result)
1834+
1835+
[<Test>]
1836+
let ``AsyncSeqExtensions - async.For with empty AsyncSeq`` () =
1837+
let mutable result = []
1838+
let computation = async {
1839+
for item in AsyncSeq.empty do
1840+
result <- item :: result
1841+
}
1842+
computation |> Async.RunSynchronously
1843+
Assert.AreEqual([], result)
1844+
1845+
[<Test>]
1846+
let ``AsyncSeqExtensions - async.For with exception in AsyncSeq`` () =
1847+
let mutable exceptionCaught = false
1848+
let computation = async {
1849+
try
1850+
for item in asyncSeq { yield 1; failwith "test error"; yield 2 } do
1851+
()
1852+
with
1853+
| ex when ex.Message = "test error" ->
1854+
exceptionCaught <- true
1855+
}
1856+
computation |> Async.RunSynchronously
1857+
Assert.IsTrue(exceptionCaught)
1858+
1859+
[<Test>]
1860+
let ``Seq.ofAsyncSeq should work`` () =
1861+
let asyncSeqData = asyncSeq {
1862+
yield 1
1863+
yield 2
1864+
yield 3
1865+
}
1866+
let seqResult = Seq.ofAsyncSeq asyncSeqData |> Seq.toList
1867+
Assert.AreEqual([1; 2; 3], seqResult)
1868+
1869+
[<Test>]
1870+
let ``Seq.ofAsyncSeq with empty AsyncSeq`` () =
1871+
let seqResult = Seq.ofAsyncSeq AsyncSeq.empty |> Seq.toList
1872+
Assert.AreEqual([], seqResult)
1873+
1874+
[<Test>]
1875+
let ``Seq.ofAsyncSeq with exception`` () =
1876+
let asyncSeqWithError = asyncSeq {
1877+
yield 1
1878+
failwith "test error"
1879+
yield 2
1880+
}
1881+
Assert.Throws<System.Exception>(fun () ->
1882+
Seq.ofAsyncSeq asyncSeqWithError |> Seq.toList |> ignore
1883+
) |> ignore
1884+
18221885
#if (NETSTANDARD2_1 || NETCOREAPP3_0)
18231886
[<Test>]
18241887
let ``AsyncSeq.ofAsyncEnum should roundtrip successfully``() =

tests/FSharp.Control.AsyncSeq.Tests/FSharp.Control.AsyncSeq.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<None Include="AsyncSeqPerf.fsx" />
1010
</ItemGroup>
1111
<ItemGroup>
12+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
1213
<ProjectReference Include="..\..\src\FSharp.Control.AsyncSeq\FSharp.Control.AsyncSeq.fsproj" />
1314
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
1415
<PackageReference Include="NUnit" Version="3.9.0" />

0 commit comments

Comments
 (0)