Skip to content

Commit 27098dd

Browse files
committed
test: Improve test suite
Some tests failed to test what they were puported to test for. This fixes that, in addition to expanding tests for new behavior
1 parent 8aea2e1 commit 27098dd

File tree

4 files changed

+111
-9
lines changed

4 files changed

+111
-9
lines changed

pkg/lib/commands/do-upgrade.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ do-upgrade() {
5959
do_actual_upgrade() {
6060
local id="$1"
6161

62-
# Only upgrade if the package is a Git repository. If it is not, then
63-
# it's a package installed with 'link'
6462
if [ ! -d "$BPM_PACKAGES_PATH/$id/.git" ]; then
6563
die "Package at '$BPM_PACKAGES_PATH/$id' is not a Git repository"
6664
fi

pkg/lib/util/abstract-completions.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ abstract.completions_search_heuristics() {
9393
done
9494
done
9595
fi
96+
97+
for file in "$BPM_PACKAGES_PATH/$id"/{,etc/}*; do
98+
local fileName="${file##*/}"
99+
if [[ $fileName == *-completion.* ]]; then
100+
case "$fileName" in
101+
*.@(sh|bash)) abstract.completions_do_action_bash "$action" "$file" ;;
102+
*.zsh) abstract.completions_do_action_zsh "$action" "$file" ;;
103+
*.fish) abstract.completions_do_action_fish "$action" "$file" ;;
104+
esac
105+
fi
106+
done
96107
}
97108

98109
abstract.completions_do_action_bash() {

scripts/install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env sh
2+

tests/do-plumbing-link-completions.bats

Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ load 'util/init.sh'
4848
mkdir 'completions'
4949
touch 'completions/prof.bash'
5050
}; test_util.finish_pkg
51+
test_util.fake_add "$pkg"
5152

5253
run do-plumbing-link-completions "$site/$pkg"
5354

54-
! [ -f "$BPM_INSTALL_COMPLETIONS/bash/prof.bash" ]
55+
assert_success
56+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prof.bash" ]
5557
}
5658

5759
@test "adds bash completions determined from bpm.toml" {
@@ -80,15 +82,18 @@ load 'util/init.sh'
8082
mkdir 'completions'
8183
touch 'completions/prof.bash'
8284
}; test_util.finish_pkg
85+
test_util.fake_add "$pkg"
8386

8487
run do-plumbing-link-completions "$site/$pkg"
8588

86-
! [ -f "$BPM_INSTALL_COMPLETIONS/bash/prof.bash" ]
89+
assert_success
90+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prof.bash" ]
8791
}
8892

8993
@test "adds bash completions determined with heuristics (./?(contrib/)completion?(s))" {
9094
local site='github.com'
91-
local pkg="username/package$i"
95+
local pkg="username/package"
96+
9297
test_util.setup_pkg "$pkg"; {
9398
mkdir -p ./{contrib/,}completion{,s}
9499
touch "completion/c1.bash"
@@ -107,6 +112,23 @@ load 'util/init.sh'
107112
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/bash/c4.bash")" = "$BPM_PACKAGES_PATH/$site/$pkg/contrib/completions/c4.bash" ]
108113
}
109114

115+
@test "adds bash completions determined with heuristics (root directory)" {
116+
local site='github.com'
117+
local pkg="username/package"
118+
119+
test_util.setup_pkg "$pkg"; {
120+
mkdir 'etc'
121+
122+
touch 'git-flow-completion.bash'
123+
touch 'etc/some-completion.bash'
124+
}; test_util.finish_pkg
125+
test_util.fake_add "$pkg"
126+
127+
assert_success
128+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/bash/git-flow-completion.bash")" = "$BPM_PACKAGES_PATH/$site/$pkg/git-flow-completion.bash" ]
129+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/bash/some-completion.bash")" = "$BPM_PACKAGES_PATH/$site/$pkg/etc/some-completion.bash" ]
130+
}
131+
110132
@test "adds bash completions determined with heuristics (share/etc)" {
111133
local site='github.com'
112134
local pkg='username/package'
@@ -148,7 +170,8 @@ load 'util/init.sh'
148170

149171
run do-plumbing-link-completions "$site/$pkg"
150172

151-
[ -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
173+
assert_success
174+
assert [ -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
152175
}
153176

154177
@test "do not add bash completions from heuristics when BASH_COMPLETIONS is specified in package.sh" {
@@ -164,7 +187,8 @@ load 'util/init.sh'
164187

165188
run do-plumbing-link-completions "$site/$pkg"
166189

167-
[ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
190+
assert_success
191+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
168192
}
169193

170194
@test "do not add bash completions from heuristics when completionDirs is specified in bpm.toml" {
@@ -180,10 +204,32 @@ load 'util/init.sh'
180204

181205
run do-plumbing-link-completions "$site/$pkg"
182206

207+
assert_success
183208
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
184209
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
185210
}
186211

212+
@test "bash completions without file extension have an extension appended" {
213+
local site='github.com'
214+
local pkg="username/package"
215+
216+
test_util.setup_pkg "$pkg"; {
217+
mkdir -p 'share/bash-completion/completions'
218+
219+
touch 'share/bash-completion/completions/seven'
220+
}; test_util.finish_pkg
221+
test_util.fake_add "$pkg"
222+
223+
run do-plumbing-link-completions "$site/$pkg"
224+
225+
assert_success
226+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/bash/seven.bash")" = "$BPM_PACKAGES_PATH/$site/$pkg/share/bash-completion/completions/seven" ]
227+
228+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
229+
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/bash/prog.bash" ]
230+
}
231+
232+
187233
## ZSH ##
188234

189235
@test "adds zsh compsys completions determined from package.sh" {
@@ -274,6 +320,23 @@ load 'util/init.sh'
274320
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compsys//c4.zsh")" = "$BPM_PACKAGES_PATH/$site/$pkg/contrib/completions/c4.zsh" ]
275321
}
276322

323+
@test "adds zsh completions determined with heuristics (root directory)" {
324+
local site='github.com'
325+
local pkg="username/package"
326+
327+
test_util.setup_pkg "$pkg"; {
328+
mkdir 'etc'
329+
330+
touch 'git-flow-completion.zsh'
331+
touch 'etc/some-completion.zsh'
332+
}; test_util.finish_pkg
333+
test_util.fake_add "$pkg"
334+
335+
assert_success
336+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compctl/git-flow-completion.zsh")" = "$BPM_PACKAGES_PATH/$site/$pkg/git-flow-completion.zsh" ]
337+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compctl/some-completion.zsh")" = "$BPM_PACKAGES_PATH/$site/$pkg/etc/some-completion.zsh" ]
338+
}
339+
277340
@test "adds zsh completions determined from heuristics when when BASH_COMPLETIONS is specified in package.sh" {
278341
local site='github.com'
279342
local pkg="username/package"
@@ -306,6 +369,7 @@ load 'util/init.sh'
306369

307370
run do-plumbing-link-completions "$site/$pkg"
308371

372+
assert_success
309373
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/zsh/compctl/prog.zsh" ]
310374
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/zsh/compsys/prog.zsh" ]
311375
}
@@ -323,10 +387,15 @@ load 'util/init.sh'
323387

