-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathScoop-GetOpts.Tests.ps1
More file actions
79 lines (65 loc) · 2.63 KB
/
Scoop-GetOpts.Tests.ps1
File metadata and controls
79 lines (65 loc) · 2.63 KB
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
72
73
74
75
76
77
78
79
. "$PSScriptRoot\Scoop-TestLib.ps1"
. "$PSScriptRoot\..\lib\getopt.ps1"
Describe 'getopt' -Tag 'Scoop' {
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 -BeNullOrEmpty
$opt.g | Should -BeTrue
$rem | Should -Not -BeNullOrEmpty
$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 -BeNullOrEmpty
$opt.global | Should -BeTrue
$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 -BeNullOrEmpty
}
It 'handles long option without required argument' {
$opt, $null, $err = getopt '--long-arg' '' 'long-arg'
$err | Should -BeNullOrEmpty
$opt.'long-arg' | Should -BeTrue
}
It 'handles long option with required argument' {
$opt, $null, $err = getopt '--long-arg', 'test' '' 'long-arg='
$err | Should -BeNullOrEmpty
$opt.'long-arg' | Should -Be 'test'
}
It 'handles the option terminator' {
$opt, $rem, $err = getopt '--long-arg', 'test', '--', '-x' 'x' 'long-arg='
$err | Should -BeNullOrEmpty
$opt.'long-arg' | Should -Be 'test'
$opt.'x' | Should -BeNullOrEmpty
$rem[0] | Should -Be '-x'
}
}