Skip to content

Commit 925160e

Browse files
authored
refactor: simplify install.sh to print PATH guidance (#403)
1 parent 00ae3ed commit 925160e

File tree

7 files changed

+606
-176
lines changed

7 files changed

+606
-176
lines changed

.github/workflows/test-install.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Test Install Script
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'install.sh'
7+
- 'e2e/install/**'
8+
- '.github/workflows/test-install.yml'
9+
push:
10+
branches: [main]
11+
paths:
12+
- 'install.sh'
13+
- 'e2e/install/**'
14+
- '.github/workflows/test-install.yml'
15+
workflow_dispatch:
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
test-install:
22+
name: install.sh (${{ matrix.shell }})
23+
runs-on: ubuntu-latest
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
- shell: sh
29+
test: e2e/install/sh_test.sh
30+
run: sh e2e/install/sh_test.sh
31+
- shell: bash
32+
test: e2e/install/bash_test.sh
33+
run: bash e2e/install/bash_test.sh
34+
- shell: zsh
35+
test: e2e/install/zsh_test.sh
36+
run: zsh e2e/install/zsh_test.sh
37+
install: zsh
38+
- shell: fish
39+
test: e2e/install/fish_test.fish
40+
run: fish e2e/install/fish_test.fish
41+
install: fish
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Install ${{ matrix.shell }}
47+
if: matrix.install
48+
run: sudo apt-get update && sudo apt-get install -y ${{ matrix.install }}
49+
50+
- name: Run tests (${{ matrix.shell }})
51+
run: ${{ matrix.run }}

e2e/install/bash_test.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Bash e2e tests for install.sh.
6+
#
7+
# Downloads the latest release for real and validates:
8+
# - Binary is installed to the correct directory
9+
# - Binary is executable and runs
10+
# - PATH guidance shows the correct export command for bash
11+
#
12+
set -euo pipefail
13+
14+
. "$(dirname "$0")/helpers.sh"
15+
16+
# ---------------------------------------------------------------------------
17+
# Tests
18+
# ---------------------------------------------------------------------------
19+
20+
test_binary_installed() {
21+
printf 'TEST: binary exists in install directory\n'
22+
23+
if [ -f "$INSTALL_DIR/openshell" ]; then
24+
pass "openshell binary exists at $INSTALL_DIR/openshell"
25+
else
26+
fail "openshell binary exists" "not found at $INSTALL_DIR/openshell"
27+
fi
28+
}
29+
30+
test_binary_executable() {
31+
printf 'TEST: binary is executable\n'
32+
33+
if [ -x "$INSTALL_DIR/openshell" ]; then
34+
pass "openshell binary is executable"
35+
else
36+
fail "openshell binary is executable" "$INSTALL_DIR/openshell is not executable"
37+
fi
38+
}
39+
40+
test_binary_runs() {
41+
printf 'TEST: binary runs successfully\n'
42+
43+
if _version="$("$INSTALL_DIR/openshell" --version 2>/dev/null)"; then
44+
pass "openshell --version succeeds: $_version"
45+
else
46+
fail "openshell --version succeeds" "exit code: $?"
47+
fi
48+
}
49+
50+
test_guidance_shows_export_path() {
51+
printf 'TEST: guidance shows export PATH for bash users\n'
52+
53+
assert_output_contains "$INSTALL_OUTPUT" 'export PATH="' "shows export PATH command"
54+
assert_output_not_contains "$INSTALL_OUTPUT" "fish_add_path" "does not show fish command"
55+
}
56+
57+
test_guidance_mentions_not_on_path() {
58+
printf 'TEST: guidance mentions install dir is not on PATH\n'
59+
60+
assert_output_contains "$INSTALL_OUTPUT" "is not on your PATH" "mentions PATH issue"
61+
assert_output_contains "$INSTALL_OUTPUT" "$INSTALL_DIR" "includes install dir in guidance"
62+
}
63+
64+
# ---------------------------------------------------------------------------
65+
# Runner
66+
# ---------------------------------------------------------------------------
67+
68+
printf '=== install.sh e2e tests: bash ===\n\n'
69+
70+
printf 'Installing openshell...\n'
71+
SHELL="/bin/bash" run_install
72+
printf 'Done.\n\n'
73+
74+
test_binary_installed; echo ""
75+
test_binary_executable; echo ""
76+
test_binary_runs; echo ""
77+
test_guidance_shows_export_path; echo ""
78+
test_guidance_mentions_not_on_path
79+
80+
print_summary

e2e/install/fish_test.fish

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/usr/bin/env fish
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Fish e2e tests for install.sh.
6+
#
7+
# Downloads the latest release for real and validates:
8+
# - Binary is installed to the correct directory
9+
# - Binary is executable and runs
10+
# - PATH guidance shows fish_add_path (not export PATH)
11+
12+
set -g PASS 0
13+
set -g FAIL 0
14+
15+
# Resolve paths relative to this script
16+
set -g SCRIPT_DIR (builtin cd (dirname (status filename)) && pwd)
17+
set -g REPO_ROOT (builtin cd "$SCRIPT_DIR/../.." && pwd)
18+
set -g INSTALL_SCRIPT "$REPO_ROOT/install.sh"
19+
20+
# Set by run_install
21+
set -g INSTALL_DIR ""
22+
set -g INSTALL_OUTPUT ""
23+
24+
# ---------------------------------------------------------------------------
25+
# Helpers
26+
# ---------------------------------------------------------------------------
27+
28+
function pass
29+
set -g PASS (math $PASS + 1)
30+
printf ' PASS: %s\n' $argv[1]
31+
end
32+
33+
function fail
34+
set -g FAIL (math $FAIL + 1)
35+
printf ' FAIL: %s\n' $argv[1] >&2
36+
if test (count $argv) -gt 1
37+
printf ' %s\n' $argv[2] >&2
38+
end
39+
end
40+
41+
function assert_output_contains
42+
set -l output $argv[1]
43+
set -l pattern $argv[2]
44+
set -l label $argv[3]
45+
46+
if string match -q -- "*$pattern*" "$output"
47+
pass "$label"
48+
else
49+
fail "$label" "expected '$pattern' in output"
50+
end
51+
end
52+
53+
function assert_output_not_contains
54+
set -l output $argv[1]
55+
set -l pattern $argv[2]
56+
set -l label $argv[3]
57+
58+
if string match -q -- "*$pattern*" "$output"
59+
fail "$label" "unexpected '$pattern' found in output"
60+
else
61+
pass "$label"
62+
end
63+
end
64+
65+
function run_install
66+
set -g INSTALL_DIR (mktemp -d)/bin
67+
68+
set -g INSTALL_OUTPUT (OPENSHELL_INSTALL_DIR="$INSTALL_DIR" \
69+
SHELL="/usr/bin/fish" \
70+
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" \
71+
sh "$INSTALL_SCRIPT" 2>&1)
72+
73+
if test $status -ne 0
74+
printf 'install.sh failed:\n%s\n' "$INSTALL_OUTPUT" >&2
75+
return 1
76+
end
77+
end
78+
79+
# ---------------------------------------------------------------------------
80+
# Tests
81+
# ---------------------------------------------------------------------------
82+
83+
function test_binary_installed
84+
printf 'TEST: binary exists in install directory\n'
85+
86+
if test -f "$INSTALL_DIR/openshell"
87+
pass "openshell binary exists at $INSTALL_DIR/openshell"
88+
else
89+
fail "openshell binary exists" "not found at $INSTALL_DIR/openshell"
90+
end
91+
end
92+
93+
function test_binary_executable
94+
printf 'TEST: binary is executable\n'
95+
96+
if test -x "$INSTALL_DIR/openshell"
97+
pass "openshell binary is executable"
98+
else
99+
fail "openshell binary is executable" "$INSTALL_DIR/openshell is not executable"
100+
end
101+
end
102+
103+
function test_binary_runs
104+
printf 'TEST: binary runs successfully\n'
105+
106+
set -l version_output ("$INSTALL_DIR/openshell" --version 2>/dev/null)
107+
if test $status -eq 0
108+
pass "openshell --version succeeds: $version_output"
109+
else
110+
fail "openshell --version succeeds" "exit code: $status"
111+
end
112+
end
113+
114+
function test_guidance_shows_fish_add_path
115+
printf 'TEST: guidance shows fish_add_path for fish users\n'
116+
117+
assert_output_contains "$INSTALL_OUTPUT" "fish_add_path" "shows fish_add_path command"
118+
assert_output_not_contains "$INSTALL_OUTPUT" 'export PATH="' "does not show POSIX export"
119+
end
120+
121+
function test_guidance_mentions_not_on_path
122+
printf 'TEST: guidance mentions install dir is not on PATH\n'
123+
124+
assert_output_contains "$INSTALL_OUTPUT" "is not on your PATH" "mentions PATH issue"
125+
assert_output_contains "$INSTALL_OUTPUT" "$INSTALL_DIR" "includes install dir in guidance"
126+
end
127+
128+
# ---------------------------------------------------------------------------
129+
# Runner
130+
# ---------------------------------------------------------------------------
131+
132+
printf '=== install.sh e2e tests: fish ===\n\n'
133+
134+
printf 'Installing openshell...\n'
135+
run_install
136+
printf 'Done.\n\n'
137+
138+
test_binary_installed
139+
echo ""
140+
test_binary_executable
141+
echo ""
142+
test_binary_runs
143+
echo ""
144+
test_guidance_shows_fish_add_path
145+
echo ""
146+
test_guidance_mentions_not_on_path
147+
148+
printf '\n=== Results: %d passed, %d failed ===\n' $PASS $FAIL
149+
150+
if test $FAIL -gt 0
151+
exit 1
152+
end

e2e/install/helpers.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/sh
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Shared test helpers for install.sh e2e tests.
6+
# Sourced by each per-shell test file (except fish, which has its own helpers).
7+
#
8+
# Provides:
9+
# - pass / fail / print_summary
10+
# - assert_output_contains / assert_output_not_contains
11+
# - run_install (runs the real install.sh to a temp dir, captures output)
12+
# - REPO_ROOT / INSTALL_SCRIPT paths
13+
# - INSTALL_DIR / INSTALL_OUTPUT (set after run_install)
14+
15+
HELPERS_DIR="$(cd "$(dirname "$0")" && pwd)"
16+
REPO_ROOT="$(cd "$HELPERS_DIR/../.." && pwd)"
17+
INSTALL_SCRIPT="$REPO_ROOT/install.sh"
18+
19+
_PASS=0
20+
_FAIL=0
21+
22+
# Set by run_install
23+
INSTALL_DIR=""
24+
INSTALL_OUTPUT=""
25+
26+
# ---------------------------------------------------------------------------
27+
# Assertions
28+
# ---------------------------------------------------------------------------
29+
30+
pass() {
31+
_PASS=$((_PASS + 1))
32+
printf ' PASS: %s\n' "$1"
33+
}
34+
35+
fail() {
36+
_FAIL=$((_FAIL + 1))
37+
printf ' FAIL: %s\n' "$1" >&2
38+
if [ -n "${2:-}" ]; then
39+
printf ' %s\n' "$2" >&2
40+
fi
41+
}
42+
43+
assert_output_contains() {
44+
_aoc_output="$1"
45+
_aoc_pattern="$2"
46+
_aoc_label="$3"
47+
48+
if printf '%s' "$_aoc_output" | grep -qF "$_aoc_pattern"; then
49+
pass "$_aoc_label"
50+
else
51+
fail "$_aoc_label" "expected '$_aoc_pattern' in output"
52+
fi
53+
}
54+
55+
assert_output_not_contains() {
56+
_aonc_output="$1"
57+
_aonc_pattern="$2"
58+
_aonc_label="$3"
59+
60+
if printf '%s' "$_aonc_output" | grep -qF "$_aonc_pattern"; then
61+
fail "$_aonc_label" "unexpected '$_aonc_pattern' found in output"
62+
else
63+
pass "$_aonc_label"
64+
fi
65+
}
66+
67+
# ---------------------------------------------------------------------------
68+
# Install runner
69+
# ---------------------------------------------------------------------------
70+
71+
# Run the real install.sh, installing to a temp directory with the install
72+
# dir removed from PATH so we always get PATH guidance output.
73+
#
74+
# Sets INSTALL_DIR and INSTALL_OUTPUT for subsequent assertions.
75+
# The SHELL variable is passed through so tests can control which shell
76+
# guidance is shown.
77+
#
78+
# Usage:
79+
# SHELL="/bin/bash" run_install
80+
run_install() {
81+
INSTALL_DIR="$(mktemp -d)/bin"
82+
83+
# Remove the install dir from PATH (it won't be there, but be explicit).
84+
# Keep a minimal PATH so curl/tar/install are available.
85+
INSTALL_OUTPUT="$(OPENSHELL_INSTALL_DIR="$INSTALL_DIR" \
86+
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" \
87+
sh "$INSTALL_SCRIPT" 2>&1)" || {
88+
printf 'install.sh failed:\n%s\n' "$INSTALL_OUTPUT" >&2
89+
return 1
90+
}
91+
}
92+
93+
# ---------------------------------------------------------------------------
94+
# Summary
95+
# ---------------------------------------------------------------------------
96+
97+
print_summary() {
98+
printf '\n=== Results: %d passed, %d failed ===\n' "$_PASS" "$_FAIL"
99+
[ "$_FAIL" -eq 0 ]
100+
}

0 commit comments

Comments
 (0)