forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Scoop-GetOpts.Tests.ps1
71 lines (58 loc) · 2.35 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' -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'
}
}