forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoop-Core.Tests.ps1
135 lines (105 loc) · 3.85 KB
/
Scoop-Core.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\install.ps1"
. "$psscriptroot\Scoop-TestLib.ps1"
describe "movedir" {
$extract_dir = "subdir"
$extract_to = $null
beforeall {
$working_dir = setup_working "movedir"
}
it "moves directories with no spaces in path" {
$dir = "$working_dir\user"
movedir "$dir\_scoop_extract\$extract_dir" "$dir\$extract_to"
"$dir\test.txt" | should contain "this is the one"
"$dir\_scoop_extract\$extract_dir" | should not exist
}
it "moves directories with spaces in path" {
$dir = "$working_dir\user with space"
movedir "$dir\_scoop_extract\$extract_dir" "$dir\$extract_to"
"$dir\test.txt" | should contain "this is the one"
"$dir\_scoop_extract\$extract_dir" | should not exist
# test trailing \ in from dir
movedir "$dir\_scoop_extract\$null" "$dir\another"
"$dir\another\test.txt" | should contain "testing"
"$dir\_scoop_extract" | should not exist
}
it "moves directories with quotes in path" {
$dir = "$working_dir\user with 'quote"
movedir "$dir\_scoop_extract\$extract_dir" "$dir\$extract_to"
"$dir\test.txt" | should contain "this is the one"
"$dir\_scoop_extract\$extract_dir" | should not exist
}
}
describe "unzip_old" {
beforeall {
$working_dir = setup_working "unzip_old"
}
function test-unzip($from) {
$to = strip_ext $from
unzip_old $from $to
$to
}
context "zip file size is zero bytes" {
$zerobyte = "$working_dir\zerobyte.zip"
it "unzips file with zero bytes without error" {
$to = test-unzip $zerobyte
$to | should exist
(gci $to).count | should be 0
}
}
context "zip file is small in size" {
$small = "$working_dir\small.zip"
it "unzips file which is small in size" {
$to = test-unzip $small
$to | should exist
# these don't work for some reason on appveyor
#join-path $to "empty" | should exist
#(gci $to).count | should be 1
}
}
}
describe "shim" {
beforeall {
$working_dir = setup_working "shim"
$shimdir = shimdir
$(ensure_in_path $shimdir) | out-null
}
it "links a file onto the user's path" {
{ get-command "shim-test" -ea stop } | should throw
{ get-command "shim-test.ps1" -ea stop } | should throw
{ get-command "shim-test.cmd" -ea stop } | should throw
{ shim-test } | should throw
shim "$working_dir\shim-test.ps1" $false "shim-test"
{ get-command "shim-test" -ea stop } | should not throw
{ get-command "shim-test.ps1" -ea stop } | should not throw
{ get-command "shim-test.cmd" -ea stop } | should not throw
shim-test | should be "Hello, world!"
}
context "user with quote" {
it "shims a file with quote in path" {
{ get-command "shim-test" -ea stop } | should throw
{ shim-test } | should throw
shim "$working_dir\user with 'quote\shim-test.ps1" $false "shim-test"
{ get-command "shim-test" -ea stop } | should not throw
shim-test | should be "Hello, world!"
}
}
aftereach {
rm_shim "shim-test" $shimdir
}
}
describe "rm_shim" {
beforeall {
$working_dir = setup_working "shim"
$shimdir = shimdir
$(ensure_in_path $shimdir) | out-null
}
it "removes shim from path" {
shim "$working_dir\shim-test.ps1" $false "shim-test"
rm_shim "shim-test" $shimdir
{ get-command "shim-test" -ea stop } | should throw
{ get-command "shim-test.ps1" -ea stop } | should throw
{ get-command "shim-test.cmd" -ea stop } | should throw
{ shim-test } | should throw
}
}