Skip to content

Commit da65586

Browse files
committed
refactor: Add Check to ensure package existance before linking. Closes #28
This increases the integrity of tests that install a package, then uninstall that package, and test if a file does not exist
1 parent 8b08569 commit da65586

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

pkg/lib/commands/do-plumbing-deps.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
do-plumbing-deps() {
1010
local package="$1"
1111
ensure.nonZero 'package' "$package"
12+
ensure.packageExists "$package"
1213

1314
local -a deps=()
1415

pkg/lib/commands/do-plumbing-link-bins.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
do-plumbing-link-bins() {
44
local package="$1"
55
ensure.nonZero 'package' "$package"
6+
ensure.packageExists "$package"
67

78
log.info "Linking bin files for '$package'"
89

pkg/lib/commands/do-plumbing-link-completions.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
do-plumbing-link-completions() {
44
local package="$1"
55
ensure.nonZero 'package' "$package"
6+
ensure.packageExists "$package"
67

78
log.info "Linking completion files for '$package'"
89

pkg/lib/commands/do-plumbing-link-man.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
do-plumbing-link-man() {
55
local package="$1"
66
ensure.nonZero 'package' "$package"
7+
ensure.packageExists "$package"
78

89
log.info "Linking man files for '$package'"
910

pkg/lib/util/ensure.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,18 @@ ensure.nonZero() {
2424
die "Variable '$varName' must be non-zero. Please check the validity of your passed arguments"
2525
fi
2626
}
27+
28+
# @description This is a check to determine if a package actually exists.
29+
# If it does not, then the program fails. This was created to increase
30+
# the integrity of the testing suite. Most of the callsites of this
31+
# function are in 'do-plumbing-link' since we expect a package to exist
32+
# before performing operations on it. This contrasts 'do-plumbing-unlink' -
33+
# that is not an expectation
34+
# @arg $1 package
35+
ensure.packageExists() {
36+
local package="$1"
37+
38+
if [ ! -d "$BPM_PACKAGES_PATH/$package" ]; then
39+
die "Package '$package' does not exist"
40+
fi
41+
}

0 commit comments

Comments
 (0)