|
1 | 1 | module Qsp.Tests.Test |
2 | 2 | open Fuchu |
| 3 | +open Argu |
3 | 4 |
|
4 | 5 | open Qsp |
5 | 6 | open Tests |
6 | 7 |
|
| 8 | +[<Struct;RequireQualifiedAccess>] |
| 9 | +type TestType = |
| 10 | + | MockTest |
| 11 | + | MainTest |
| 12 | +module TestType = |
| 13 | + let ofTestName (name: string) = |
| 14 | + match name.StartsWith TestOnMocks.mockTestList with |
| 15 | + | true -> TestType.MockTest |
| 16 | + | false -> TestType.MainTest |
| 17 | + |
| 18 | +[<RequireQualifiedAccess>] |
| 19 | +type TestOnMocksType = |
| 20 | + | True |
| 21 | + | Interactive |
| 22 | + |
| 23 | +[<RequireQualifiedAccess>] |
| 24 | +type CliArguments = |
| 25 | + | Test_Main |
| 26 | + | Test_Mocks of TestOnMocksType |
| 27 | + |
| 28 | + interface IArgParserTemplate with |
| 29 | + member s.Usage = |
| 30 | + match s with |
| 31 | + | Test_Main -> "run main tests" |
| 32 | + | Test_Mocks _ -> "run tests on the sources, which are placed in the \"mocks\" folder" |
| 33 | + |
7 | 34 | [<EntryPoint;System.STAThread>] |
8 | 35 | let main args = |
9 | | - let isFullTest () = |
10 | | - let rec whileYOrN () = |
11 | | - match System.Console.ReadKey().Key with |
12 | | - | System.ConsoleKey.Y -> true |
13 | | - | System.ConsoleKey.N -> false |
14 | | - | x -> |
15 | | - printfn "`y` or `n` but %A" x |
16 | | - whileYOrN () |
17 | | - printfn "Full test? (`y` or `n`)" |
18 | | - whileYOrN () |
19 | | - |
20 | | - let f isFullTest = |
21 | | - if isFullTest then |
22 | | - defaultMainThisAssembly args |
23 | | - else |
24 | | - defaultMainThisAssemblyFilter |
25 | | - args |
26 | | - (fun x -> |
27 | | - x.Where(fun x -> not <| x.StartsWith TestOnMocks.mockTestList) |
28 | | - ) |
29 | | - |
| 36 | + let argParser = ArgumentParser.Create<CliArguments>(programName = "qsp-toolbox") |
30 | 37 | match args with |
31 | | - | [|"--full"|] -> |
32 | | - f true |
33 | 38 | | [||] -> |
34 | | - f (isFullTest ()) |
| 39 | + argParser.PrintUsage() |> printfn "%s" |
| 40 | + 0 |
35 | 41 | | _ -> |
36 | | - printfn "`--full` or pass args but: %A" args |
37 | | - 1 |
| 42 | + let results = |
| 43 | + try |
| 44 | + Ok (argParser.ParseCommandLine(args)) |
| 45 | + with e -> |
| 46 | + Error e.Message |
| 47 | + match results with |
| 48 | + | Error errMsg -> |
| 49 | + printfn "%s" errMsg |
| 50 | + 1 |
| 51 | + |
| 52 | + | Ok results -> |
| 53 | + let isFullTest () = |
| 54 | + let rec whileYOrN () = |
| 55 | + match System.Console.ReadKey().Key with |
| 56 | + | System.ConsoleKey.Y -> true |
| 57 | + | System.ConsoleKey.N -> false |
| 58 | + | x -> |
| 59 | + printfn "`y` or `n` but %A" x |
| 60 | + whileYOrN () |
| 61 | + printfn "Full test? (`y` or `n`)" |
| 62 | + whileYOrN () |
| 63 | + |
| 64 | + let isTestMocks = |
| 65 | + match results.TryGetResult CliArguments.Test_Mocks with |
| 66 | + | None -> |
| 67 | + false |
| 68 | + | Some typ -> |
| 69 | + match typ with |
| 70 | + | TestOnMocksType.Interactive -> |
| 71 | + isFullTest () |
| 72 | + | TestOnMocksType.True -> |
| 73 | + true |
| 74 | + |
| 75 | + let isTestMain = |
| 76 | + match results.TryGetResult CliArguments.Test_Main with |
| 77 | + | None -> false |
| 78 | + | Some _ -> true |
| 79 | + |
| 80 | + if isTestMain && isTestMocks then |
| 81 | + defaultMainThisAssembly args |
| 82 | + else |
| 83 | + defaultMainThisAssemblyFilter |
| 84 | + args |
| 85 | + (fun x -> |
| 86 | + x.Where(fun testName -> |
| 87 | + let testType = TestType.ofTestName testName |
| 88 | + match testType with |
| 89 | + | TestType.MainTest -> isTestMain |
| 90 | + | TestType.MockTest -> isTestMocks |
| 91 | + ) |
| 92 | + ) |
0 commit comments