Skip to content

Commit 6d48fcb

Browse files
committed
test(refactor): Use 'test_util.setup_pkg' for all tests and use 'pkg' variable
This will make it easier to fix the tests when #35 is introduced
1 parent fc7de31 commit 6d48fcb

File tree

3 files changed

+233
-267
lines changed

3 files changed

+233
-267
lines changed

tests/do-plumbing-link-completions.bats

Lines changed: 139 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
load 'util/init.sh'
44

5-
@test "does not fail if there are no binaries" {
5+
@test "does not fail if there are no completions" {
66
local pkg='username/package'
77

88
test_util.setup_pkg "$pkg"; {
@@ -15,6 +15,9 @@ load 'util/init.sh'
1515
assert_success
1616
}
1717

18+
19+
## BASH ##
20+
1821
@test "adds bash completions determined from package.sh" {
1922
local pkg='username/package'
2023

@@ -75,7 +78,7 @@ load 'util/init.sh'
7578
! [ -f "$BPM_INSTALL_COMPLETIONS/bash/prof.bash" ]
7679
}
7780

78-
@test "adds bash completions determined with heuristics ./?(contrib/)completion?(s)" {
81+
@test "adds bash completions determined with heuristics (./?(contrib/)completion?(s))" {
7982
local pkg="username/package$i"
8083

8184
test_util.setup_pkg "$pkg"; {
@@ -99,116 +102,180 @@ load 'util/init.sh'
99102
@test "adds bash completions determined from heuristics when when ZSH_COMPLETIONS is specified in package.sh" {
100103
local pkg="username/package"
101104

102-
test_util.setup_pkg "$pkg"; {'
103-
echo "ZSH_COMPLETIONS="' > 'package.sh'
105+
test_util.setup_pkg "$pkg"; {
106+
echo 'ZSH_COMPLETIONS=""' > 'package.sh'
104107
mkdir 'completion'
105108
touch "completion/prog.bash"
106109
}; test_util.finish_pkg
107110
test_util.fake_install "$pkg"
108111

109-
run do-plumbing-link-completions "$package"
112+
run do-plumbing-link-completions "$pkg"
110113

111114
[ -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
112115
}
113116

114-
@test "links zsh compsys completions to prefix/completions" {
115-
local package="username/package"
117+
@test "do not add bash completions from heuristics when BASH_COMPLETIONS is specified in package.sh" {
118+
local pkg="username/package"
116119

117-
create_package username/package
118-
create_zsh_compsys_completions username/package _exec
119-
test_util.fake_clone "$package"
120+
test_util.setup_pkg "$pkg"; {
121+
echo 'BASH_COMPLETIONS=""' > 'package.sh'
122+
mkdir 'completion'
123+
touch "completion/prog.bash"
124+
}; test_util.finish_pkg
125+
test_util.fake_install "$pkg"
120126

121-
run do-plumbing-link-completions username/package
127+
run do-plumbing-link-completions "$pkg"
122128

123-
assert_success
124-
assert [ "$(readlink $BPM_INSTALL_COMPLETIONS/zsh/compsys/_exec)" = "$BPM_PACKAGES_PATH/username/package/completions/_exec" ]
129+
[ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
125130
}
126131

127-
@test "links zsh compctl completions to prefix/completions" {
128-
local package="username/package"
132+
@test "do not add bash completions from heuristics when completionDirs is specified in bpm.toml" {
133+
local pkg="username/package"
129134

130-
create_package username/package
131-
create_zsh_compctl_completions username/package exec
132-
test_util.fake_clone "$package"
135+
test_util.setup_pkg "$pkg"; {
136+
echo 'completionDirs = [ "dirr" ]' > 'bpm.toml'
137+
mkdir 'completion'
138+
touch "completion/prog.bash"
139+
}; test_util.finish_pkg
140+
test_util.fake_install "$pkg"
133141

134-
run do-plumbing-link-completions username/package
142+
run do-plumbing-link-completions "$pkg"
135143

136-
assert_success
137-
assert [ "$(readlink $BPM_INSTALL_COMPLETIONS/zsh/compctl/exec)" = "$BPM_PACKAGES_PATH/username/package/completions/exec" ]
144+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
145+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
138146
}
139147

140-
@test "links zsh completions from ./?(contrib/)completion?(s)" {
141-
local -i i=1
142-
for completion_dir in completion completions contrib/completion contrib/completions; do
143-
local package="username/package$i"
148+
## ZSH ##
144149

145-
create_package "$package"
146-
cd "$BPM_ORIGIN_DIR/$package"
147-
mkdir -p "$completion_dir"
148-
touch "$completion_dir/c.zsh"
149-
echo "#compdef" >| "$completion_dir/c2.zsh"
150-
git add .
151-
git commit -m "Add completions"
152-
cd "$BPM_CWD"
153-
test_util.fake_clone "$package"
150+
@test "adds zsh compsys completions determined from package.sh" {
151+
local pkg="username/package"
154152

155-
run do-plumbing-link-completions "$package"
153+
test_util.setup_pkg "$pkg"; {
154+
echo 'ZSH_COMPLETIONS="dirr/_exec"' > 'package.sh'
155+
mkdir 'dirr'
156+
echo '#compdef' > "dirr/_exec"
157+
}; test_util.finish_pkg
158+
test_util.fake_install "$pkg"
156159

157-
assert_success
158-
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compsys/c2.zsh")" = "$BPM_PACKAGES_PATH/$package/$completion_dir/c2.zsh" ]
159-
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compctl/c.zsh")" = "$BPM_PACKAGES_PATH/$package/$completion_dir/c.zsh" ]
160+
run do-plumbing-link-completions "$pkg"
160161

161-
(( ++i ))
162-
done
162+
assert_success
163+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compsys/_exec")" = "$BPM_PACKAGES_PATH/$pkg/dirr/_exec" ]
163164
}
164165

165-
@test "don't link bash from './?(contrib/)completion?(s)' when ZSH_COMPLETIONS is specified in package.sh" {
166-
local package="username/package"
166+
@test "adds zsh compctl completions determined from pacakge.sh" {
167+
local pkg="username/package"
168+
169+
test_util.setup_pkg "$pkg"; {
170+
echo 'ZSH_COMPLETIONS="dirr/exec"' > 'package.sh'
171+
mkdir 'dirr'
172+
touch "dirr/exec"
173+
}; test_util.finish_pkg
174+
test_util.fake_install "$pkg"
167175

168-
create_package "$package"
169-
cd "$BPM_ORIGIN_DIR/$package"
170-
mkdir completions
171-
touch completions/prog.zsh
172-
echo "ZSH_COMPLETIONS=" >| package.sh
173-
git add .
174-
git commit -m 'Add package.sh'
175-
cd "$BPM_CWD"
176-
test_util.fake_clone "$package"
176+
run do-plumbing-link-completions "$pkg"
177+
178+
assert_success
179+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compctl/exec")" = "$BPM_PACKAGES_PATH/$pkg/dirr/exec" ]
180+
}
181+
182+
@test "adds zsh compsys completions determined from bpm.toml" {
183+
local pkg="username/package"
184+
185+
test_util.setup_pkg "$pkg"; {
186+
echo 'completionDirs = [ "dirr" ]' > 'bpm.toml'
187+
mkdir 'dirr'
188+
echo '#compdef' > "dirr/_exec.zsh"
189+
}; test_util.finish_pkg
190+
test_util.fake_install "$pkg"
177191

178-
run do-plumbing-link-completions "$package"
192+
run do-plumbing-link-completions "$pkg"
179193

180194
assert_success
181-
! [ -f "$BPM_INSTALL_COMPLETIONS/zsh/compctl/prof.zsh" ]
182-
! [ -f "$BPM_INSTALL_COMPLETIONS/zsh/compsys/prof.zsh" ]
195+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compsys/_exec.zsh")" = "$BPM_PACKAGES_PATH/$pkg/dirr/_exec.zsh" ]
183196
}
184197

185-
@test "do link zsh from './?(contrib/)completion?(s)' when BASH_COMPLETIONS is specified in package.sh" {
186-
local package="username/package"
198+
@test "adds zsh compctl completions determined from bpm.toml" {
199+
local pkg="username/package"
187200

188-
create_package "$package"
189-
cd "$BPM_ORIGIN_DIR/$package"
190-
mkdir completions
191-
touch completions/prog.zsh
192-
echo "BASH_COMPLETIONS=" >| package.sh
193-
git add .
194-
git commit -m 'Add package.sh'
195-
cd "$BPM_CWD"
196-
test_util.fake_clone "$package"
201+
test_util.setup_pkg "$pkg"; {
202+
echo 'completionDirs = [ "dirr" ]' > 'bpm.toml'
203+
mkdir 'dirr'
204+
touch "dirr/exec.zsh"
205+
}; test_util.finish_pkg
206+
test_util.fake_install "$pkg"
197207

198-
run do-plumbing-link-completions "$package"
208+
run do-plumbing-link-completions "$pkg"
199209

200210
assert_success
201-
[ -f "$BPM_INSTALL_COMPLETIONS/zsh/compctl/prog.zsh" ]
211+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compctl/exec.zsh")" = "$BPM_PACKAGES_PATH/$pkg/dirr/exec.zsh" ]
202212
}
203213

214+
@test "adds zsh completions determined with heuristics (./?(contrib/)completion?(s))" {
215+
local pkg="username/package"
216+
217+
test_util.setup_pkg "$pkg"; {
218+
mkdir -p ./{contrib/,}completion{,s}
219+
touch "completion/c1.zsh"
220+
echo '#compdef' > "completions/c2.zsh"
221+
touch "contrib/completion/c3.zsh"
222+
echo '#compdef' > "contrib/completions/c4.zsh"
223+
}; test_util.finish_pkg
224+
test_util.fake_install "$pkg"
225+
226+
assert_success
227+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compctl/c1.zsh")" = "$BPM_PACKAGES_PATH/$pkg/completion/c1.zsh" ]
228+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compsys//c2.zsh")" = "$BPM_PACKAGES_PATH/$pkg/completions/c2.zsh" ]
229+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compctl/c3.zsh")" = "$BPM_PACKAGES_PATH/$pkg/contrib/completion/c3.zsh" ]
230+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compsys//c4.zsh")" = "$BPM_PACKAGES_PATH/$pkg/contrib/completions/c4.zsh" ]
231+
}
204232

205-
@test "does not fail if package doesn't have any completions" {
206-
local package="username/package"
233+
@test "adds zsh completions determined from heuristics when when BASH_COMPLETIONS is specified in package.sh" {
234+
local pkg="username/package"
207235

208-
create_package username/package
209-
test_util.fake_clone "$package"
236+
test_util.setup_pkg "$pkg"; {
237+
echo 'BASH_COMPLETIONS=""' > 'package.sh'
238+
mkdir completion{,s}
239+
touch "completion/c1.zsh"
240+
echo '#compdef' > "completions/c2.zsh"
241+
}; test_util.finish_pkg
242+
test_util.fake_install "$pkg"
210243

211-
run do-plumbing-link-completions username/package
244+
run do-plumbing-link-completions "$pkg"
212245

213246
assert_success
247+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compctl/c1.zsh")" = "$BPM_PACKAGES_PATH/$pkg/completion/c1.zsh" ]
248+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compsys//c2.zsh")" = "$BPM_PACKAGES_PATH/$pkg/completions/c2.zsh" ]
249+
}
250+
251+
@test "do not add zsh completions from heuristics when ZSH_COMPLETIONS is specified in package.sh" {
252+
local pkg="username/package"
253+
254+
test_util.setup_pkg "$pkg"; {
255+
echo 'ZSH_COMPLETIONS=""' > 'package.sh'
256+
mkdir 'completion'
257+
touch "completion/prog.zsh"
258+
}; test_util.finish_pkg
259+
test_util.fake_install "$pkg"
260+
261+
run do-plumbing-link-completions "$pkg"
262+
263+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/zsh/compctl/prog.zsh" ]
264+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/zsh/compsys/prog.zsh" ]
265+
}
266+
267+
@test "do not add zsh completions from heuristics when completionDirs is specified in bpm.toml" {
268+
local pkg="username/package"
269+
270+
test_util.setup_pkg "$pkg"; {
271+
echo 'completionDirs = [ "dirr" ]' > 'bpm.toml'
272+
mkdir 'completion'
273+
touch "completion/prog.zsh"
274+
}; test_util.finish_pkg
275+
test_util.fake_install "$pkg"
276+
277+
run do-plumbing-link-completions "$pkg"
278+
279+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/zsh/compctl/prog.zsh" ]
280+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/zsh/compsys/prog.zsh" ]
214281
}

0 commit comments

Comments
 (0)