Skip to content

Commit 7bf010b

Browse files
committed
test: Fix getting root bpm directory for test
1 parent 0fc34e0 commit 7bf010b

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

tests/do-upgrade.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ load 'util/init.sh'
126126
run do-upgrade 'bpm'
127127

128128
assert_success
129-
assert_line -e 'git -C /(.*)/tests/../pkg/lib/../.. pull'
129+
assert_line -e 'git -C /(.*)/bpm/source/pkg/lib/../.. pull'
130130
}
131131

132132
@test "upgrade bpm fails when mixing package names" {

tests/util/init.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,29 @@ load 'vendor/bats-core/load'
77
load 'vendor/bats-assert/load'
88
load 'util/test_util.sh'
99

10-
export BPM_TEST_DIR="$BATS_TMPDIR/bpm"
11-
export BPM_CWD="$BPM_TEST_DIR/cwd"
12-
export BPM_ORIGIN_DIR="$BPM_TEST_DIR/origin"
13-
export BPM_MODE_TEST=
14-
1510
export LANG="C"
1611
export LANGUAGE="C"
1712
export LC_ALL="C"
1813
export XDG_DATA_HOME=
19-
export PATH="$BPM_ROOT/pkg/bin:$PATH" # TODO
2014

21-
export PROGRAM_LIB_DIR="$BATS_TEST_DIRNAME/../pkg/lib"
22-
export BPM_ROOT="$BATS_TEST_DIRNAME/.."
15+
# Test-specific
16+
export BPM_TEST_DIR="$BATS_TMPDIR/bpm"
17+
export BPM_CWD="$BPM_TEST_DIR/cwd"
18+
export BPM_ORIGIN_DIR="$BPM_TEST_DIR/origin"
19+
export BPM_MODE_TEST=
20+
21+
# Stub common variables
22+
test_util.get_bpm_root
23+
export BPM_ROOT="$REPLY"
2324
export BPM_PREFIX="$BPM_TEST_DIR/cellar"
2425
export BPM_PACKAGES_PATH="$BPM_PREFIX/packages"
2526
export BPM_INSTALL_BIN="$BPM_PREFIX/bin"
2627
export BPM_INSTALL_MAN="$BPM_PREFIX/man"
2728
export BPM_INSTALL_COMPLETIONS="$BPM_PREFIX/completions"
29+
export PROGRAM_LIB_DIR="$BPM_ROOT/source/pkg/lib"
2830

29-
for f in "$BPM_ROOT"/pkg/lib/{commands,util}/?*.sh; do
31+
export PATH="$BPM_ROOT/source/pkg/bin:$PATH"
32+
for f in "$BPM_ROOT"/source/pkg/lib/{commands,util}/?*.sh; do
3033
source "$f"
3134
done
3235

tests/util/test_util.sh

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

4+
test_util.get_bpm_root() {
5+
REPLY=
6+
if ! REPLY="$(
7+
while [[ ! -d ".git" && "$PWD" != / ]]; do
8+
if ! cd ..; then
9+
printf "%s\n" "Error: Could not cd to BPM directory"
10+
exit 1
11+
fi
12+
done
13+
14+
if [[ $PWD == / ]]; then
15+
printf "%s\n" "Error: Could not find root BPM directory"
16+
exit 1
17+
fi
18+
19+
# BPM root is the parent directory of 'source', which holds
20+
# the Git repository
21+
if ! cd ..; then
22+
printf "%s\n" "Error: Could not cd to BPM directory"
23+
exit 1
24+
fi
25+
printf "%s" "$PWD"
26+
)"; then
27+
exit 1
28+
fi
29+
}
30+
431
# @description This stubs a command by creating a function for it, which
532
# prints the command name and its arguments
633
test_util.stub_command() {
@@ -16,7 +43,7 @@ test_util.mock_clone() {
1643
ensure.non_zero 'destDir' "$destDir"
1744

1845
# Be explicit with the 'file' protocol. The upstream "repository"
19-
# is just another (non-bare) Git repository. By default, packages are usually
46+
# is just another (non-bare) Git repository
2047
git clone "file://$BPM_ORIGIN_DIR/$srcDir" "$BPM_PACKAGES_PATH/$destDir"
2148
}
2249

0 commit comments

Comments
 (0)