aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/helpers.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/helpers.sh')
-rw-r--r--tests/helpers.sh68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/helpers.sh b/tests/helpers.sh
new file mode 100644
index 0000000..eaccd5c
--- /dev/null
+++ b/tests/helpers.sh
@@ -0,0 +1,68 @@
+function test_exit_code() {
+ cat > main.c
+
+ "$ducc" -o a.out main.c
+ set +e
+ ./a.out
+ exit_code=$?
+ set -e
+
+ expected=$1
+
+ if [[ $exit_code -ne $expected ]]; then
+ echo "invalid exit code: expected $expected, but got $exit_code" >&2
+ exit 1
+ fi
+}
+
+function test_diff() {
+ cat > main.c
+
+ "$ducc" -o a.out main.c
+ if [[ ! -f input ]]; then
+ touch input
+ fi
+ ./a.out "$@" < input > output
+ exit_code=$?
+
+ if [[ $exit_code -ne 0 ]]; then
+ echo "invalid exit code: $exit_code" >&2
+ exit 1
+ fi
+
+ diff -u expected output
+}
+
+function test_compile_error() {
+ cat > main.c
+
+ set +e
+ "$ducc" main.c > /dev/null 2> output
+ exit_code=$?
+ set -e
+
+ if [[ $exit_code -eq 0 ]]; then
+ echo "expected to fail" >&2
+ exit 1
+ fi
+
+ diff -u expected output
+}
+
+function test_example() {
+ filename="../../../examples/$1.c"
+
+ "$ducc" -o a.out "$filename"
+ if [[ ! -f input ]]; then
+ touch input
+ fi
+ ./a.out "$@" < input > output
+ exit_code=$?
+
+ if [[ $exit_code -ne 0 ]]; then
+ echo "invalid exit code: $exit_code" >&2
+ exit 1
+ fi
+
+ diff -u expected output
+}