-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathKoanContainer.fs
More file actions
28 lines (23 loc) · 777 Bytes
/
KoanContainer.fs
File metadata and controls
28 lines (23 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module FSharpKoans.Core.KoanContainer
open System
open System.IO
open System.Reflection
let hasKoanAttribute (info:MethodInfo) =
info.GetCustomAttributes(typeof<KoanAttribute>, true)
|> Seq.isEmpty
|> not
let findKoanMethods (container: Type) =
container.GetMethods(BindingFlags.Public ||| BindingFlags.Static)
|> Seq.filter hasKoanAttribute
let runKoans container =
let getKoanResult (m:MethodInfo) =
try
m.Invoke(null, [||]) |> ignore
Success <| sprintf "%s passed" m.Name
with
| ex ->
let outcome = sprintf "%s failed." m.Name
Failure(outcome, ex.InnerException)
container
|> findKoanMethods
|> Seq.map getKoanResult