@@ -7,11 +7,9 @@ open Utils
7
7
open Input
8
8
open System.CommandLine .Parsing
9
9
10
- let mutable handlerCalled = false
10
+ let mutable actionCalled = false
11
11
[<SetUp>]
12
- let setup () = handlerCalled <- false
13
- [<TearDown>]
14
- let tearDown () = handlerCalled =! true
12
+ let setup () = actionCalled <- false
15
13
16
14
[<Test>]
17
15
let ``01 -- word Hello - w World - s * return unit`` () =
@@ -26,9 +24,10 @@ let ``01 --word Hello -w World -s * return unit`` () =
26
24
setAction ( fun ( words , separator ) ->
27
25
words =! [| " Hello" ; " World" |]
28
26
separator =! Some " *"
29
- handlerCalled <- true
27
+ actionCalled <- true
30
28
)
31
29
} =! 0
30
+ actionCalled =! true
32
31
33
32
[<Test>]
34
33
let ``02 -- word Hello - w World return unit`` () =
@@ -41,9 +40,10 @@ let ``02 --word Hello -w World return unit`` () =
41
40
setAction ( fun ( words , separator ) ->
42
41
words =! [| " Hello" ; " World" |]
43
42
separator =! None
44
- handlerCalled <- true
43
+ actionCalled <- true
45
44
)
46
45
} =! 0
46
+ actionCalled =! true
47
47
48
48
[<Test>]
49
49
let ``03 -- word Hello - w World - s * return int`` () =
@@ -56,10 +56,11 @@ let ``03 --word Hello -w World -s * return int`` () =
56
56
setAction ( fun ( words , separator ) ->
57
57
words =! [| " Hello" ; " World" |]
58
58
separator =! Some " *"
59
- handlerCalled <- true
59
+ actionCalled <- true
60
60
5
61
61
)
62
62
} =! 5
63
+ actionCalled =! true
63
64
64
65
[<Test>]
65
66
let ``04 -- word Hello - w World - s * return int using manual configured options`` () =
@@ -72,10 +73,11 @@ let ``04 --word Hello -w World -s * return int using manual configured options``
72
73
setAction ( fun ( words , separator ) ->
73
74
words =! [| " Hello" ; " World" |]
74
75
separator =! Some " *"
75
- handlerCalled <- true
76
+ actionCalled <- true
76
77
5
77
78
)
78
79
} =! 5
80
+ actionCalled =! true
79
81
80
82
[<Test>]
81
83
let ``05 empty array`` () =
@@ -88,9 +90,10 @@ let ``05 empty array`` () =
88
90
setAction ( fun ( words , separator ) ->
89
91
words =! [||]
90
92
separator =! Some " *"
91
- handlerCalled <- true
93
+ actionCalled <- true
92
94
)
93
95
} =! 0
96
+ actionCalled =! true
94
97
95
98
/// In beta5, the action handler is never called if an input starts with "@", even if ResponseFileTokenReplacer is set to null.
96
99
[<Test>]
@@ -104,7 +107,7 @@ let ``06 - rootCommand should use configuration`` () =
104
107
//inputs (Input.Option<string>("package", [ "--package"; "-p" ], "A package with a leading @ name"))
105
108
inputs ( option " --package" |> aliases [ " -p" ] |> desc " A package with a leading @ name" )
106
109
setAction ( fun ( package : string ) ->
107
- handlerCalled <- true
110
+ actionCalled <- true
108
111
if package.StartsWith( " @" ) then
109
112
printfn $" {package}"
110
113
0 // success
@@ -113,6 +116,7 @@ let ``06 - rootCommand should use configuration`` () =
113
116
1 // failure
114
117
)
115
118
} =! 0
119
+ actionCalled =! true
116
120
117
121
[<Test>]
118
122
let ``07 - Child command should use configuration`` () =
@@ -124,7 +128,7 @@ let ``07 - Child command should use configuration`` () =
124
128
|> desc " A package with a leading @ name"
125
129
)
126
130
setAction ( fun ( package : string ) ->
127
- handlerCalled <- true
131
+ actionCalled <- true
128
132
if package.StartsWith( " @" ) then
129
133
printfn $" {package}"
130
134
0 // success
@@ -143,10 +147,10 @@ let ``07 - Child command should use configuration`` () =
143
147
noAction
144
148
addCommand getCmd
145
149
} =! 0
150
+ actionCalled =! true
146
151
147
152
[<Test>]
148
153
let ``08 - Validators`` () =
149
- handlerCalled <- true // Set to true to avoid false negatives in the test
150
154
let args = args " -w delete -s *"
151
155
let cfg =
152
156
commandLineConfiguration {
@@ -174,4 +178,26 @@ let ``08 - Validators`` () =
174
178
175
179
printfn $" {cfg.Error}"
176
180
let result = cfg.Invoke( args)
177
- result =! 1 // Expecting a failure due to the separator validation
181
+ result =! 1 // Expecting a failure due to the separator validation
182
+ actionCalled =! false
183
+
184
+ [<Test>]
185
+ let ``09 tryParser Directory Info`` () =
186
+ testRootCommand " --directory .." {
187
+ description " Custom parser for directory info"
188
+ inputs (
189
+ option< System.IO.DirectoryInfo> " --directory"
190
+ |> desc " A directory path"
191
+ |> required
192
+ |> tryParse ( fun res ->
193
+ let path = res.Tokens[ 0 ]. Value
194
+ if path = " .."
195
+ then Error " '..' is not a valid directory"
196
+ else Ok ( System.IO.DirectoryInfo path)
197
+ )
198
+ )
199
+ setAction ( fun dir ->
200
+ printfn $" Directory: {dir}"
201
+ )
202
+ } =! 1 // Should fail
203
+ actionCalled =! false
0 commit comments