Skip to content

Commit 892e800

Browse files
committed
test: add more richer command support for the test program
1 parent 9f893c8 commit 892e800

File tree

6 files changed

+178
-29
lines changed

6 files changed

+178
-29
lines changed

.vscode/tasks.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,51 @@
3333
},
3434
"problemMatcher": []
3535
},
36+
{
37+
"label": "TestsRunMock",
38+
"type": "shell",
39+
"command": "dotnet",
40+
"args": [
41+
"fake",
42+
"build",
43+
"-t",
44+
"TestsRunMock"
45+
],
46+
"group": {
47+
"kind": "test",
48+
},
49+
"problemMatcher": []
50+
},
51+
{
52+
"label": "TestsRunFull",
53+
"type": "shell",
54+
"command": "dotnet",
55+
"args": [
56+
"fake",
57+
"build",
58+
"-t",
59+
"TestsRunFull"
60+
],
61+
"group": {
62+
"kind": "test",
63+
},
64+
"problemMatcher": []
65+
},
66+
{
67+
"label": "TestsRunInteractiveFull",
68+
"type": "shell",
69+
"command": "dotnet",
70+
"args": [
71+
"fake",
72+
"build",
73+
"-t",
74+
"TestsRunInteractiveFull"
75+
],
76+
"group": {
77+
"kind": "test",
78+
},
79+
"problemMatcher": []
80+
},
3681
{
3782
"label": "CliBuild",
3883
"type": "shell",

build.fsx

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ let dotnetBuild =
6161
|> String.concat " "
6262
dotnet (sprintf "build %s" commonBuildArgs)
6363

64-
let dotnetRun framework =
65-
dotnet (sprintf "run --framework %s" framework)
64+
let dotnetRun framework args =
65+
dotnet (sprintf "run --framework %s -- %s" framework args)
6666

6767
Target.create "CoreMeta" (fun _ ->
6868
let release = ReleaseNotes.load (parserProjDir </> "RELEASE_NOTES.md")
@@ -173,8 +173,49 @@ Target.create "CliBuild" (fun _ ->
173173
|> dotnetBuild
174174
)
175175

176+
[<RequireQualifiedAccess>]
177+
type TestOnMocksType =
178+
| True
179+
| Interactive
180+
181+
module TestOnMocksType =
182+
let toString typ =
183+
match typ with
184+
| TestOnMocksType.True -> "true"
185+
| TestOnMocksType.Interactive -> "interactive"
186+
187+
let testsRun isTestMain (isTestMocks: TestOnMocksType option) =
188+
let args =
189+
[
190+
if isTestMain then
191+
"--test-main"
192+
match isTestMocks with
193+
| None -> ""
194+
| Some typ ->
195+
let typ = TestOnMocksType.toString typ
196+
sprintf "--test-mocks %s" typ
197+
]
198+
|> String.concat " "
199+
200+
Path.getDirectory testProjPath
201+
|> dotnetRun
202+
"netcoreapp3.1"
203+
args
204+
176205
Target.create "TestsRun" (fun _ ->
177-
dotnetRun "netcoreapp3.1" (Path.getDirectory testProjPath)
206+
testsRun true None
207+
)
208+
209+
Target.create "TestsRunMock" (fun _ ->
210+
testsRun false (Some TestOnMocksType.True)
211+
)
212+
213+
Target.create "TestsRunFull" (fun _ ->
214+
testsRun true (Some TestOnMocksType.True)
215+
)
216+
217+
Target.create "TestsRunInteractiveFull" (fun _ ->
218+
testsRun true (Some TestOnMocksType.Interactive)
178219
)
179220

180221
Target.create "TrimTrailingWhitespace" (fun _ ->

paket.dependencies

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ group Tests
4444

4545
nuget FSharp.Core >= 4.7.2 lowest_matching: true
4646
nuget Fuchu >= 1.1 lowest_matching: true
47+
nuget Argu >= 6.1.1 lowest_matching: true
4748

4849
source https://gitlab.com/api/v4/projects/28574921/packages/nuget/index.json
4950
nuget FSharpMyExt >= 2.0.0-prerelease.8 lowest_matching: true

paket.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,9 @@ STRATEGY: MIN
700700
RESTRICTION: || (== net461) (== netcoreapp3.1)
701701
NUGET
702702
remote: https://api.nuget.org/v3/index.json
703+
Argu (6.1.1)
704+
FSharp.Core (>= 4.3.2) - restriction: || (&& (== net461) (>= netstandard2.0)) (== netcoreapp3.1)
705+
System.Configuration.ConfigurationManager (>= 4.4) - restriction: || (&& (== net461) (>= netstandard2.0)) (== netcoreapp3.1)
703706
dotenv.net (3.1.2)
704707
FParsec (1.1.1)
705708
FSharp.Core (>= 4.3.4)
@@ -715,10 +718,13 @@ NUGET
715718
Newtonsoft.Json (12.0.3)
716719
Newtonsoft.Json.Bson (1.0.2)
717720
Newtonsoft.Json (>= 12.0.1)
721+
System.Configuration.ConfigurationManager (4.4) - restriction: || (&& (== net461) (>= netstandard2.0)) (== netcoreapp3.1)
722+
System.Security.Cryptography.ProtectedData (>= 4.4) - restriction: || (&& (== net461) (>= netcoreapp2.0)) (== netcoreapp3.1)
718723
System.Drawing.Common (4.7)
719724
Microsoft.NETCore.Platforms (>= 3.1) - restriction: || (&& (== net461) (>= netcoreapp2.0)) (== netcoreapp3.1)
720725
Microsoft.Win32.SystemEvents (>= 4.7) - restriction: || (&& (== net461) (>= netcoreapp2.0)) (== netcoreapp3.1)
721726
System.Runtime.InteropServices.RuntimeInformation (4.3) - restriction: || (== net461) (&& (== netcoreapp3.1) (>= net461))
727+
System.Security.Cryptography.ProtectedData (4.4) - restriction: || (&& (== net461) (>= netcoreapp2.0)) (== netcoreapp3.1)
722728
System.ValueTuple (4.4) - restriction: || (== net461) (&& (== netcoreapp3.1) (>= net45))
723729
TextCopy (4.2)
724730
Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.4)
Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,92 @@
11
module Qsp.Tests.Test
22
open Fuchu
3+
open Argu
34

45
open Qsp
56
open Tests
67

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+
734
[<EntryPoint;System.STAThread>]
835
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")
3037
match args with
31-
| [|"--full"|] ->
32-
f true
3338
| [||] ->
34-
f (isFullTest ())
39+
argParser.PrintUsage() |> printfn "%s"
40+
0
3541
| _ ->
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+
)

tests/Qsp.FSharp.Core.Tests/paket.references

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ group Tests
22
FSharp.Core
33
FuChu
44
FSharpMyExt
5+
Argu

0 commit comments

Comments
 (0)