diff --git a/.gitignore b/.gitignore index e43b0f9..8687e41 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .DS_Store + +# build artifacts from `make build` +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..75144fb --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +# distribution — build/test gate. +# +# The sx compiler lives in a separate repo; locate it via SX (overridable): +# make build SX=/path/to/sx +SX ?= /Users/agra/projects/sx/zig-out/bin/sx + +BUILD_DIR := build + +# Programs compiled by `make build`. Currently just the smoke program; +# product entry points under src/ get added here as they land (P1.2+). +SMOKE := tests/smoke.sx + +.PHONY: build test publish-example clean + +# Compile the smoke program (and, later, product sources) without running. +build: + @mkdir -p $(BUILD_DIR) + $(SX) build -o $(BUILD_DIR)/smoke $(SMOKE) + +# Run the test runner over every tests/**/*.sx. Exits non-zero on any failure. +test: + @SX="$(SX)" ./tests/run.sh + +# Placeholder for the end-to-end publish flow — becomes real in P3.4. +publish-example: + @echo "publish-example: not implemented yet (becomes real in P3.4)" + +clean: + @rm -rf $(BUILD_DIR) diff --git a/examples/.gitkeep b/examples/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/.gitkeep b/src/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/infra/.gitkeep b/src/infra/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 0000000..dabb2de --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# Test runner — discovers every tests/**/*.sx, runs each via `$SX run`, and +# reports per-test ok/FAIL. Exits 0 only when every test passes. +# +# A test passes iff `$SX run ` exits 0 (compile failures count as a +# failure too). Each test program asserts its own invariants — e.g. via +# process.assert — and exits non-zero on failure. +# +# Locate the compiler via SX (overridable); defaults to the sibling sx repo. +set -u + +SX="${SX:-/Users/agra/projects/sx/zig-out/bin/sx}" +TESTS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) + +pass=0 +fail=0 + +# Test filenames follow the no-spaces convention, so word-splitting the +# sorted find output is safe and keeps the loop in the current shell (so the +# pass/fail counters survive). +for t in $(find "$TESTS_DIR" -name '*.sx' -type f | sort); do + name=${t#"$TESTS_DIR"/} + if "$SX" run "$t" >/dev/null 2>&1; then + printf ' %-44s ok\n' "$name" + pass=$((pass + 1)) + else + printf ' %-44s FAIL\n' "$name" + fail=$((fail + 1)) + fi +done + +total=$((pass + fail)) +if [ "$total" -eq 0 ]; then + echo "no tests found under $TESTS_DIR" >&2 + exit 1 +fi + +echo "------------------------------------------------" +printf 'tests: %d pass: %d fail: %d\n' "$total" "$pass" "$fail" + +[ "$fail" -eq 0 ] diff --git a/tests/smoke.sx b/tests/smoke.sx new file mode 100644 index 0000000..9b4d4b5 --- /dev/null +++ b/tests/smoke.sx @@ -0,0 +1,9 @@ +// Smoke test: proves the sx toolchain is wired end-to-end from this repo — +// the standard library import resolves, the program runs, and it exits 0. +// The runner (tests/run.sh) treats a clean exit as `ok`. +#import "modules/std.sx"; + +main :: () -> s32 { + print("distribution smoke test: toolchain ok\n"); + return 0; +}