Skip to content

Commit e8e35fb

Browse files
committed
fix: Better test variable from 'init' subcommand
1 parent d1655b3 commit e8e35fb

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

pkg/lib/commands/do-init.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ echo_bpm_variables_posix() {
66
export BPM_ROOT="$BPM_ROOT"
77
export BPM_REPO_ROOT="$BPM_ROOT/source"
88
export BPM_PREFIX="$BPM_PREFIX"
9-
export BPM_PACKAGES_PATH="$BPM_PACKAGES_PATH"
109
1110
EOF
1211
}
@@ -56,7 +55,6 @@ do-init() {
5655
set -gx BPM_ROOT $BPM_ROOT
5756
set -gx BPM_REPO_ROOT $BPM_ROOT/source
5857
set -gx BPM_PREFIX $BPM_PREFIX
59-
set -gx BPM_PACKAGES_PATH $BPM_PACKAGES_PATH
6058
6159
# bpm completion
6260
source \$BPM_REPO_ROOT/completions/bpm.fish

tests/do-init.bats

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@
33
load './util/init.sh'
44

55
@test "exports BPM_ROOT" {
6-
BPM_ROOT=/lol run do-init bash
6+
unset BPM_ROOT
7+
eval "$(BPM_ROOT=/lol do-init bash)"
78

89
assert_success
9-
assert_line -p 'export BPM_ROOT="/lol"'
10+
assert [ "$BPM_ROOT" = '/lol' ]
11+
assert test_util.is_exported 'BPM_ROOT'
1012
}
1113

14+
1215
@test "exports BPM_PREFIX" {
1316
BPM_PREFIX=/lol run do-init bash
1417

1518
assert_success
1619
assert_line -p 'export BPM_PREFIX="/lol"'
1720
}
1821

19-
@test "exports BPM_PACKAGES_PATH" {
20-
BPM_PACKAGES_PATH=/lol run do-init bash
21-
22-
assert_success
23-
assert_line -p 'export BPM_PACKAGES_PATH="/lol"'
24-
}
2522

2623
@test "errors if shell is not available" {
2724
run do-init fakesh

tests/util/test_util.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# shellcheck shell=bash
22
# shellcheck disable=SC2164
33

4+
test_util.is_exported() {
5+
local variable_name="$1"
6+
7+
local -n variable="$variable_name"
8+
if [[ "${variable@a}" == *x* ]]; then
9+
return 0
10+
else
11+
return 1
12+
fi
13+
}
14+
415
test_util.get_repo_root() {
516
REPLY=
617
if ! REPLY="$(

0 commit comments

Comments
 (0)