diff --git a/bats/tests/helpers/info.bash b/bats/tests/helpers/info.bash new file mode 100644 index 00000000000..bbb940966c7 --- /dev/null +++ b/bats/tests/helpers/info.bash @@ -0,0 +1,15 @@ +load load.bash + +# This file exists to print information about the configuration just once, e.g. +# +# bats test/helpers/info.bash tests/* +# +# This can't be done during normal `load` operation because then it would be +# printed for every single test run. + +# The info output is wrapped in a dummy test because bats doesn't execute +# files that don't contain at least a single test case. + +@test "info" { + echo "Using '$RD_LOCATION' install; resources '$PATH_RESOURCES'" >&3 +} diff --git a/bats/tests/helpers/load.bash b/bats/tests/helpers/load.bash index ca7f9d4bd1e..79013142cc8 100644 --- a/bats/tests/helpers/load.bash +++ b/bats/tests/helpers/load.bash @@ -1,14 +1,11 @@ set -o errexit -o nounset -o pipefail -# Get absolute path names for current and top directories -PATH_BATS_HELPERS=$( - cd "$(dirname "${BASH_SOURCE[0]}")" - pwd -) -PATH_BATS_ROOT=$( - cd "$PATH_BATS_HELPERS/../.." - pwd -) +absolute_path() { + (cd "$1"; pwd) +} + +PATH_BATS_HELPERS=$(absolute_path "$(dirname "${BASH_SOURCE[0]}")") +PATH_BATS_ROOT=$(absolute_path "$PATH_BATS_HELPERS/../..") # Use fatal() to abort loading helpers; don't run any tests fatal() { diff --git a/bats/tests/helpers/paths.bash b/bats/tests/helpers/paths.bash index 50fef6a2cc5..c8ea5654512 100644 --- a/bats/tests/helpers/paths.bash +++ b/bats/tests/helpers/paths.bash @@ -1,11 +1,10 @@ # PATH_BATS_ROOT and PATH_BATS_HELPERS are already set by load.bash -PATH_REPO_ROOT=$( - # We are running with `set -o errexit`, so no need for explicit error checking - # shellcheck disable=SC2164 - cd "$PATH_BATS_ROOT/.." - pwd -) +PATH_REPO_ROOT=$(absolute_path "$PATH_BATS_ROOT/..") + +inside_repo_clone() { + [ -d "$PATH_REPO_ROOT/pkg/rancher-desktop" ] +} set_path_resources() { local system=$1 @@ -18,15 +17,20 @@ set_path_resources() { RD_LOCATION=system elif [ -d "$user" ]; then RD_LOCATION=user - elif [ -d "$PATH_REPO_ROOT/pkg/rancher-desktop" ]; then - # dist and npm only work when inside a repo clone + elif inside_repo_clone; then if [ -d "$dist" ]; then RD_LOCATION=dist else RD_LOCATION=npm fi else - fatal "Could not locate Rancher Desktop installation" + ( + echo "Couldn't locate Rancher Desktop in" + echo "- \"$system\"" + echo "- \"$user\"" + echo "and 'npm run dev' is unavailable outside repo clone" + ) >&3 + exit 1 fi fi if using_npm_run_dev; then @@ -50,14 +54,14 @@ if is_macos; then PATH_EXTENSIONS="$PATH_APP_HOME/extensions" LIMA_HOME="$PATH_APP_HOME/lima" - DIST_ARCH="mac" + ELECTRON_DIST_ARCH="mac" if is_macos arm64; then - DIST_ARCH="mac-arm64" + ELECTRON_DIST_ARCH="mac-arm64" fi set_path_resources \ "/Applications/Rancher Desktop.app" \ "$HOME/Applications/Rancher Desktop.app" \ - "$PATH_REPO_ROOT/dist/$DIST_ARCH/Rancher Desktop.app" \ + "$PATH_REPO_ROOT/dist/$ELECTRON_DIST_ARCH/Rancher Desktop.app" \ "Contents/Resources/resources" fi