Skip to content

Commit ae45170

Browse files
committed
Implement our own test runner
1 parent 1504b4b commit ae45170

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/FSharpy.TaskSeq.Test/FSharpy.TaskSeq.Test.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<Compile Include="AssemblyInfo.fs" />
1212
<Compile Include="Nunit.Extensions.fs" />
1313
<Compile Include="TestUtils.fs" />
14+
<Compile Include="TaskSeq.AllTests.fs" />
1415
<Compile Include="TaskSeq.Choose.Tests.fs" />
1516
<Compile Include="TaskSeq.Collect.Tests.fs" />
1617
<Compile Include="TaskSeq.Filter.Tests.fs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace FSharpy.Tests
2+
3+
open System
4+
open System.Threading.Tasks
5+
open System.Reflection
6+
7+
open Xunit
8+
open FsUnit.Xunit
9+
open FsToolkit.ErrorHandling
10+
11+
open FSharpy
12+
open Xunit.Abstractions
13+
14+
15+
type AllTests(output: ITestOutputHelper) =
16+
17+
[<Fact>]
18+
let ``Run all tests`` () =
19+
let myAsm = Assembly.GetExecutingAssembly()
20+
21+
let allMethods = [
22+
for ty in myAsm.DefinedTypes do
23+
for mem in ty.DeclaredMembers do
24+
match mem.MemberType with
25+
| MemberTypes.Method ->
26+
if mem.Name.StartsWith("TaskSeq") || mem.Name.StartsWith("CE") then
27+
yield ty, mem :?> MethodInfo
28+
| _ -> ()
29+
]
30+
31+
let x =
32+
{ new System.IFormattable with
33+
member x.ToString(format: string, provider: System.IFormatProvider) =
34+
if format = "D" then "foo" else "bar"
35+
}
36+
37+
task {
38+
for (ty, method) in allMethods do
39+
let ctor = ty.GetConstructor [| typeof<ITestOutputHelper> |]
40+
41+
if isNull ctor then
42+
failwith "Constructor for test not found"
43+
44+
let testObj = ctor.Invoke([| output |])
45+
46+
let! _ =
47+
if method.ReturnType.Name.Contains "Task" then
48+
method.Invoke(testObj, null) :?> Task<unit>
49+
else
50+
method.Invoke(testObj, null) |> ignore
51+
task { return () }
52+
53+
()
54+
55+
return ()
56+
}

0 commit comments

Comments
 (0)