mirror of
https://github.com/arthur-pbty/arthur-os.git
synced 2026-08-04 20:28:23 +02:00
77 lines
3.0 KiB
Bash
Executable File
77 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
source "$(dirname "$0")/base-test.sh"
|
|
|
|
run_bootstrap() {
|
|
local shell_bin="$1"
|
|
local bootstrap="$2"
|
|
local home="$3"
|
|
local path_value="$4"
|
|
|
|
HOME="$home" PATH="$path_value" "$shell_bin" -c '
|
|
. "$1"
|
|
printf "%s\n%s\n" "$OMARCHY_PATH" "$PATH"
|
|
' sh "$bootstrap"
|
|
}
|
|
|
|
assert_path_first() {
|
|
local path_value="$1"
|
|
local entry="$2"
|
|
local description="$3"
|
|
|
|
[[ ${path_value%%:*} == "$entry" ]] || fail "$description" "expected first PATH entry: $entry\nactual PATH: $path_value"
|
|
pass "$description"
|
|
}
|
|
|
|
assert_path_present() {
|
|
local path_value="$1"
|
|
local entry="$2"
|
|
local description="$3"
|
|
|
|
case ":$path_value:" in
|
|
*":$entry:"*) pass "$description" ;;
|
|
*) fail "$description" "PATH does not contain $entry in $path_value" ;;
|
|
esac
|
|
}
|
|
|
|
tmpdir=$(mktemp -d)
|
|
trap 'rm -rf "$tmpdir"' EXIT
|
|
|
|
home="$tmpdir/home"
|
|
mkdir -p "$tmpdir/active/bin" "$tmpdir/unrelated/bin"
|
|
|
|
# Test against a copy so the test controls /etc/omarchy.conf without mutating the host.
|
|
bootstrap="$tmpdir/env-bootstrap"
|
|
sed "s#/etc/omarchy.conf#$tmpdir/omarchy.conf#g" "$ROOT/default/bash/env-bootstrap" >"$bootstrap"
|
|
|
|
printf 'export OMARCHY_PATH="/usr/share/omarchy"\n' >"$tmpdir/omarchy.conf"
|
|
mapfile -t default_result < <(run_bootstrap bash "$bootstrap" "$home" "$tmpdir/unrelated/bin:/usr/bin")
|
|
default_path=${default_result[1]}
|
|
|
|
[[ ${default_result[0]} == /usr/share/omarchy ]] || fail "env-bootstrap resolves default OMARCHY_PATH" "actual: ${default_result[0]}"
|
|
pass "env-bootstrap resolves default OMARCHY_PATH"
|
|
assert_path_present "$default_path" "$tmpdir/unrelated/bin" "env-bootstrap preserves PATH entries in default mode"
|
|
|
|
printf 'export OMARCHY_PATH="%s"\n' "$tmpdir/active" >"$tmpdir/omarchy.conf"
|
|
mapfile -t linked_result < <(run_bootstrap bash "$bootstrap" "$home" "$tmpdir/unrelated/bin:/usr/bin")
|
|
linked_path=${linked_result[1]}
|
|
|
|
[[ ${linked_result[0]} == "$tmpdir/active" ]] || fail "env-bootstrap resolves linked OMARCHY_PATH" "actual: ${linked_result[0]}"
|
|
pass "env-bootstrap resolves linked OMARCHY_PATH"
|
|
assert_path_first "$linked_path" "$tmpdir/active/bin" "env-bootstrap prepends active checkout bin in linked mode"
|
|
assert_path_present "$linked_path" "$tmpdir/unrelated/bin" "env-bootstrap preserves unrelated PATH entries in linked mode"
|
|
|
|
mapfile -t linked_duplicate_result < <(run_bootstrap bash "$bootstrap" "$home" "$tmpdir/active/bin:/usr/bin")
|
|
linked_duplicate_path=${linked_duplicate_result[1]}
|
|
[[ $linked_duplicate_path == "$tmpdir/active/bin:/usr/bin" ]] || fail "env-bootstrap does not duplicate active checkout bin" "actual PATH: $linked_duplicate_path"
|
|
pass "env-bootstrap does not duplicate active checkout bin"
|
|
|
|
if command -v zsh >/dev/null 2>&1; then
|
|
mapfile -t zsh_result < <(run_bootstrap zsh "$bootstrap" "$home" "$tmpdir/unrelated/bin:/usr/bin")
|
|
zsh_path=${zsh_result[1]}
|
|
assert_path_first "$zsh_path" "$tmpdir/active/bin" "env-bootstrap works when sourced by zsh"
|
|
assert_path_present "$zsh_path" "$tmpdir/unrelated/bin" "env-bootstrap zsh mode preserves unrelated PATH entries"
|
|
fi
|