Skip to content

Commit 2beda74

Browse files
committed
chore: Rename BASE_DIR environment variable to ASDF_DEV_BASE_DIR
New users to `asdf` who wish to contribute will run into the following errors when running `./scripts/test.bash`: ``` ✗ help should show dummy plugin help specific to version when version is present [7] (from function `setup_asdf_dir' in file test/test_helpers.bash, line 16, from function `setup' in test file test/help_command.bats, line 6) `setup_asdf_dir' failed mkdir: cannot create directory ‘/w spacetest_help_should_show_dummy_plugin_help_specific_to_version_when_version_is_present’: Permission denied ``` This is due to paths within the various test suites relying on the `BASE_DIR` environment variable, which is not set by default. This pull request adds the following: * Renames `BASE_DIR` to `ASDF_DEV_BASE_DIR` to clarify intent of the variable. * Modifies `scripts/test.bash` to correctly export `ASDF_DEV_BASE_DIR` Note: I am a long-time asdf user, who would like to contribute to the project and noticed this while setting up my dev environment on an up-to-date Arch Linux system. My intention is to work on this issue: #2042 * Rename `BASE_DIR` to `ASDF_DEV_BASE_DIR` to clarify intent of variable. * Modify `test.bash` to export `ASDF_DEV_BASE_DIR`
1 parent 9f3b346 commit 2beda74

8 files changed

+51
-49
lines changed

scripts/test.bash

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env bash
22

33
set -euo pipefail
4-
IFS=$'\n\t'
54

