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
12 changes: 9 additions & 3 deletions crates/bashkit/tests/integration/spec_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,24 @@ async fn run_spec_test_paused_time(test: &SpecTest) -> TestResult {

/// Run a spec test against real bash for comparison
pub fn run_real_bash(script: &str) -> (String, i32) {
// Important decision: host bash comparison is untrusted spec input. Run it
// from a private temp directory, and remap hard-coded /tmp paths there, so
// redirects cannot clobber host or repo files while stdout parity remains /tmp-based.
// Run the host comparison from a private directory and remap fixture paths
// under /tmp. Scripts that assume Bashkit's synthetic root must opt out of
// the host comparison.
let sandbox = tempfile::tempdir().expect("Failed to create bash comparison tempdir");
let sandbox_tmp = sandbox.path().to_string_lossy();
let sandbox_tmp_prefix = format!("{sandbox_tmp}/");
let rewritten_script = script.replace("/tmp/", &sandbox_tmp_prefix);
// Set the initial mask outside the fixture so its line numbers stay intact.
let oracle_env =
tempfile::NamedTempFile::new().expect("Failed to create Bash oracle init file");
fs::write(oracle_env.path(), "umask 022\nunset BASH_ENV\n")
.expect("Failed to write Bash oracle init file");
let output = Command::new("bash")
.arg("-c")
.arg(&rewritten_script)
.current_dir(sandbox.path())
.env("TMPDIR", sandbox.path())
.env("BASH_ENV", oracle_env.path())
// A bashkit script is a top-level shell; drop the test runner's own
// SHLVL so real bash starts at 1 too.
.env_remove("SHLVL")
Expand Down
14 changes: 11 additions & 3 deletions crates/bashkit/tests/spec_cases/bash/fmt.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,17 @@ rc=1
### end

### fmt_goal_over_width
LC_ALL=C fmt -w 20 -g 30 </dev/null 2>&1; echo "rc=$?"
### expect
fmt: invalid width: '30': Numerical result out of range
# GNU coreutils versions use different errno messages for this bound.
diagnostic=$(LC_ALL=C fmt -w 20 -g 30 </dev/null 2>&1)
rc=$?
case "$diagnostic" in
*": Numerical result out of range"|*": Value too large for defined data type")
diagnostic=${diagnostic%: *}
;;
esac
printf '%s\nrc=%s\n' "$diagnostic" "$rc"
### expect
fmt: invalid width: '30'
rc=1
### end

Expand Down
2 changes: 1 addition & 1 deletion crates/bashkit/tests/spec_cases/bash/jobs.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ code=1
### jobs_list_running
sleep 2 & sleep 3 &
true &
sleep 0.1
wait %3
jobs
jobs -p | wc -l
kill %1 %2
Expand Down
16 changes: 8 additions & 8 deletions crates/bashkit/tests/spec_cases/bash/script-exec.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ inner

### script_exec_path_search
# $PATH search finds executable
mkdir -p /usr/local/bin
mkdir -p /tmp/bin
echo '#!/bin/bash
echo found via path' > /usr/local/bin/myutil
chmod +x /usr/local/bin/myutil
PATH=/usr/local/bin
echo found via path' > /tmp/bin/myutil
chmod +x /tmp/bin/myutil
PATH=/tmp/bin
myutil
### expect
found via path
Expand Down Expand Up @@ -131,14 +131,14 @@ got: test input

### script_exec_pipe_stdin_path_search
# Piped stdin works for PATH-based script execution
mkdir -p /usr/local/bin
cat > /usr/local/bin/my-tool <<'SCRIPT'
mkdir -p /tmp/bin
cat > /tmp/bin/my-tool <<'SCRIPT'
#!/usr/bin/env bash
input="$(cat)"
echo "received: ${input}"
SCRIPT
chmod +x /usr/local/bin/my-tool
export PATH="/usr/local/bin:${PATH}"
chmod +x /tmp/bin/my-tool
export PATH="/tmp/bin:${PATH}"
echo "data" | my-tool
### expect
received: data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ parent still: parent
not_exported="hidden"
export VISIBLE="yes"

mkdir -p /usr/local/bin
cat > /usr/local/bin/check-isolation <<'SCRIPT'
mkdir -p /tmp/bin
cat > /tmp/bin/check-isolation <<'SCRIPT'
#!/usr/bin/env bash
echo "visible=${VISIBLE:-unset}"
echo "hidden=${not_exported:-unset}"
SCRIPT
chmod +x /usr/local/bin/check-isolation
chmod +x /tmp/bin/check-isolation

PATH="/usr/local/bin:${PATH}" check-isolation
PATH="/tmp/bin:${PATH}" check-isolation
### expect
visible=yes
hidden=unset
Expand Down
18 changes: 10 additions & 8 deletions scripts/update-spec-expected.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,24 @@ done

cd "$ROOT_DIR"

if ! command -v bc >/dev/null; then
echo "Strict Bash parity requires GNU bc on PATH." >&2
exit 1
fi

echo "Checking spec tests against real bash..."
echo ""

test_args=(--test integration -- spec_tests:: --ignored)
if $VERBOSE; then
cargo test --test integration -- spec_tests:: --ignored --nocapture 2>&1
else
cargo test --test integration -- spec_tests:: --ignored 2>&1
test_args+=(--nocapture)
fi

exit_code=$?

if [[ $exit_code -eq 0 ]]; then
if cargo test "${test_args[@]}" 2>&1; then
echo ""
echo "All non-excluded tests match real bash."
else
exit_code=$?
echo ""
echo "Some tests have differences from real bash."
echo ""
Expand All @@ -81,6 +84,5 @@ else
echo " 2. Add '### bash_diff: reason' if the difference is intentional"
echo ""
echo "Run with --verbose to see all comparisons."
exit "$exit_code"
fi

exit $exit_code
Loading