forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scoop-GetOpts.Tests.ps1
71 lines (58 loc) · 2.29 KB
/
Scoop-GetOpts.Tests.ps1
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
. "$psscriptroot\Scoop-TestLib.ps1"
. "$psscriptroot\..\lib\getopt.ps1"
describe "getopt" {
it 'handle short option with required argument missing' {
$null, $null, $err = getopt '-x' 'x:' ''
$err | should be 'Option -x requires an argument.'
$null, $null, $err = getopt '-xy' 'x:y' ''
$err | should be 'Option -x requires an argument.'
}
it 'handle long option with required argument missing' {
$null, $null, $err = getopt '--arb' '' 'arb='
$err | should be 'Option --arb requires an argument.'
}
it 'handle unrecognized short option' {
$null, $null, $err = getopt '-az' 'a' ''
$err | should be 'Option -z not recognized.'
}
it 'handle unrecognized long option' {
$null, $null, $err = getopt '--non-exist' '' ''
$err | should be 'Option --non-exist not recognized.'
$null, $null, $err = getopt '--global','--another' 'abc:de:' 'global','one'
$err | should be 'Option --another not recognized.'
}
it 'remaining args returned' {
$opt, $rem, $err = getopt '-g','rem' 'g' ''
$err | should be $null
$opt.g | should be $true
$rem | should not be $null
$rem.length | should be 1
$rem[0] | should be 'rem'
}
it 'get a long flag and a short option with argument' {
$a = "--global -a 32bit test" -split ' '
$opt, $rem, $err = getopt $a 'ga:' 'global','arch='
$err | should be $null
$opt.global | should be $true
$opt.a | should be '32bit'
}
it 'handles regex characters' {
$a = "-?"
{ $opt, $rem, $err = getopt $a 'ga:' 'global' 'arch=' } | should not throw
{ $null, $null, $null = getopt $a '?:' 'help' | should not throw }
}
it 'handles short option without required argument' {
$null, $null, $err = getopt '-x' 'x' ''
$err | should be $null
}
it 'handles long option without required argument' {
$opt, $null, $err = getopt '--long-arg' '' 'long-arg'
$err | should be $null
$opt."long-arg" | should be $true
}
it 'handles long option with required argument' {
$opt, $null, $err = getopt '--long-arg', 'test' '' 'long-arg='
$err | should be $null
$opt."long-arg" | should be "test"
}
}