all repos — xyw @ 5e297f50f8612789fa337ee331e2428641536af2

A minimal virtual machine and assembler for terminals.

Updated test script.
h3rald h3rald@h3rald.com
Mon, 02 Feb 2026 15:56:11 +0100
commit

5e297f50f8612789fa337ee331e2428641536af2

parent

ed455f994f4497b3b389df581489c0bf91ec0b0a

1 files changed, 39 insertions(+), 4 deletions(-)

jump to
M test.shtest.sh

@@ -17,6 +17,14 @@ echo "ERROR: $*" >&2

exit 1 } +dump_file_if_exists() { + local label="$1" + local path="$2" + if [[ -f "$path" ]]; then + (tr -d '\r' <"$path" | cat -v >&2 || true) + fi +} + need_file() { local path="$1" [[ -f "$path" ]] || fail "Missing file: $path"

@@ -30,6 +38,18 @@ echo "WARN: 'make' not found; using existing xyw binary if present." >&2

fi } +clean_examples_images() { + # Only clean generated images in examples/. + # (Keeps repository-wide behavior conservative.) + shopt -s nullglob + local images=("$EXAMPLES_DIR"/*.xim) + shopt -u nullglob + + if ((${#images[@]} > 0)); then + rm -f "${images[@]}" + fi +} + find_xyw_bin() { if [[ -x "$ROOT_DIR/xyw" ]]; then echo "$ROOT_DIR/xyw"

@@ -48,7 +68,15 @@ local src_basename="$2" # e.g. helloworld.xyw

need_file "$EXAMPLES_DIR/$src_basename" - (cd "$EXAMPLES_DIR" && "$xyw_bin" "$src_basename" >/dev/null) + local asm_log="$TMPDIR/assemble.${src_basename%.xyw}.log" + if ! (cd "$EXAMPLES_DIR" && "$xyw_bin" "$src_basename" >"$asm_log" 2>&1); then + dump_file_if_exists "Assembly output" "$asm_log" + fail "Assembly failed for $src_basename" + fi + + # Show assembler output, but keep this function's stdout reserved for the + # produced .xim basename (so callers can capture it). + dump_file_if_exists "Assemble $src_basename" "$asm_log" local img_basename="${src_basename%.xyw}.xim" need_file "$EXAMPLES_DIR/$img_basename"

@@ -62,7 +90,12 @@ local out_file="$3"

need_file "$EXAMPLES_DIR/$img_basename" - (cd "$EXAMPLES_DIR" && "$xyw_bin" "$img_basename" >"$out_file") + local run_log="$TMPDIR/run.${img_basename}.log" + if ! (cd "$EXAMPLES_DIR" && "$xyw_bin" "$img_basename" >"$out_file" 2>"$run_log"); then + dump_file_if_exists "Runtime stderr" "$run_log" + dump_file_if_exists "Runtime stdout" "$out_file" + fail "Execution failed for $img_basename" + fi } normalize_crlf() {

@@ -142,7 +175,7 @@ run_image_capture_stdout "$XYW_BIN" "$img_basename" "$raw_out"

normalize_crlf "$raw_out" "$norm_out" "$assert_fn" "$norm_out" "$@" - echo "PASS: $src_basename" + echo "-> PASS: $src_basename" } ### Main

@@ -152,6 +185,8 @@ need_file "$ROOT_DIR/Makefile"

build_xyw + clean_examples_images + TMPDIR="$(mktemp -d 2>/dev/null || mktemp -d -t xywtest)" trap "rm -rf \"$TMPDIR\"" EXIT

@@ -161,7 +196,7 @@ for tc in "${TEST_CASES[@]}"; do

eval "$tc" done - echo "All tests passed." + echo -e "\n=> All tests passed." } main "$@"