Skip to content

Commit 6373a7a

Browse files
committed
test: Improve tests for do-uninstall. Closes #33
1 parent d49b666 commit 6373a7a

File tree

4 files changed

+89
-34
lines changed

4 files changed

+89
-34
lines changed

pkg/lib/commands/do-link.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ do-link() {
2626
die "Package '$package' is already present"
2727
fi
2828

29+
# TODO: local git clone
2930
mkdir -p "$BPM_PACKAGES_PATH/$namespace"
3031
ln -s "$directory" "$BPM_PACKAGES_PATH/$package"
3132

pkg/lib/commands/do-uninstall.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ do-uninstall() {
2424

2525
if [ -d "$BPM_PACKAGES_PATH/$user/$repository" ]; then
2626
do_actual_uninstall "$user/$repository"
27-
elif [ -f "$BPM_PACKAGES_PATH/$user/$repository" ]; then
27+
elif [ -e "$BPM_PACKAGES_PATH/$user/$repository" ]; then
2828
rm -f "$BPM_PACKAGES_PATH/$user/$repository"
2929
else
3030
die "Package '$user/$repository' is not installed"
@@ -42,4 +42,5 @@ do_actual_uninstall() {
4242
do-plumbing-unlink-completions "$package"
4343

4444
rm -rf "${BPM_PACKAGES_PATH:?}/$package"
45+
rmdir --ignore-fail-on-non-empty "${BPM_PACKAGES_PATH:?}/${package%/*}"
4546
}

tests/do-uninstall.bats

Lines changed: 85 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,114 @@
33
load 'util/init.sh'
44

55
@test "fails if package is not installed" {
6-
run do-uninstall user/lol
6+
local pkg='user/repo'
7+
8+
run do-uninstall "$pkg"
79

810
assert_failure
9-
assert_output -e "Package 'user/lol' is not installed"
11+
assert_output -e "Package '$pkg' is not installed"
1012
}
1113

12-
@test "removes package directory" {
13-
local package="username/package"
14+
@test "succeeds if package is a file" {
15+
local pkg='user/repo'
16+
17+
mkdir -p "$BPM_PACKAGES_PATH/${pkg%/*}"
18+
touch "$BPM_PACKAGES_PATH/$pkg"
1419

15-
create_package 'username/package'
16-
test_util.fake_clone 'username/package'
17-
do-link "$BPM_ORIGIN_DIR/$package"
20+
[ -f "$BPM_PACKAGES_PATH/$pkg" ]
1821

19-
run do-uninstall 'username/package'
22+
run do-uninstall "$pkg"
2023

2124
assert_success
22-
[ ! -d "$BPM_PACKAGES_PATH/username/package" ]
25+
assert [ ! -e "$BPM_ORIGIN_DIR/$pkg" ]
2326
}
2427

25-
@test "removes package directory (if it happens to be a file)" {
26-
mkdir -p "$BPM_PACKAGES_PATH/theta"
27-
touch "$BPM_PACKAGES_PATH/theta/tango"
28+
@test "succeeds if package is an empty directory" {
29+
local pkg='user/repo'
30+
31+
mkdir -p "$BPM_PACKAGES_PATH/$pkg"
2832

29-
run do-uninstall 'theta/tango'
33+
run do-uninstall "$pkg"
3034

3135
assert_success
32-
[ ! -e "$BPM_PACKAGES_PATH/username/package" ]
36+
assert [ ! -e "$BPM_ORIGIN_DIR/$pkg" ]
3337
}
3438

35-
@test "removes binaries" {
36-
local package="username/package"
39+
@test "properly removes package directory" {
40+
local pkg="username/package"
3741

38-
create_package 'username/package'
39-
create_exec 'username/package' exec1
40-
test_util.fake_clone 'username/package'
41-
do-link "$BPM_ORIGIN_DIR/$package"
42+
test_util.setup_pkg "$pkg"; {
43+
touch 'bpm.toml'
44+
touch 'file.sh'
45+
}; test_util.finish_pkg
46+
test_util.fake_install "$pkg"
4247

43-
run do-uninstall 'username/package'
48+
run do-uninstall "$pkg"
4449

4550
assert_success
46-
[ ! -e "$BPM_INSTALL_BIN/exec1" ]
51+
assert [ ! -d "$BPM_PACKAGES_PATH/$pkg" ]
4752
}
4853

49-
@test "does not remove other package directories and binaries" {
50-
create_package 'username/package1'
51-
create_package 'username/package2'
52-
create_exec 'username/package1' exec1
53-
create_exec 'username/package2' exec2
54-
do-link "$BPM_ORIGIN_DIR/username/package1"
55-
do-link "$BPM_ORIGIN_DIR/username/package2"
54+
@test "properly removes package namespace directory, if it is empty" {
55+
local pkg="username/package"
56+
57+
test_util.setup_pkg "$pkg"; {
58+
touch 'bpm.toml'
59+
touch 'file.sh'
60+
}; test_util.finish_pkg
61+
test_util.fake_install "$pkg"
5662

57-
run do-uninstall 'bpm-local/package1'
63+
run do-uninstall "$pkg"
64+
65+
assert_success
66+
assert [ ! -d "$BPM_PACKAGES_PATH/$pkg" ]
67+
assert [ ! -d "$BPM_PACKAGES_PATH/${pkg%/*}" ]
68+
}
69+
70+
@test "properly removes binaries" {
71+
local pkg="username/package"
72+
73+
test_util.setup_pkg "$pkg"; {
74+
mkdir bin
75+
touch 'bin/exec1'
76+
touch 'exec2.sh'
77+
chmod +x 'exec2.sh'
78+
}; test_util.finish_pkg
79+
test_util.fake_install "$pkg"
80+
81+
run do-uninstall "$pkg"
5882

5983
assert_success
60-
[ ! -d "$BPM_PACKAGES_PATH/bpm-local/package1" ]
6184
[ ! -e "$BPM_INSTALL_BIN/exec1" ]
62-
[ -d "$BPM_PACKAGES_PATH/bpm-local/package2" ]
63-
[ -e "$BPM_INSTALL_BIN/exec2" ]
85+
[ ! -e "$BPM_INSTALL_BIN/exec2.sh" ]
86+
}
87+
88+
@test "properly keeps non-uninstalled package directories and binaries" {
89+
local pkg1='username/pkg1'
90+
local pkg2='username/pkg2'
91+
92+
test_util.setup_pkg "$pkg1"; {
93+
mkdir bin
94+
touch 'bin/exec1'
95+
}; test_util.finish_pkg
96+
test_util.fake_install "$pkg1"
97+
98+
test_util.setup_pkg "$pkg2"; {
99+
mkdir bin
100+
touch 'bin/exec2'
101+
}; test_util.finish_pkg
102+
test_util.fake_install "$pkg2"
103+
104+
assert [ -d "$BPM_PACKAGES_PATH/$pkg1" ]
105+
assert [ -e "$BPM_INSTALL_BIN/exec1" ]
106+
assert [ -d "$BPM_PACKAGES_PATH/$pkg2" ]
107+
assert [ -e "$BPM_INSTALL_BIN/exec2" ]
108+
109+
run do-uninstall "$pkg1"
110+
111+
assert_success
112+
assert [ ! -d "$BPM_PACKAGES_PATH/$pkg1" ]
113+
assert [ ! -e "$BPM_INSTALL_BIN/exec1" ]
114+
assert [ -d "$BPM_PACKAGES_PATH/$pkg2" ]
115+
assert [ -e "$BPM_INSTALL_BIN/exec2" ]
64116
}

tests/util/test_util.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ test_util.fake_clone() {
1717
git clone "$BPM_ORIGIN_DIR/$package" "$BPM_PACKAGES_PATH/$package"
1818
}
1919

20+
# TODO phase out in favor if do-link?
2021
# @description Clones the repository, and performs any linking, etc.
2122
test_util.fake_install() {
2223
local package="$1"

0 commit comments

Comments
 (0)