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
30 changes: 29 additions & 1 deletion cli/bash/commands/basectl/tests/demo.bats
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,40 @@ EOF
[ -x "$BASE_REPO_ROOT/demo/demo.sh" ]
}

@test "Base self-demo defaults nested commands to its own Base home" {
local fake_bin="$TEST_TMPDIR/fake-bin"
local bash_bin_dir

mkdir -p "$fake_bin"
bash_bin_dir="$(dirname "$(command -v bash)")"
cat > "$fake_bin/basectl" <<'EOF'
#!/usr/bin/env bash
printf 'unexpected PATH basectl invocation\n' >&2
exit 1
EOF
chmod +x "$fake_bin/basectl"

run env \
BASE_HOME="$BASE_REPO_ROOT" \
BASE_BASH_LIBS_DIR="${BASE_BASH_LIBS_DIR:-}" \
PATH="$bash_bin_dir:$fake_bin:/usr/bin:/bin:/usr/sbin:/sbin" \
bash -c '
source "$BASE_HOME/demo/demo.sh"
printf "%s\n%s\n" "$BASE_DEMO_BASECTL" "$BASE_DEMO_BASE_WRAPPER"
'

[ "$status" -eq 0 ]
[ "$output" = "$(printf '%s\n%s' "$BASE_REPO_ROOT/bin/basectl" "$BASE_REPO_ROOT/bin/base-wrapper")" ]
}

@test "basectl demo base runs the self-demo in non-interactive mode" {
local python_bin="$TEST_HOME/.base.d/base/.venv/bin/python"
local fake_bin="$TEST_TMPDIR/fake-bin"
local state_file="$TEST_TMPDIR/self-demo-state"
local bash_bin_dir

mkdir -p "$(dirname "$python_bin")" "$TEST_HOME/.base.d/base/.venv/bin" "$fake_bin"
bash_bin_dir="$(dirname "$(command -v bash)")"
cat > "$python_bin" <<'EOF'
#!/usr/bin/env bash
if [[ "${1:-}" == "-m" && "${2:-}" == "base_projects" && "${3:-}" == "demo-script" && "${4:-}" == "base" ]]; then
Expand Down Expand Up @@ -353,7 +381,7 @@ EOF

run env \
HOME="$TEST_HOME" \
PATH="/usr/bin:/bin:/usr/sbin:/sbin" \
PATH="$bash_bin_dir:$fake_bin:/usr/bin:/bin:/usr/sbin:/sbin" \
BASE_REPO_ROOT="$BASE_REPO_ROOT" \
BASE_TEST_SELF_DEMO_STATE="$state_file" \
BASE_DEMO_BASECTL="$fake_bin/basectl" \
Expand Down
6 changes: 3 additions & 3 deletions demo/demo.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env basectl
#!/usr/bin/env bash
# shellcheck shell=bash

if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
Expand Down Expand Up @@ -34,8 +34,8 @@ source "$BASE_HOME/base_init.sh" || {
exit 1
}

BASE_DEMO_BASECTL="${BASE_DEMO_BASECTL:-basectl}"
BASE_DEMO_BASE_WRAPPER="${BASE_DEMO_BASE_WRAPPER:-base-wrapper}"
BASE_DEMO_BASECTL="${BASE_DEMO_BASECTL:-$BASE_HOME/bin/basectl}"
BASE_DEMO_BASE_WRAPPER="${BASE_DEMO_BASE_WRAPPER:-$BASE_HOME/bin/base-wrapper}"
BASE_DEMO_NON_INTERACTIVE=0

base_demo_usage() {
Expand Down
Loading