Skip to content

Commit 9d368a9

Browse files
committed
feat: Print warning when not specifying folders with bpm.toml
1 parent 5da1932 commit 9d368a9

File tree

6 files changed

+118
-10
lines changed

6 files changed

+118
-10
lines changed

pkg/lib/util/abstract-bins.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ abstract.bins() {
2323

2424
if util.get_toml_array "$bpm_toml_file" 'binDirs'; then
2525
for dir in "${REPLIES[@]}"; do
26-
for file in "$BPM_PACKAGES_PATH/$id/$dir"/*; do
27-
abstract.bins_do_action "$action" "$file" "$remove_extensions"
28-
done
26+
local full_path="$BPM_PACKAGES_PATH/$id/$dir"
27+
if [ -f "$full_path" ]; then
28+
die "Specified file '$dir' in bpm.toml; only directories are valid"
29+
elif [ ! -d "$full_path" ]; then
30+
log.warn "Directory '$dir' with executable files not found. Skipping"
31+
else
32+
for file in "$full_path"/*; do
33+
abstract.bins_do_action "$action" "$file" "$remove_extensions"
34+
done
35+
fi
2936
done
3037

3138
return
@@ -45,7 +52,7 @@ abstract.bins() {
4552
if [ -d "$full_path" ]; then
4653
die "Specified directory '$file' in package.sh; only files are valid"
4754
elif [ ! -f "$full_path" ]; then
48-
log.warn "Executable file '$file' not found in repository. Skipping"
55+
log.warn "Executable file '$file' not found. Skipping"
4956
else
5057
abstract.bins_do_action "$action" "$full_path" "$remove_extensions"
5158
fi

pkg/lib/util/abstract-completions.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ abstract.completions() {
1616
if [ -f "$bpm_toml_file" ]; then
1717
if util.get_toml_array "$bpm_toml_file" 'completionDirs'; then
1818
for dir in "${REPLIES[@]}"; do
19-
for file in "$BPM_PACKAGES_PATH/$id/$dir"/*; do
19+
local full_dir="$BPM_PACKAGES_PATH/$id/$dir"
20+
if [ -f "$full_dir" ]; then
21+
die "Specified file '$dir' in bpm.toml; only directories are valid"
22+
elif [ ! -d "$full_dir" ]; then
23+
log.warn "Directory '$dir' with executable files not found. Skipping"
24+
continue
25+
fi
26+
27+
for file in "$full_dir"/*; do
2028
local fileName="${file##*/}"
2129

