asdf/test/which_command.bats
Victor Hugo Borja ab59e5618f Move common functionality to utils.sh
- Make shim-exec, shim-env, and which use the same logic to look for commands
- Make sure shim-exec and which use a plugin exec-path hook as documented
  (the hook takes a relative path to the executable and returns also
   a relative path, possibly modified)
- Fix shellchecks
2019-01-20 14:02:22 -06:00

88 lines
2.1 KiB
Bash

#!/usr/bin/env bats
load test_helpers
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/which.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh
setup() {
setup_asdf_dir
install_dummy_plugin
run asdf install dummy 1.0
PROJECT_DIR=$HOME/project
mkdir $PROJECT_DIR
echo 'dummy 1.0' >> $PROJECT_DIR/.tool-versions
}
teardown() {
clean_asdf_dir
}
@test "which should show dummy 1.0 main binary" {
cd $PROJECT_DIR
run asdf which "dummy"
[ "$status" -eq 0 ]
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/dummy" ]
}
@test "which should fail for unknown binary" {
cd $PROJECT_DIR
run asdf which "sunny"
[ "$status" -eq 1 ]
[ "$output" == "unknown command: sunny. Perhaps you have to reshim?" ]
}
@test "which should show dummy 1.0 other binary" {
cd $PROJECT_DIR
echo "echo bin bin/subdir" > "$ASDF_DIR/plugins/dummy/bin/list-bin-paths"
chmod +x "$ASDF_DIR/plugins/dummy/bin/list-bin-paths"
run asdf reshim dummy 1.0
run asdf which "other_bin"
[ "$status" -eq 0 ]
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/subdir/other_bin" ]
}
@test "which should show path of system version" {
echo 'dummy system' > $PROJECT_DIR/.tool-versions
cd $PROJECT_DIR
mkdir $PROJECT_DIR/sys
touch $PROJECT_DIR/sys/dummy
chmod +x $PROJECT_DIR/sys/dummy
run env PATH=$PATH:$PROJECT_DIR/sys asdf which "dummy"
[ "$status" -eq 0 ]
[ "$output" == "$PROJECT_DIR/sys/dummy" ]
}
@test "which report when missing executable on system version" {
echo 'dummy system' > $PROJECT_DIR/.tool-versions
cd $PROJECT_DIR
run asdf which "dummy"
[ "$status" -eq 1 ]
[ "$output" == "No dummy executable found for dummy system" ]
}
@test "which should inform when no binary is found" {
cd $PROJECT_DIR
run asdf which "bazbat"
[ "$status" -eq 1 ]
[ "$output" == "unknown command: bazbat. Perhaps you have to reshim?" ]
}
@test "which should use path returned by exec-path when present" {
cd $PROJECT_DIR
install_dummy_exec_path_script "dummy"
run asdf which "dummy"
[ "$status" -eq 0 ]
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/custom/dummy" ]
}