Skip to content

Commit 44cc368

Browse files
committed
fix: Improve naming of variables
Renaming should make it easier to test and use variables
1 parent 73bfa7c commit 44cc368

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

pkg/lib/commands/do-init.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
echo_bpm_variables_posix() {
44
cat <<-EOF
55
# bpm variables
6-
export BPM_ROOT="$BPM_ROOT"
7-
export BPM_REPO_ROOT="$BPM_ROOT/source"
6+
export BPM_REPO_ROOT="$BPM_REPO_ROOT"
87
export BPM_CELLAR="$BPM_CELLAR"
98
109
EOF
@@ -52,8 +51,7 @@ do-init() {
5251
fish)
5352
cat <<-EOF
5453
# bpm variables
55-
set -gx BPM_ROOT $BPM_ROOT
56-
set -gx BPM_REPO_ROOT $BPM_ROOT/source
54+
set -gx BPM_REPO_ROOT $BPM_REPO_ROOT
5755
set -gx BPM_CELLAR $BPM_CELLAR
5856
5957
# bpm completion

tests/bpm-load.bats

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ load 'util/init.sh'
1111
}; test_util.finish_pkg
1212
test_util.mock_add "$pkg"
1313

14-
BPM_ROOT="$BPM_TEST_DIR"
15-
1614
source bpm-load
1715
run bpm-load --global "$pkg"
1816

tests/do-init.bats

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

55
@test "exports BPM_ROOT" {
6-
unset BPM_ROOT
7-
eval "$(BPM_ROOT=/lol do-init bash)"
6+
BPM_REPO_ROOT="$BPM_TEST_REPO_ROOT/../source"
7+
BPM_CELLAR="$BPM_TEST_REPO_ROOT/../cellar"
8+
9+
eval "$(BPM_REPO_ROOT=/lol do-init bash)"
810

911
assert_success
10-
assert [ "$BPM_ROOT" = '/lol' ]
11-
assert test_util.is_exported 'BPM_ROOT'
12+
assert [ "$BPM_REPO_ROOT" = '/lol' ]
13+
assert test_util.is_exported 'BPM_REPO_ROOT'
1214
}
1315

1416
@test "exports BPM_CELLAR" {
15-
unset BPM_ROOT
17+
unset BPM_CELLAR
1618
eval "$(BPM_CELLAR=/lol do-init bash)"
1719

1820
assert_success
@@ -28,6 +30,9 @@ load './util/init.sh'
2830
}
2931

3032
@test "bash completion works" {
33+
BPM_REPO_ROOT="$BPM_TEST_REPO_ROOT/../source"
34+
BPM_CELLAR="$BPM_TEST_REPO_ROOT/../cellar"
35+
3136
! command -v _bpm
3237

3338
eval "$(do-init bash)"

tests/include.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
load 'util/init.sh'
44

55
@test "with no arguments, prints an error" {
6+
BPM_REPO_ROOT="$BPM_TEST_REPO_ROOT/.."
7+
BPM_CELLAR="$BPM_TEST_REPO_ROOT/../cellar"
8+
69
eval "$(do-init sh)"
710

811
run include

tests/util/init.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ export BPM_IS_TEST=
2020

2121
# Stub common variables
2222
test_util.get_repo_root
23-
export REPO_ROOT="$REPLY"
24-
export BPM_ROOT="${REPO_ROOT%/*}"
25-
export PROGRAM_LIB_DIR="$REPO_ROOT/pkg/lib"
23+
# The root of the real source. This is a separate variable because we want to
24+
# set 'BPM_ROOT' to some other value
25+
export BPM_TEST_REPO_ROOT="$REPLY"
26+
export PROGRAM_LIB_DIR="$BPM_TEST_REPO_ROOT/pkg/lib"
27+
28+
export BPM_ROOT="$BPM_TEST_DIR"
2629
export BPM_CELLAR="$BPM_TEST_DIR/cellar"
2730
export BPM_PACKAGES_PATH="$BPM_CELLAR/packages"
2831
export BPM_INSTALL_BIN="$BPM_CELLAR/bin"
2932
export BPM_INSTALL_MAN="$BPM_CELLAR/man"
3033
export BPM_INSTALL_COMPLETIONS="$BPM_CELLAR/completions"
3134
export BPM_MODE='global' # for non-tests, the default is 'local'
3235

33-
export PATH="$REPO_ROOT/pkg/bin:$PATH"
34-
for f in "$REPO_ROOT"/pkg/lib/{commands,util}/?*.sh; do
36+
export PATH="$BPM_TEST_REPO_ROOT/pkg/bin:$PATH"
37+
for f in "$BPM_TEST_REPO_ROOT"/pkg/lib/{commands,util}/?*.sh; do
3538
source "$f"
3639
done
3740

0 commit comments

Comments
 (0)