Skip to content

Commit d8cbc9e

Browse files
authored
Merge pull request #182 from fsprojects/feature/test-coverage-improvements-extensions-seq
Daily Test Coverage Improver: Add tests for AsyncSeqExtensions and Seq modules
2 parents 61ed256 + 73aac31 commit d8cbc9e

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
@@ -1762,6 +1762,69 @@ let ``AsyncSeq.sortByDescending should work``() =
17621762
let actual = input |> AsyncSeq.sortByDescending fn
17631763
Assert.AreEqual(expected, actual)
17641764

1765+
// ----------------------------------------------------------------------------
1766+
// Tests for previously uncovered modules to improve coverage
1767+
1768+
[<Test>]
1769+
let ``AsyncSeqExtensions - async.For with AsyncSeq`` () =
1770+
let mutable result = []
1771+
let computation = async {
1772+
for item in asyncSeq { yield 1; yield 2; yield 3 } do
1773+
result <- item :: result
1774+
}
1775+
computation |> Async.RunSynchronously
1776+
Assert.AreEqual([3; 2; 1], result)
1777+
1778+
[<Test>]
1779+
let ``AsyncSeqExtensions - async.For with empty AsyncSeq`` () =
1780+
let mutable result = []
1781+
let computation = async {
1782+
for item in AsyncSeq.empty do
1783+
result <- item :: result
1784+
}
1785+
computation |> Async.RunSynchronously
1786+
Assert.AreEqual([], result)
1787+
1788+
[<Test>]
1789+
let ``AsyncSeqExtensions - async.For with exception in AsyncSeq`` () =
1790+
let mutable exceptionCaught = false
1791+
let computation = async {
1792+
try
1793+
for item in asyncSeq { yield 1; failwith "test error"; yield 2 } do
1794+
()
1795+
with
1796+
| ex when ex.Message = "test error" ->
1797+
exceptionCaught <- true
1798+
}
1799+
computation |> Async.RunSynchronously
1800+
Assert.IsTrue(exceptionCaught)
1801+
1802+
[<Test>]
1803+
let ``Seq.ofAsyncSeq should work`` () =
1804+
let asyncSeqData = asyncSeq {
1805+
yield 1
1806+
yield 2
1807+
yield 3
1808+
}
1809+
let seqResult = Seq.ofAsyncSeq asyncSeqData |> Seq.toList
1810+
Assert.AreEqual([1; 2; 3], seqResult)
1811+
1812+
[<Test>]
1813+
let ``Seq.ofAsyncSeq with empty AsyncSeq`` () =
1814+
let seqResult = Seq.ofAsyncSeq AsyncSeq.empty |> Seq.toList
1815+
Assert.AreEqual([], seqResult)
1816+
1817+
[<Test>]
1818+
let ``Seq.ofAsyncSeq with exception`` () =
1819+
let asyncSeqWithError = asyncSeq {
1820+
yield 1
1821+
failwith "test error"
1822+
yield 2
1823+
}
1824+
Assert.Throws<System.Exception>(fun () ->
1825+
Seq.ofAsyncSeq asyncSeqWithError |> Seq.toList |> ignore
1826+
) |> ignore
1827+
17651828
#if (NETSTANDARD2_1 || NETCOREAPP3_0)
17661829
[<Test>]
17671830
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)