diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | justfile | 13 | ||||
| -rw-r--r-- | tests/001.sh | 14 | ||||
| -rw-r--r-- | tests/all.sh | 16 | ||||
| -rw-r--r-- | tests/run.sh | 18 |
5 files changed, 61 insertions, 3 deletions
@@ -1 +1,2 @@ -/a.out +/p4dcc +/tests/tmp @@ -3,7 +3,16 @@ CFLAGS := "-Wno-builtin-declaration-mismatch" all: build build: - gcc main.c {{CFLAGS}} + gcc -o p4dcc main.c {{CFLAGS}} + +test TESTCASE="all": build + #!/usr/bin/env bash + if [[ {{TESTCASE}} = all ]]; then + bash tests/all.sh + else + bash tests/run.sh {{TESTCASE}} + fi clean: - rm a.out + rm p4dcc + rm -rf tests/tmp diff --git a/tests/001.sh b/tests/001.sh new file mode 100644 index 0000000..9245cf6 --- /dev/null +++ b/tests/001.sh @@ -0,0 +1,14 @@ +cat <<'EOF' > main.c +int main() { + return 42; +} +EOF + +"$p4dcc" < main.c > main.s +gcc -o a.out main.s +set +e +./a.out +exit_code=$? +set -e + +test $exit_code -eq 42 diff --git a/tests/all.sh b/tests/all.sh new file mode 100644 index 0000000..4ff3688 --- /dev/null +++ b/tests/all.sh @@ -0,0 +1,16 @@ +set -e + +export p4dcc="../../../p4dcc" + +rm -rf tests/tmp +mkdir -p tests/tmp +for i in $(seq 1 999); do + testcase=$(printf '%03d' $i) + test_file="tests/$testcase.sh" + if [[ -f "$test_file" ]]; then + bash tests/run.sh "$testcase" + else + echo "All tests passed." + exit + fi +done diff --git a/tests/run.sh b/tests/run.sh new file mode 100644 index 0000000..d92cc29 --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,18 @@ +set -e + +export p4dcc="../../../p4dcc" + +export testcase=$1 +export tmp_dir="tests/tmp/$testcase" + +test_file="tests/$testcase.sh" + +if [[ ! -f "$test_file" ]]; then + echo "no test $testcase" >&2 + exit 1 +fi + +echo "$test_file" +mkdir -p "$tmp_dir" +cd "$tmp_dir" +bash "../../../$test_file" |
