Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/test-install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Test Install Script

on:
pull_request:
paths:
- 'install.sh'
- 'e2e/install/**'
- '.github/workflows/test-install.yml'
push:
branches: [main]
paths:
- 'install.sh'
- 'e2e/install/**'
- '.github/workflows/test-install.yml'
workflow_dispatch:

permissions:
contents: read

jobs:
test-install:
name: install.sh (${{ matrix.shell }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- shell: sh
test: e2e/install/sh_test.sh
run: sh e2e/install/sh_test.sh
- shell: bash
test: e2e/install/bash_test.sh
run: bash e2e/install/bash_test.sh
- shell: zsh
test: e2e/install/zsh_test.sh
run: zsh e2e/install/zsh_test.sh
install: zsh
- shell: fish
test: e2e/install/fish_test.fish
run: fish e2e/install/fish_test.fish
install: fish

steps:
- uses: actions/checkout@v4

- name: Install ${{ matrix.shell }}
if: matrix.install
run: sudo apt-get update && sudo apt-get install -y ${{ matrix.install }}

- name: Run tests (${{ matrix.shell }})
run: ${{ matrix.run }}
80 changes: 80 additions & 0 deletions e2e/install/bash_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Bash e2e tests for install.sh.
#
# Downloads the latest release for real and validates:
# - Binary is installed to the correct directory
# - Binary is executable and runs
# - PATH guidance shows the correct export command for bash
#
set -euo pipefail

. "$(dirname "$0")/helpers.sh"

# ---------------------------------------------------------------------------
# Tests
# ---------------------------------------------------------------------------

test_binary_installed() {
printf 'TEST: binary exists in install directory\n'

if [ -f "$INSTALL_DIR/openshell" ]; then
pass "openshell binary exists at $INSTALL_DIR/openshell"
else
fail "openshell binary exists" "not found at $INSTALL_DIR/openshell"
fi
}

test_binary_executable() {
printf 'TEST: binary is executable\n'

if [ -x "$INSTALL_DIR/openshell" ]; then
pass "openshell binary is executable"
else
fail "openshell binary is executable" "$INSTALL_DIR/openshell is not executable"
fi
}

test_binary_runs() {
printf 'TEST: binary runs successfully\n'

if _version="$("$INSTALL_DIR/openshell" --version 2>/dev/null)"; then
pass "openshell --version succeeds: $_version"
else
fail "openshell --version succeeds" "exit code: $?"
fi
}

test_guidance_shows_export_path() {
printf 'TEST: guidance shows export PATH for bash users\n'

assert_output_contains "$INSTALL_OUTPUT" 'export PATH="' "shows export PATH command"
assert_output_not_contains "$INSTALL_OUTPUT" "fish_add_path" "does not show fish command"
}

test_guidance_mentions_not_on_path() {
printf 'TEST: guidance mentions install dir is not on PATH\n'

assert_output_contains "$INSTALL_OUTPUT" "is not on your PATH" "mentions PATH issue"
assert_output_contains "$INSTALL_OUTPUT" "$INSTALL_DIR" "includes install dir in guidance"
}

# ---------------------------------------------------------------------------
# Runner
# ---------------------------------------------------------------------------

printf '=== install.sh e2e tests: bash ===\n\n'

printf 'Installing openshell...\n'
SHELL="/bin/bash" run_install
printf 'Done.\n\n'

test_binary_installed; echo ""
test_binary_executable; echo ""
test_binary_runs; echo ""
test_guidance_shows_export_path; echo ""
test_guidance_mentions_not_on_path

print_summary
152 changes: 152 additions & 0 deletions e2e/install/fish_test.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env fish
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Fish e2e tests for install.sh.
#
# Downloads the latest release for real and validates:
# - Binary is installed to the correct directory
# - Binary is executable and runs
# - PATH guidance shows fish_add_path (not export PATH)

set -g PASS 0
set -g FAIL 0

# Resolve paths relative to this script
set -g SCRIPT_DIR (builtin cd (dirname (status filename)) && pwd)
set -g REPO_ROOT (builtin cd "$SCRIPT_DIR/../.." && pwd)
set -g INSTALL_SCRIPT "$REPO_ROOT/install.sh"

# Set by run_install
set -g INSTALL_DIR ""
set -g INSTALL_OUTPUT ""

# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------

function pass
set -g PASS (math $PASS + 1)
printf ' PASS: %s\n' $argv[1]
end

function fail
set -g FAIL (math $FAIL + 1)
printf ' FAIL: %s\n' $argv[1] >&2
if test (count $argv) -gt 1
printf ' %s\n' $argv[2] >&2
end
end

function assert_output_contains
set -l output $argv[1]
set -l pattern $argv[2]
set -l label $argv[3]

if string match -q -- "*$pattern*" "$output"
pass "$label"
else
fail "$label" "expected '$pattern' in output"
end
end

function assert_output_not_contains
set -l output $argv[1]
set -l pattern $argv[2]
set -l label $argv[3]

if string match -q -- "*$pattern*" "$output"
fail "$label" "unexpected '$pattern' found in output"
else
pass "$label"
end
end

function run_install
set -g INSTALL_DIR (mktemp -d)/bin

set -g INSTALL_OUTPUT (OPENSHELL_INSTALL_DIR="$INSTALL_DIR" \
SHELL="/usr/bin/fish" \
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" \
sh "$INSTALL_SCRIPT" 2>&1)

if test $status -ne 0
printf 'install.sh failed:\n%s\n' "$INSTALL_OUTPUT" >&2
return 1
end
end

# ---------------------------------------------------------------------------
# Tests
# ---------------------------------------------------------------------------

function test_binary_installed
printf 'TEST: binary exists in install directory\n'

if test -f "$INSTALL_DIR/openshell"
pass "openshell binary exists at $INSTALL_DIR/openshell"
else
fail "openshell binary exists" "not found at $INSTALL_DIR/openshell"
end
end

function test_binary_executable
printf 'TEST: binary is executable\n'

if test -x "$INSTALL_DIR/openshell"
pass "openshell binary is executable"
else
fail "openshell binary is executable" "$INSTALL_DIR/openshell is not executable"
end
end

function test_binary_runs
printf 'TEST: binary runs successfully\n'

set -l version_output ("$INSTALL_DIR/openshell" --version 2>/dev/null)
if test $status -eq 0
pass "openshell --version succeeds: $version_output"
else
fail "openshell --version succeeds" "exit code: $status"
end
end

function test_guidance_shows_fish_add_path
printf 'TEST: guidance shows fish_add_path for fish users\n'

assert_output_contains "$INSTALL_OUTPUT" "fish_add_path" "shows fish_add_path command"
assert_output_not_contains "$INSTALL_OUTPUT" 'export PATH="' "does not show POSIX export"
end

function test_guidance_mentions_not_on_path
printf 'TEST: guidance mentions install dir is not on PATH\n'

assert_output_contains "$INSTALL_OUTPUT" "is not on your PATH" "mentions PATH issue"
assert_output_contains "$INSTALL_OUTPUT" "$INSTALL_DIR" "includes install dir in guidance"
end

# ---------------------------------------------------------------------------
# Runner
# ---------------------------------------------------------------------------

printf '=== install.sh e2e tests: fish ===\n\n'

printf 'Installing openshell...\n'
run_install
printf 'Done.\n\n'

test_binary_installed
echo ""
test_binary_executable
echo ""
test_binary_runs
echo ""
test_guidance_shows_fish_add_path
echo ""
test_guidance_mentions_not_on_path

printf '\n=== Results: %d passed, %d failed ===\n' $PASS $FAIL

if test $FAIL -gt 0
exit 1
end
100 changes: 100 additions & 0 deletions e2e/install/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/sh
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Shared test helpers for install.sh e2e tests.
# Sourced by each per-shell test file (except fish, which has its own helpers).
#
# Provides:
# - pass / fail / print_summary
# - assert_output_contains / assert_output_not_contains
# - run_install (runs the real install.sh to a temp dir, captures output)
# - REPO_ROOT / INSTALL_SCRIPT paths
# - INSTALL_DIR / INSTALL_OUTPUT (set after run_install)

HELPERS_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$HELPERS_DIR/../.." && pwd)"
INSTALL_SCRIPT="$REPO_ROOT/install.sh"

_PASS=0
_FAIL=0

# Set by run_install
INSTALL_DIR=""
INSTALL_OUTPUT=""

# ---------------------------------------------------------------------------
# Assertions
# ---------------------------------------------------------------------------

pass() {
_PASS=$((_PASS + 1))
printf ' PASS: %s\n' "$1"
}

fail() {
_FAIL=$((_FAIL + 1))
printf ' FAIL: %s\n' "$1" >&2
if [ -n "${2:-}" ]; then
printf ' %s\n' "$2" >&2
fi
}

assert_output_contains() {
_aoc_output="$1"
_aoc_pattern="$2"
_aoc_label="$3"

if printf '%s' "$_aoc_output" | grep -qF "$_aoc_pattern"; then
pass "$_aoc_label"
else
fail "$_aoc_label" "expected '$_aoc_pattern' in output"
fi
}

assert_output_not_contains() {
_aonc_output="$1"
_aonc_pattern="$2"
_aonc_label="$3"

if printf '%s' "$_aonc_output" | grep -qF "$_aonc_pattern"; then
fail "$_aonc_label" "unexpected '$_aonc_pattern' found in output"
else
pass "$_aonc_label"
fi
}

# ---------------------------------------------------------------------------
# Install runner
# ---------------------------------------------------------------------------

# Run the real install.sh, installing to a temp directory with the install
# dir removed from PATH so we always get PATH guidance output.
#
# Sets INSTALL_DIR and INSTALL_OUTPUT for subsequent assertions.
# The SHELL variable is passed through so tests can control which shell
# guidance is shown.
#
# Usage:
# SHELL="/bin/bash" run_install
run_install() {
INSTALL_DIR="$(mktemp -d)/bin"

# Remove the install dir from PATH (it won't be there, but be explicit).
# Keep a minimal PATH so curl/tar/install are available.
INSTALL_OUTPUT="$(OPENSHELL_INSTALL_DIR="$INSTALL_DIR" \
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" \
sh "$INSTALL_SCRIPT" 2>&1)" || {
printf 'install.sh failed:\n%s\n' "$INSTALL_OUTPUT" >&2
return 1
}
}

# ---------------------------------------------------------------------------
# Summary
# ---------------------------------------------------------------------------

print_summary() {
printf '\n=== Results: %d passed, %d failed ===\n' "$_PASS" "$_FAIL"
[ "$_FAIL" -eq 0 ]
}
Loading
Loading