324388
run do-plumbing-link-completions "$site/$pkg"
325389

390+
assert_success
326391
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/zsh/compctl/prog.zsh" ]
327392
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/zsh/compsys/prog.zsh" ]
328393
}
329394

395+
@test "zsh completions without file extension have an extension appended" {
396+
skip
397+
}
398+
330399

331400
## FISH ##
332401

@@ -356,15 +425,18 @@ load 'util/init.sh'
356425
mkdir 'completions'
357426
touch 'completions/prof.fish'
358427
}; test_util.finish_pkg
428+
test_util.fake_add "$pkg"
359429

360430
run do-plumbing-link-completions "$site/$pkg"
361431

362-
! [ -f "$BPM_INSTALL_COMPLETIONS/fish/prof.fish" ]
432+
assert_success
433+
assert_success [ ! -f "$BPM_INSTALL_COMPLETIONS/fish/prof.fish" ]
363434
}
364435

365436
@test "adds fish completions determined with heuristics (./?(contrib/)completion?(s))" {
366437
local site='github.com'
367-
local pkg="username/package$i"
438+
local pkg="username/package"
439+
368440
test_util.setup_pkg "$pkg"; {
369441
mkdir -p ./{contrib/,}completion{,s}
370442
touch "completion/c1.fish"
@@ -383,6 +455,23 @@ load 'util/init.sh'
383455
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/fish/c4.fish")" = "$BPM_PACKAGES_PATH/$site/$pkg/contrib/completions/c4.fish" ]
384456
}
385457

458+
@test "adds fish completions determined with heuristics (root directory)" {
459+
local site='github.com'
460+
local pkg="username/package"
461+
462+
test_util.setup_pkg "$pkg"; {
463+
mkdir 'etc'
464+
465+
touch 'git-flow-completion.fish'
466+
touch 'etc/some-completion.fish'
467+
}; test_util.finish_pkg
468+
test_util.fake_add "$pkg"
469+
470+
assert_success
471+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/fish/git-flow-completion.fish")" = "$BPM_PACKAGES_PATH/$site/$pkg/git-flow-completion.fish" ]
472+
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/fish/some-completion.fish")" = "$BPM_PACKAGES_PATH/$site/$pkg/etc/some-completion.fish" ]
473+
}
474+
386475
@test "do not add fish completions from heuristics when completionDirs is specified in bpm.toml" {
387476
local site='github.com'
388477
local pkg="username/package"
@@ -396,6 +485,7 @@ load 'util/init.sh'
396485

397486
run do-plumbing-link-completions "$site/$pkg"
398487

488+
assert_success
399489
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/fish/prog.fish" ]
400490
assert [ ! -f "$BPM_INSTALL_COMPLETIONS/fish/prog.fish" ]
401491
}
@@ -418,6 +508,7 @@ load 'util/init.sh'
418508

419509
run do-plumbing-link-completions "$site/$pkg"
420510

511+
assert_success
421512
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/fish/prog.fish")" = "$BPM_PACKAGES_PATH/$site/$pkg/completion/prog.fish" ]
422513
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/bash/prog1.bash")" = "$BPM_PACKAGES_PATH/$site/$pkg/completion/prog1.bash" ]
423514
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/bash/prog2.bash")" = "$BPM_PACKAGES_PATH/$site/$pkg/completions/prog2.bash" ]

0 commit comments

Comments
 (0)