65
print.info() {
76
printf '[INFO] %s\n' "$1"
@@ -11,18 +10,21 @@ print.error() {
1110
printf '[ERROR] %s\n' "$1" >&2
1211
}
1312

14-
{
15-
repo_dir=$(git rev-parse --show-toplevel)
16-
current_dir=$(pwd -P)
17-
if [ "$repo_dir" != "$current_dir" ]; then
18-
print.error "This scripts requires execution from the repository root directory."
19-
printf "\t%s\t%s\n" "Repo root dir:" "$repo_dir"
20-
printf "\t%s\t%s\n\n" "Current dir:" "$current_dir"
21-
exit 1
22-
fi
23-
}
13+
ASDF_DEV_BASE_DIR="$(git rev-parse --show-toplevel)"
14+
readonly ASDF_DEV_BASE_DIR
15+
export ASDF_DEV_BASE_DIR
16+
17+
current_dir="$(pwd -P)"
18+
readonly current_dir
19+
20+
if [[ $ASDF_DEV_BASE_DIR != "$current_dir" ]]; then
21+
print.error "This script requires execution from the repository root directory."
22+
printf "\t%s\t%s\n" "asdf repo root dir:" "$ASDF_DEV_BASE_DIR" >&2
23+
printf "\t%s\t%s\n\n" "current dir:" "$current_dir" >&2
24+
exit 1
25+
fi
2426

25-
test_directory="./test"
27+
readonly test_directory="$ASDF_DEV_BASE_DIR/test"
2628
bats_options=(--timing --print-output-on-failure)
2729

2830
if command -v parallel >/dev/null; then
@@ -35,5 +37,5 @@ else
3537
print.info "For faster test execution, install GNU parallel."
3638
fi
3739

38-
print.info "Running Bats in directory '${test_directory}' with options:" "${bats_options[@]}"
40+
print.info "Running Bats in directory '${test_directory}' with options: '${bats_options[*]}'"
3941
bats "${bats_options[@]}" "${test_directory}"

test/asdf_nu.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ run_nushell() {
118118
#@test "parses the output of asdf plugin list --urls" {
119119
# setup_repo
120120
# install_mock_plugin_repo "dummy"
121-
# asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
121+
# asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
122122

123123
# run_nushell "asdf plugin list --urls | to csv -n"
124124

@@ -133,7 +133,7 @@ run_nushell() {
133133
#@test "parses the output of asdf plugin list --refs" {
134134
# setup_repo
135135
# install_mock_plugin_repo "dummy"
136-
# asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
136+
# asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
137137

138138
# run_nushell "asdf plugin list --refs | to csv -n"
139139

@@ -149,7 +149,7 @@ run_nushell() {
149149
#@test "parses the output of asdf plugin list --urls --refs" {
150150
# setup_repo
151151
# install_mock_plugin_repo "dummy"
152-
# asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
152+
# asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
153153

154154
# run_nushell "asdf plugin list --urls --refs | to csv -n"
155155

test/plugin_add_command.bats

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ teardown() {
1414
@test "plugin_add command with plugin name matching all valid regex chars succeeds" {
1515
install_mock_plugin_repo "plugin_with-all-valid-chars-123"
1616

17-
run asdf plugin add "plugin_with-all-valid-chars-123" "${BASE_DIR}/repo-plugin_with-all-valid-chars-123"
17+
run asdf plugin add "plugin_with-all-valid-chars-123" "${ASDF_DEV_BASE_DIR}/repo-plugin_with-all-valid-chars-123"
1818
[ "$status" -eq 0 ]
1919

2020
run asdf plugin list
@@ -29,7 +29,7 @@ teardown() {
2929

3030
# https://stackoverflow.com/questions/52570103/regular-expression-a-za-z-seems-to-not-include-letter-w-and-wA
3131
# https://github.com/asdf-vm/asdf/issues/1237
32-
run asdf plugin add "plugin-with-w" "${BASE_DIR}/repo-plugin-with-w"
32+
run asdf plugin add "plugin-with-w" "${ASDF_DEV_BASE_DIR}/repo-plugin-with-w"
3333
[ "$status" -eq 0 ]
3434

3535
run asdf plugin list
@@ -89,7 +89,7 @@ teardown() {
8989
@test "plugin_add command with URL specified adds a plugin using repo" {
9090
install_mock_plugin_repo "dummy"
9191

92-
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
92+
run asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
9393
[ "$status" -eq 0 ]
9494

9595
run asdf plugin list
@@ -100,8 +100,8 @@ teardown() {
100100
@test "plugin_add command with URL specified twice returns success on second time" {
101101
install_mock_plugin_repo "dummy"
102102

103-
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
104-
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
103+
run asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
104+
run asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
105105
[ "$status" -eq 0 ]
106106
[ "$output" = "Plugin named dummy already added" ]
107107
}
@@ -115,8 +115,8 @@ teardown() {
115115
@test "plugin_add command executes post-plugin add script" {
116116
install_mock_plugin_repo "dummy"
117117

118-
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
119-
[ "$output" = "plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy" ]
118+
run asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
119+
[ "$output" = "plugin add path=${ASDF_DIR}/plugins/dummy source_url=${ASDF_DEV_BASE_DIR}/repo-dummy" ]
120120
}
121121

122122
@test "plugin_add command executes configured pre hook (generic)" {
@@ -126,10 +126,10 @@ teardown() {
126126
pre_asdf_plugin_add = echo ADD ${@}
127127
EOM
128128

129-
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
129+
run asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
130130

131131
local expected_output="ADD dummy
132-
plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy"
132+
plugin add path=${ASDF_DIR}/plugins/dummy source_url=${ASDF_DEV_BASE_DIR}/repo-dummy"
133133
[ "$output" = "${expected_output}" ]
134134
}
135135

@@ -140,10 +140,10 @@ plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy"
140140
pre_asdf_plugin_add_dummy = echo ADD
141141
EOM
142142

143-
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
143+
run asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
144144

145145
local expected_output="ADD
146-
plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy"
146+
plugin add path=${ASDF_DIR}/plugins/dummy source_url=${ASDF_DEV_BASE_DIR}/repo-dummy"
147147
[ "$output" = "${expected_output}" ]
148148
}
149149

@@ -154,9 +154,9 @@ plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy"
154154
post_asdf_plugin_add = echo ADD ${@}
155155
EOM
156156

157-
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
157+
run asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
158158

159-
local expected_output="plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy
159+
local expected_output="plugin add path=${ASDF_DIR}/plugins/dummy source_url=${ASDF_DEV_BASE_DIR}/repo-dummy
160160
ADD dummy"
161161
[ "$output" = "${expected_output}" ]
162162
}
@@ -168,9 +168,9 @@ ADD dummy"
168168
post_asdf_plugin_add_dummy = echo ADD
169169
EOM
170170

171-
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
171+
run asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
172172

173-
local expected_output="plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy
173+
local expected_output="plugin add path=${ASDF_DIR}/plugins/dummy source_url=${ASDF_DEV_BASE_DIR}/repo-dummy
174174
ADD"
175175
[ "$output" = "${expected_output}" ]
176176
}

test/plugin_test_command.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ teardown() {
2424
}
2525

2626
@test "plugin_test_command works with no options provided" {
27-
run asdf plugin test dummy "${BASE_DIR}/repo-dummy"
27+
run asdf plugin test dummy "${ASDF_DEV_BASE_DIR}/repo-dummy"
2828
[ "$status" -eq 0 ]
2929
}
3030

3131
@test "plugin_test_command works with all options provided" {
32-
run asdf plugin test dummy "${BASE_DIR}/repo-dummy" --asdf-tool-version 1.0.0 --asdf-plugin-gitref master
32+
run asdf plugin test dummy "${ASDF_DEV_BASE_DIR}/repo-dummy" --asdf-tool-version 1.0.0 --asdf-plugin-gitref master
3333
[ "$status" -eq 0 ]
3434
}

test/plugin_update_command.bats

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ load test_helpers
55
setup() {
66
setup_asdf_dir
77
install_mock_plugin_repo "dummy"
8-
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
8+
run asdf plugin add "dummy" "${ASDF_DEV_BASE_DIR}/repo-dummy"
99
}
1010

1111
teardown() {
@@ -22,7 +22,7 @@ teardown() {
2222

2323
#@test "asdf plugin update should pull latest default branch (refs/remotes/origin/HEAD) for plugin even if default branch changes" {
2424
# install_mock_plugin_repo "dummy-remote"
25-
# remote_dir="$BASE_DIR/repo-dummy-remote"
25+
# remote_dir="$ASDF_DEV_BASE_DIR/repo-dummy-remote"
2626
# # set HEAD to refs/head/main in dummy-remote
2727
# git -C "${remote_dir}" checkout -b main
2828
# # track & fetch remote repo (dummy-remote) in plugin (dummy)
@@ -40,7 +40,7 @@ teardown() {
4040

4141
#@test "asdf plugin update should pull latest default branch (refs/remotes/origin/HEAD) for plugin even if the default branch contains a forward slash" {
4242
# install_mock_plugin_repo "dummy-remote"
43-
# remote_dir="$BASE_DIR/repo-dummy-remote"
43+
# remote_dir="$ASDF_DEV_BASE_DIR/repo-dummy-remote"
4444
# # set HEAD to refs/head/my/default in dummy-remote
4545
# git -C "${remote_dir}" checkout -b my/default
4646
# # track & fetch remote repo (dummy-remote) in plugin (dummy)
@@ -58,12 +58,12 @@ teardown() {
5858

5959
#@test "asdf plugin update should pull latest default branch (refs/remotes/origin/HEAD) for plugin even if already set to specific ref" {
6060
# # set plugin to specific sha
61-
# current_sha="$(git --git-dir "${BASE_DIR}/repo-dummy/.git" --work-tree "$BASE_DIR/repo-dummy" rev-parse HEAD)"
61+
# current_sha="$(git --git-dir "${ASDF_DEV_BASE_DIR}/repo-dummy/.git" --work-tree "$ASDF_DEV_BASE_DIR/repo-dummy" rev-parse HEAD)"
6262
# run asdf plugin update dummy "${current_sha}"
6363

6464
# # setup mock plugin remote
6565
# install_mock_plugin_repo "dummy-remote"
66-
# remote_dir="$BASE_DIR/repo-dummy-remote"
66+
# remote_dir="$ASDF_DEV_BASE_DIR/repo-dummy-remote"
6767
# # set HEAD to refs/head/main in dummy-remote
6868
# git -C "${remote_dir}" checkout -b main
6969
# # track & fetch remote repo (dummy-remote) in plugin (dummy)
@@ -141,7 +141,7 @@ teardown() {
141141

142142
# # setup mock plugin remote
143143
# install_mock_plugin_repo "dummy-remote"
144-
# remote_dir="$BASE_DIR/repo-dummy-remote"
144+
# remote_dir="$ASDF_DEV_BASE_DIR/repo-dummy-remote"
145145
# # set HEAD to refs/head/main in dummy-remote
146146
# git -C "${remote_dir}" checkout -b main
147147
# # track & fetch remote repo (dummy-remote) in plugin (dummy)

test/test_helpers.bash

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ bats_require_minimum_version 1.7.0
77

88
setup_asdf_dir() {
99
if [ "$BATS_TEST_NAME" = 'test_shim_exec_should_use_path_executable_when_specified_version_path-3a-3cpath-3e' ]; then
10-
BASE_DIR="$BASE_DIR/asdf_with_no_spaces"
10+
ASDF_DEV_BASE_DIR="$ASDF_DEV_BASE_DIR/asdf_with_no_spaces"
1111
else
12-
BASE_DIR="$BASE_DIR/w space${BATS_TEST_NAME}"
12+
ASDF_DEV_BASE_DIR="$ASDF_DEV_BASE_DIR/w space${BATS_TEST_NAME}"
1313
fi
1414

1515
# We don't call mktemp anymore so we need to create this sub directory manually
16-
mkdir "$BASE_DIR"
16+
mkdir "$ASDF_DEV_BASE_DIR"
1717

1818
# HOME is now defined by the Golang test code in main_test.go
19-
HOME="$BASE_DIR"
19+
HOME="$ASDF_DEV_BASE_DIR"
2020
export HOME
2121
ASDF_DIR="$HOME/.asdf"
2222
mkdir -p "$ASDF_DIR/plugins"
@@ -26,7 +26,7 @@ setup_asdf_dir() {
2626
# ASDF_BIN is now defined by the Golang test code in main_test.go
2727
#ASDF_BIN="$(dirname "$BATS_TEST_DIRNAME")/bin"
2828

29-
ASDF_DATA_DIR="$BASE_DIR/.asdf"
29+
ASDF_DATA_DIR="$ASDF_DEV_BASE_DIR/.asdf"
3030
export ASDF_DATA_DIR
3131

3232
# shellcheck disable=SC2031,SC2153
@@ -63,7 +63,7 @@ install_mock_broken_plugin() {
6363

6464
install_mock_plugin_repo() {
6565
local plugin_name=$1
66-
local location="${BASE_DIR}/repo-${plugin_name}"
66+
local location="${ASDF_DEV_BASE_DIR}/repo-${plugin_name}"
6767
cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_plugin" "${location}"
6868
init_git_repo "${location}"
6969
}
@@ -122,7 +122,7 @@ install_dummy_exec_path_script() {
122122
}
123123

124124
clean_asdf_dir() {
125-
rm -rf "$BASE_DIR"
125+
rm -rf "$ASDF_DEV_BASE_DIR"
126126
unset ASDF_DIR
127127
unset ASDF_DATA_DIR
128128
}

test/update_command.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#load test_helpers
44

55
#setup() {
6-
# BASE_DIR=$(mktemp -dt asdf.XXXX)
7-
# HOME="$BASE_DIR/home"
6+
# ASDF_DEV_BASE_DIR=$(mktemp -dt asdf.XXXX)
7+
# HOME="$ASDF_DEV_BASE_DIR/home"
88
# ASDF_DIR="$HOME/.asdf"
99
# git clone -o local "$(dirname "$BATS_TEST_DIRNAME")" "$ASDF_DIR"
1010
# git --git-dir "$ASDF_DIR/.git" remote add origin https://github.com/asdf-vm/asdf.git

test/utils.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ teardown() {
247247

248248
@test "get_preset_version_for returns the global version from home when project is outside of home" {
249249
echo "dummy 0.1.0" >"$HOME/.tool-versions"
250-
PROJECT_DIR=$BASE_DIR/project
250+
PROJECT_DIR=$ASDF_DEV_BASE_DIR/project
251251
mkdir -p "$PROJECT_DIR"
252252
run get_preset_version_for "dummy"
253253
[ "$status" -eq 0 ]

0 commit comments

Comments
 (0)