mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
test plugin in subshell and from isolated asdf
The subshell sources the isolated asdf environment, making the asdf command available. In some plugin tests we were having failures do to the asdf bin not set on PATH.
This commit is contained in:
parent
c060b4c390
commit
950853d9e6
@ -1,18 +1,28 @@
|
||||
fail_test() {
|
||||
echo "FAILED: $1"
|
||||
rm -rf "$ASDF_DIR"
|
||||
exit 1
|
||||
}
|
||||
|
||||
plugin_test_command() {
|
||||
ASDF_DIR=$(mktemp -dt asdf.XXXX)
|
||||
export ASDF_DIR
|
||||
git clone https://github.com/asdf-vm/asdf.git "$ASDF_DIR"
|
||||
|
||||
local plugin_name=$1
|
||||
local plugin_url=$2
|
||||
local plugin_command="${*:3}"
|
||||
|
||||
local exit_code
|
||||
local TEST_DIR
|
||||
|
||||
TEST_DIR=$(mktemp -dt asdf.XXXX)
|
||||
git clone "$ASDF_DIR/.git" "$TEST_DIR"
|
||||
|
||||
fail_test() {
|
||||
echo "FAILED: $1"
|
||||
rm -rf "$TEST_DIR"
|
||||
exit 1
|
||||
}
|
||||
|
||||
plugin_test() {
|
||||
export ASDF_DIR=$TEST_DIR
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$ASDF_DIR/asdf.sh"
|
||||
|
||||
if [ -z "$plugin_name" ] || [ -z "$plugin_url" ]; then
|
||||
fail_test "please provide a plugin name and url"
|
||||
fi
|
||||
@ -25,6 +35,7 @@ plugin_test_command() {
|
||||
fail_test "$plugin_name was not properly installed"
|
||||
fi
|
||||
|
||||
|
||||
local versions
|
||||
# shellcheck disable=SC2046
|
||||
if ! read -r -a versions <<< $(asdf list-all "$plugin_name"); then
|
||||
@ -42,7 +53,7 @@ plugin_test_command() {
|
||||
fail_test "install exited with an error"
|
||||
fi
|
||||
|
||||
cd "$ASDF_DIR" || fail_test "could not cd $ASDF_DIR"
|
||||
cd "$TEST_DIR" || fail_test "could not cd $TEST_DIR"
|
||||
|
||||
if ! (asdf local "$plugin_name" "$latest_version"); then
|
||||
fail_test "install did not add the requested version"
|
||||
@ -53,8 +64,7 @@ plugin_test_command() {
|
||||
fi
|
||||
|
||||
if [ -n "$plugin_command" ]; then
|
||||
(PATH="$ASDF_DIR/bin:$ASDF_DIR/shims:$PATH" "$plugin_command")
|
||||
local exit_code
|
||||
$plugin_command
|
||||
exit_code=$?
|
||||
if [ $exit_code != 0 ]; then
|
||||
fail_test "$plugin_command failed with exit code $?"
|
||||
@ -78,6 +88,11 @@ plugin_test_command() {
|
||||
else
|
||||
fail_test "LICENSE file must be present in the plugin repository"
|
||||
fi
|
||||
|
||||
rm -rf "$ASDF_DIR"
|
||||
}
|
||||
|
||||
# run test in a subshell
|
||||
(plugin_test)
|
||||
exit_code=$?
|
||||
rm -rf "$TEST_DIR"
|
||||
exit $exit_code
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user