2019-01-19 19:59:27 -07:00
|
|
|
#!/usr/bin/env bats
|
2023-01-25 06:37:21 -07:00
|
|
|
# shellcheck disable=SC2164
|
2019-01-19 19:59:27 -07:00
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_asdf_dir
|
|
|
|
install_dummy_plugin
|
|
|
|
|
2023-01-22 16:36:47 -07:00
|
|
|
PROJECT_DIR="$HOME/project"
|
|
|
|
mkdir -p "$PROJECT_DIR"
|
|
|
|
cd "$PROJECT_DIR"
|
2019-01-19 19:59:27 -07:00
|
|
|
|
|
|
|
# asdf lib needed to run generated shims
|
2023-01-22 21:29:18 -07:00
|
|
|
cp -rf "$BATS_TEST_DIRNAME"/../{bin,lib} "$ASDF_DIR/"
|
2019-01-19 19:59:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
|
|
|
}
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
@test "asdf env without argument should display help" {
|
|
|
|
run asdf env
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "$output" | grep "usage: asdf env <command>"
|
|
|
|
}
|
|
|
|
|
2019-01-19 19:59:27 -07:00
|
|
|
@test "asdf env should execute under the environment used for a shim" {
|
2023-01-22 21:29:18 -07:00
|
|
|
echo "dummy 1.0" >"$PROJECT_DIR/.tool-versions"
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2019-01-19 19:59:27 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf env dummy which dummy
|
2019-01-19 19:59:27 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2023-01-14 06:18:44 -07:00
|
|
|
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/dummy" ]
|
2019-01-19 19:59:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "asdf env should execute under plugin custom environment used for a shim" {
|
2023-01-22 21:29:18 -07:00
|
|
|
echo "dummy 1.0" >"$PROJECT_DIR/.tool-versions"
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2019-01-19 19:59:27 -07:00
|
|
|
|
2023-01-22 16:36:47 -07:00
|
|
|
echo "export FOO=bar" >"$ASDF_DIR/plugins/dummy/bin/exec-env"
|
|
|
|
chmod +x "$ASDF_DIR/plugins/dummy/bin/exec-env"
|
2019-01-19 19:59:27 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf env dummy
|
2019-01-19 19:59:27 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2023-01-22 16:36:47 -07:00
|
|
|
echo "$output" | grep 'FOO=bar'
|
2019-01-19 19:59:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "asdf env should ignore plugin custom environment on system version" {
|
2023-01-22 21:29:18 -07:00
|
|
|
echo "dummy 1.0" >"$PROJECT_DIR/.tool-versions"
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2019-01-19 19:59:27 -07:00
|
|
|
|
2023-01-22 16:36:47 -07:00
|
|
|
echo "export FOO=bar" >"$ASDF_DIR/plugins/dummy/bin/exec-env"
|
|
|
|
chmod +x "$ASDF_DIR/plugins/dummy/bin/exec-env"
|
2019-01-19 19:59:27 -07:00
|
|
|
|
2023-01-22 21:29:18 -07:00
|
|
|
echo "dummy system" >"$PROJECT_DIR/.tool-versions"
|
2019-01-19 19:59:27 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf env dummy
|
2019-01-19 19:59:27 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2023-01-25 06:37:21 -07:00
|
|
|
run grep 'FOO=bar' <<<"$output"
|
2023-01-14 06:18:44 -07:00
|
|
|
[ "$output" = "" ]
|
2019-01-19 19:59:27 -07:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf env dummy which dummy
|
2023-01-14 06:18:44 -07:00
|
|
|
[ "$output" = "$ASDF_DIR/shims/dummy" ]
|
2019-01-23 21:18:18 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2019-01-19 19:59:27 -07:00
|
|
|
}
|
2019-08-14 16:31:23 -07:00
|
|
|
|
|
|
|
@test "asdf env should set PATH correctly" {
|
2023-01-22 21:29:18 -07:00
|
|
|
echo "dummy 1.0" >"$PROJECT_DIR/.tool-versions"
|
2019-08-14 16:31:23 -07:00
|
|
|
run asdf install
|
|
|
|
|
|
|
|
run asdf env dummy
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
# Should set path
|
|
|
|
path_line=$(echo "$output" | grep '^PATH=')
|
|
|
|
[ "$path_line" != "" ]
|
|
|
|
|
|
|
|
# Should not contain duplicate colon
|
2023-01-25 06:37:21 -07:00
|
|
|
run grep -q '::' <<<"$path_line"
|
|
|
|
[ "$status" -ne 0 ]
|
2019-08-14 16:31:23 -07:00
|
|
|
}
|