diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-05-03 13:52:49 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-05-03 13:52:49 +0900 |
| commit | 1c44079167dbac07e71e177b3ef125755c4308fc (patch) | |
| tree | a5d087b1bbcbca2aedf139e0e4cb4ae58df498a0 /tests | |
| parent | 4be0e6ed059827a22f5ad6e5c84f5ed306b94372 (diff) | |
| download | P4Dcc-1c44079167dbac07e71e177b3ef125755c4308fc.tar.gz P4Dcc-1c44079167dbac07e71e177b3ef125755c4308fc.tar.zst P4Dcc-1c44079167dbac07e71e177b3ef125755c4308fc.zip | |
refactor tests
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/001.sh | 18 | ||||
| -rw-r--r-- | tests/002.sh | 18 | ||||
| -rw-r--r-- | tests/003.sh | 18 | ||||
| -rw-r--r-- | tests/test_exit_code.sh | 17 |
4 files changed, 20 insertions, 51 deletions
diff --git a/tests/001.sh b/tests/001.sh index a81f2c3..00e0aca 100644 --- a/tests/001.sh +++ b/tests/001.sh @@ -1,21 +1,5 @@ -cat <<'EOF' > main.c +bash ../../test_exit_code.sh 42 <<'EOF' int main() { return 42; } EOF - -"$p4dcc" < main.c > main.s -if [[ $? -ne 0 ]]; then - cat main.s >&2 - exit 1 -fi -gcc -Wl,-z,noexecstack -o a.out main.s -./a.out -exit_code=$? - -expected=42 - -if [[ ! $exit_code -eq $expected ]]; then - echo "expected $expected, but $exit_code" >&2 - exit 1 -fi diff --git a/tests/002.sh b/tests/002.sh index 9dbbb21..ee54213 100644 --- a/tests/002.sh +++ b/tests/002.sh @@ -1,21 +1,5 @@ -cat <<'EOF' > main.c +bash ../../test_exit_code.sh 21 <<'EOF' int main() { return 5+20-4; } EOF - -"$p4dcc" < main.c > main.s -if [[ $? -ne 0 ]]; then - cat main.s >&2 - exit 1 -fi -gcc -Wl,-z,noexecstack -o a.out main.s -./a.out -exit_code=$? - -expected=21 - -if [[ ! $exit_code -eq $expected ]]; then - echo "expected $expected, but $exit_code" >&2 - exit 1 -fi diff --git a/tests/003.sh b/tests/003.sh index 77a3886..4fa0b42 100644 --- a/tests/003.sh +++ b/tests/003.sh @@ -1,21 +1,5 @@ -cat <<'EOF' > main.c +bash ../../test_exit_code.sh 26 <<'EOF' int main() { return 2*3+4*5; } EOF - -"$p4dcc" < main.c > main.s -if [[ $? -ne 0 ]]; then - cat main.s >&2 - exit 1 -fi -gcc -Wl,-z,noexecstack -o a.out main.s -./a.out -exit_code=$? - -expected=26 - -if [[ ! $exit_code -eq $expected ]]; then - echo "expected $expected, but $exit_code" >&2 - exit 1 -fi diff --git a/tests/test_exit_code.sh b/tests/test_exit_code.sh new file mode 100644 index 0000000..f69e862 --- /dev/null +++ b/tests/test_exit_code.sh @@ -0,0 +1,17 @@ +cat > main.c + +"$p4dcc" < main.c > main.s +if [[ $? -ne 0 ]]; then + cat main.s >&2 + exit 1 +fi +gcc -Wl,-z,noexecstack -o a.out main.s +./a.out +exit_code=$? + +expected=$1 + +if [[ ! $exit_code -eq $expected ]]; then + echo "expected $expected, but $exit_code" >&2 + exit 1 +fi |
