Skip to content

Commit 5da1932

Browse files
committed
feat: Print warning/error when package.sh values are unusable
1 parent b3c26ed commit 5da1932

File tree

5 files changed

+125
-3
lines changed

5 files changed

+125
-3
lines changed

pkg/lib/util/abstract-bins.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ abstract.bins() {
4141
IFS=':' read -ra bins <<< "$REPLY"
4242

4343
for file in "${bins[@]}"; do
44-
abstract.bins_do_action "$action" "$BPM_PACKAGES_PATH/$id/$file" "$remove_extensions"
44+
local full_path="$BPM_PACKAGES_PATH/$id/$file"
45+
if [ -d "$full_path" ]; then
46+
die "Specified directory '$file' in package.sh; only files are valid"
47+
elif [ ! -f "$full_path" ]; then
48+
log.warn "Executable file '$file' not found in repository. Skipping"
49+
else
50+
abstract.bins_do_action "$action" "$full_path" "$remove_extensions"
51+
fi
4552
done
4653
else
4754
abstract.bins_search_heuristics "$action" "$id" "$remove_extensions"

pkg/lib/util/abstract-completions.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ abstract.completions() {
3838
IFS=':' read -ra bash_completion_files <<< "$REPLY"
3939

4040
for file in "${bash_completion_files[@]}"; do
41-
abstract.completions_do_action_bash "$action" "$BPM_PACKAGES_PATH/$id/$file"
41+
local full_path="$BPM_PACKAGES_PATH/$id/$file"
42+
if [ -d "$full_path" ]; then
43+
die "Specified directory '$file' in package.sh; only files are valid"
44+
elif [ ! -f "$full_path" ]; then
45+
log.warn "Completion file '$file' not found in repository. Skipping"
46+
else
47+
abstract.completions_do_action_bash "$action" "$full_path"
48+
fi
4249
done
4350
else
4451
abstract.completions_search_heuristics "$action" "$id" 'bash'
@@ -48,7 +55,14 @@ abstract.completions() {
4855
IFS=':' read -ra zsh_completion_files <<< "$REPLY"
4956

5057
for file in "${zsh_completion_files[@]}"; do
51-
abstract.completions_do_action_zsh "$action" "$BPM_PACKAGES_PATH/$id/$file"
58+
local full_path="$BPM_PACKAGES_PATH/$id/$file"
59+
if [ -d "$full_path" ]; then
60+
die "Specified directory '$file' in package.sh; only files are valid"
61+
elif [ ! -f "$full_path" ]; then
62+
log.warn "Completion file '$file' not found in repository. Skipping"
63+
else
64+
abstract.completions_do_action_zsh "$action" "$full_path"
65+
fi
5266
done
5367
else
5468
abstract.completions_search_heuristics "$action" "$id" 'zsh'

tests/do-add.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,6 @@ load 'util/init.sh'
204204
assert_success
205205
assert_line "do-plumbing-clone https://github.com/username/package.git github.com/username/package"
206206
}
207+
208+
209+

tests/do-plumbing-link-bins.bats

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,35 @@ load 'util/init.sh'
300300
assert [ ! -e "$BPM_PREFIX/bin/package" ]
301301
assert [ ! -e "$BPM_PREFIX/bin/package2" ]
302302
}
303+
304+
@test "fails link bins when specifying directory in package.sh" {
305+
local site='github.com'
306+
local pkg="username/package"
307+
308+
test_util.setup_pkg "$pkg"; {
309+
echo 'BINS="dir"' > 'package.sh'
310+
311+
mkdir 'dir'
312+
touch 'dir/.gitkeep'
313+
}; test_util.finish_pkg
314+
test_util.fake_clone "$site/$pkg"
315+
316+
run do-plumbing-link-bins "$site/$pkg"
317+
318+
assert_failure
319+
assert_line -p "Specified directory 'dir' in package.sh; only files are valid"
320+
}
321+
322+
@test "warns link bins when specifying non-existent file in package.sh" {
323+
local site='github.com'
324+
local pkg="username/package"
325+
326+
test_util.setup_pkg "$pkg"; {
327+
echo 'BINS="some_file"' > 'package.sh'
328+
}; test_util.finish_pkg
329+
test_util.fake_clone "$site/$pkg"
330+
331+
run do-plumbing-link-bins "$site/$pkg"
332+
333+
assert_line -p "Executable file 'some_file' not found in repository. Skipping"
334+
}

tests/do-plumbing-link-completions.bats

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,69 @@ load 'util/init.sh'
512512
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/bash/prog2.bash")" = "$BPM_PACKAGES_PATH/$site/$pkg/completions/prog2.bash" ]
513513
assert [ "$(readlink "$BPM_INSTALL_COMPLETIONS/zsh/compctl/prog.zsh")" = "$BPM_PACKAGES_PATH/$site/$pkg/completions/prog.zsh" ]
514514
}
515+
516+
@test "fails bash link completions when specifying directory in package.sh" {
517+
local site='github.com'
518+
local pkg="username/package"
519+
520+
test_util.setup_pkg "$pkg"; {
521+
echo 'BASH_COMPLETIONS="dir"' > 'package.sh'
522+
523+
mkdir 'dir'
524+
touch 'dir/.gitkeep'
525+
}; test_util.finish_pkg
526+
test_util.fake_clone "$site/$pkg"
527+
528+
run do-plumbing-link-completions "$site/$pkg"
529+
530+
assert_failure
531+
assert_line -p "Specified directory 'dir' in package.sh; only files are valid"
532+
}
533+
534+
@test "fails zsh link completions when specifying directory in package.sh" {
535+
local site='github.com'
536+
local pkg="username/package"
537+
538+
test_util.setup_pkg "$pkg"; {
539+
echo 'ZSH_COMPLETIONS="dir"' > 'package.sh'
540+
541+
mkdir 'dir'
542+
touch 'dir/.gitkeep'
543+
}; test_util.finish_pkg
544+
test_util.fake_clone "$site/$pkg"
545+
546+
run do-plumbing-link-completions "$site/$pkg"
547+
548+
assert_failure
549+
assert_line -p "Specified directory 'dir' in package.sh; only files are valid"
550+
}
551+
552+
553+
@test "warns bash link completions when specifying non-existent file in package.sh" {
554+
local site='github.com'
555+
local pkg="username/package"
556+
557+
test_util.setup_pkg "$pkg"; {
558+
echo 'BASH_COMPLETIONS="some_file"' > 'package.sh'
559+
}; test_util.finish_pkg
560+
test_util.fake_clone "$site/$pkg"
561+
562+
run do-plumbing-link-completions "$site/$pkg"
563+
564+
assert_line -p "Completion file 'some_file' not found in repository. Skipping"
565+
}
566+
567+
568+
@test "warns zsh link completions when specifying non-existent file in package.sh" {
569+
local site='github.com'
570+
local pkg="username/package"
571+
572+
test_util.setup_pkg "$pkg"; {
573+
echo 'ZSH_COMPLETIONS="some_file"' > 'package.sh'
574+
}; test_util.finish_pkg
575+
test_util.fake_clone "$site/$pkg"
576+
577+
run do-plumbing-link-completions "$site/$pkg"
578+
579+
assert_line -p "Completion file 'some_file' not found in repository. Skipping"
580+
}

0 commit comments

Comments
 (0)