diff --git a/ci/install.sh b/ci/install.sh index 2830b7ba..ae7909eb 100644 --- a/ci/install.sh +++ b/ci/install.sh @@ -16,7 +16,7 @@ Options: --crate NAME Name of the crate to install (default ) --tag TAG Tag (version) of the crate to install (default ) --target TARGET Install the release compiled for $TARGET (default <`rustc` host>) - --to LOCATION Where to install the binary (default ~/.cargo/bin) + --to LOCATION Where to install the binary (default $CARGO_HOME/bin or ~/.cargo/bin) EOF } @@ -130,7 +130,7 @@ fi say_err "Target: $target" if [ -z $dest ]; then - dest="$HOME/.cargo/bin" + dest="${CARGO_HOME:-$HOME/.cargo}/bin" fi say_err "Installing to: $dest" diff --git a/tests/snapshots/failure-install-script-defaults-to-cargo-home b/tests/snapshots/failure-install-script-defaults-to-cargo-home new file mode 100644 index 00000000..0c0039ab --- /dev/null +++ b/tests/snapshots/failure-install-script-defaults-to-cargo-home @@ -0,0 +1,7 @@ +install.sh: GitHub repository: https://github.com/Byron/dua-cli +install.sh: Crate: dua +install.sh: Tag: v2.29.0 +install.sh: Target: does-not-exist +install.sh: Installing to: /tmp/dua-cargo-home/bin +install.sh: Downloading: https://github.com/Byron/dua-cli/releases/download/v2.29.0/dua-v2.29.0-does-not-exist.tar.gz +stub tar failure \ No newline at end of file diff --git a/tests/snapshots/failure-install-script-defaults-to-home-cargo-bin b/tests/snapshots/failure-install-script-defaults-to-home-cargo-bin new file mode 100644 index 00000000..cf4fc816 --- /dev/null +++ b/tests/snapshots/failure-install-script-defaults-to-home-cargo-bin @@ -0,0 +1,7 @@ +install.sh: GitHub repository: https://github.com/Byron/dua-cli +install.sh: Crate: dua +install.sh: Tag: v2.29.0 +install.sh: Target: does-not-exist +install.sh: Installing to: /tmp/dua-install-home/.cargo/bin +install.sh: Downloading: https://github.com/Byron/dua-cli/releases/download/v2.29.0/dua-v2.29.0-does-not-exist.tar.gz +stub tar failure \ No newline at end of file diff --git a/tests/stateless-journey.sh b/tests/stateless-journey.sh index 2557f3ad..04e72227 100755 --- a/tests/stateless-journey.sh +++ b/tests/stateless-journey.sh @@ -113,3 +113,41 @@ WITH_FAILURE=1 } ) ) + +(with "the install script" + (sandbox + mkdir fakebin + cat > fakebin/curl <<'EOF' +#!/bin/sh +exit 0 +EOF + cat > fakebin/tar <<'EOF' +#!/bin/sh +echo "stub tar failure" >&2 +exit 1 +EOF + chmod +x fakebin/curl fakebin/tar + rm -rf /tmp/dua-install-home /tmp/dua-cargo-home + it "uses CARGO_HOME for the default install location" && { + WITH_SNAPSHOT="$snapshot/failure-install-script-defaults-to-cargo-home" \ + PATH="$PWD/fakebin:$PATH" \ + HOME=/tmp/dua-install-home \ + CARGO_HOME=/tmp/dua-cargo-home \ + expect_run ${WITH_FAILURE} sh "$root/../ci/install.sh" \ + --git Byron/dua-cli \ + --crate dua \ + --tag v2.29.0 \ + --target does-not-exist + } + it "falls back to HOME/.cargo/bin when CARGO_HOME is unset" && { + WITH_SNAPSHOT="$snapshot/failure-install-script-defaults-to-home-cargo-bin" \ + PATH="$PWD/fakebin:$PATH" \ + HOME=/tmp/dua-install-home \ + expect_run ${WITH_FAILURE} sh "$root/../ci/install.sh" \ + --git Byron/dua-cli \ + --crate dua \ + --tag v2.29.0 \ + --target does-not-exist + } + ) +)