2230
if [[ $fileName == *.@(sh|bash) ]]; then
@@ -42,7 +50,7 @@ abstract.completions() {
4250
if [ -d "$full_path" ]; then
4351
die "Specified directory '$file' in package.sh; only files are valid"
4452
elif [ ! -f "$full_path" ]; then
45-
log.warn "Completion file '$file' not found in repository. Skipping"
53+
log.warn "Completion file '$file' not found. Skipping"
4654
else
4755
abstract.completions_do_action_bash "$action" "$full_path"
4856
fi
@@ -59,7 +67,7 @@ abstract.completions() {
5967
if [ -d "$full_path" ]; then
6068
die "Specified directory '$file' in package.sh; only files are valid"
6169
elif [ ! -f "$full_path" ]; then
62-
log.warn "Completion file '$file' not found in repository. Skipping"
70+
log.warn "Completion file '$file' not found. Skipping"
6371
else
6472
abstract.completions_do_action_zsh "$action" "$full_path"
6573
fi

pkg/lib/util/abstract-mans.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ abstract.mans() {
1616
for dir in "${REPLIES[@]}"; do
1717
local full_dir="$BPM_PACKAGES_PATH/$id/$dir"
1818

19+
if [ -f "$full_dir" ]; then
20+
die "Specified file '$dir' in bpm.toml; only directories are valid"
21+
elif [ ! -d "$full_dir" ]; then
22+
log.warn "Directory '$dir' with executable files not found. Skipping"
23+
continue
24+
fi
25+
1926
# 'file' can be
2027
# 1. A man file
2128
# 2. A directory (man1, man2), that contains man files

tests/do-plumbing-link-bins.bats

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,5 +330,35 @@ load 'util/init.sh'
330330

331331
run do-plumbing-link-bins "$site/$pkg"
332332

333-
assert_line -p "Executable file 'some_file' not found in repository. Skipping"
333+
assert_line -p "Executable file 'some_file' not found. Skipping"
334+
}
335+
336+
@test "fails link bins when specifying file in bpm.toml" {
337+
local site='github.com'
338+
local pkg="username/package"
339+
340+
test_util.setup_pkg "$pkg"; {
341+
echo 'binDirs = ["file"]' > 'bpm.toml'
342+
touch 'file'
343+
}; test_util.finish_pkg
344+
test_util.fake_clone "$site/$pkg"
345+
346+
run do-plumbing-link-bins "$site/$pkg"
347+
348+
assert_failure
349+
assert_line -p "Specified file 'file' in bpm.toml; only directories are valid"
350+
}
351+
352+
@test "warns link bins when specifying non-existent directory in bpm.toml" {
353+
local site='github.com'
354+
local pkg="username/package"
355+
356+
test_util.setup_pkg "$pkg"; {
357+
echo 'binDirs = ["dir"]' > 'bpm.toml'
358+
}; test_util.finish_pkg
359+
test_util.fake_clone "$site/$pkg"
360+
361+
run do-plumbing-link-bins "$site/$pkg"
362+
363+
assert_line -p "Directory 'dir' with executable files not found. Skipping"
334364
}

tests/do-plumbing-link-completions.bats

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ load 'util/init.sh'
561561

562562
run do-plumbing-link-completions "$site/$pkg"
563563

564-
assert_line -p "Completion file 'some_file' not found in repository. Skipping"
564+
assert_line -p "Completion file 'some_file' not found. Skipping"
565565
}
566566

567567

@@ -576,5 +576,33 @@ load 'util/init.sh'
576576

577577
run do-plumbing-link-completions "$site/$pkg"
578578

579-
assert_line -p "Completion file 'some_file' not found in repository. Skipping"
579+
assert_line -p "Completion file 'some_file' not found. Skipping"
580+
}
581+
582+
@test "fails link completions when specifying file in bpm.toml" {
583+
local site='github.com'
584+
local pkg="username/package"
585+
586+
test_util.setup_pkg "$pkg"; {
587+
echo 'completionDirs = ["dir"]' > 'bpm.toml'
588+
}; test_util.finish_pkg
589+
test_util.fake_clone "$site/$pkg"
590+
591+
run do-plumbing-link-completions "$site/$pkg"
592+
593+
assert_line -p "Directory 'dir' with executable files not found. Skipping"
594+
}
595+
596+
@test "warns link completions when specifying non-existent directory in bpm.toml" {
597+
local site='github.com'
598+
local pkg="username/package"
599+
600+
test_util.setup_pkg "$pkg"; {
601+
echo 'completionDirs = ["dir"]' > 'bpm.toml'
602+
}; test_util.finish_pkg
603+
test_util.fake_clone "$site/$pkg"
604+
605+
run do-plumbing-link-completions "$site/$pkg"
606+
607+
assert_line -p "Directory 'dir' with executable files not found. Skipping"
580608
}

tests/do-plumbing-link-man.bats

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,31 @@ load 'util/init.sh'
147147
assert [ ! -e "$BPM_INSTALL_MAN/man1/exec.1" ]
148148
assert [ ! -e "$BPM_INSTALL_MAN/man5/2man/exec.2" ]
149149
}
150+
151+
@test "fails link man when specifying file in bpm.toml" {
152+
local site='github.com'
153+
local pkg="username/package"
154+
155+
test_util.setup_pkg "$pkg"; {
156+
echo 'manDirs = ["dir"]' > 'bpm.toml'
157+
}; test_util.finish_pkg
158+
test_util.fake_clone "$site/$pkg"
159+
160+
run do-plumbing-link-man "$site/$pkg"
161+
162+
assert_line -p "Directory 'dir' with executable files not found. Skipping"
163+
}
164+
165+
@test "warns link man when specifying non-existent directory in bpm.toml" {
166+
local site='github.com'
167+
local pkg="username/package"
168+
169+
test_util.setup_pkg "$pkg"; {
170+
echo 'manDirs = ["dir"]' > 'bpm.toml'
171+
}; test_util.finish_pkg
172+
test_util.fake_clone "$site/$pkg"
173+
174+
run do-plumbing-link-man "$site/$pkg"
175+
176+
assert_line -p "Directory 'dir' with executable files not found. Skipping"
177+
}

0 commit comments

Comments
 (0)