Skip to content

Commit 870d5cd

Browse files
committed
fix: 'package-path' errors with output if package cannot be found. Closes #45
1 parent 4781571 commit 870d5cd

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

pkg/lib/commands/do-package-path.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ bpm-package-path() {
99
local package="$REPLY3"
1010
local ref="$REPLY4"
1111

12-
printf "%s\n" "$BPM_PACKAGES_PATH/$site/$package"
12+
local dir="$BPM_PACKAGES_PATH/$site/$package"
13+
if [ -d "$dir" ]; then
14+
printf "%s\n" "$dir"
15+
else
16+
die "Package '$site/$package' not found"
17+
fi
1318
}

tests/do-package-path.bats

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,45 @@ load 'util/init.sh'
1111

1212
run bpm-package-path "$pkg"
1313

14-
assert_success "$BPM_PACKAGES_PATH/$site/$pkg"
14+
assert_success
15+
assert_output "$BPM_PACKAGES_PATH/$site/$pkg"
16+
}
17+
18+
@test "prints the package path while specifying site" {
19+
local site='github.com'
20+
local pkg='username/package'
21+
22+
test_util.create_package "$pkg"
23+
test_util.fake_install "$pkg"
24+
25+
run bpm-package-path "$site/$pkg"
26+
27+
assert_success
28+
assert_output "$BPM_PACKAGES_PATH/$site/$pkg"
29+
}
30+
31+
@test "prints the package path while specifying URL" {
32+
local site='github.com'
33+
local pkg='username/package'
34+
35+
test_util.create_package "$pkg"
36+
test_util.fake_install "$pkg"
37+
38+
run bpm-package-path "https://$site/$pkg"
39+
40+
assert_success
41+
assert_output "$BPM_PACKAGES_PATH/$site/$pkg"
42+
}
43+
44+
@test "fails if the package cannot be found" {
45+
local site='github.com'
46+
local pkg='username/package'
47+
48+
test_util.create_package "$pkg"
49+
test_util.fake_install "$pkg"
50+
51+
run bpm-package-path "other/package"
52+
53+
assert_failure
54+
assert_output -p "Package 'github.com/other/package' not found"
1555
}

0 commit comments

Comments
 (0)