tests: Test *ARGV* is set correctly in step 6
authorDov Murik <dov.murik@gmail.com>
Tue, 10 May 2016 19:28:29 +0000 (15:28 -0400)
committerDov Murik <dov.murik@gmail.com>
Wed, 11 May 2016 15:31:04 +0000 (11:31 -0400)
Add new mini test harness run_argv_test.sh to run the Mal interpreter
with different command-line arguments and test the stdout of that
process.

The main Makefile will automatically run the new harness whenever step 6
is tested (either directly or during REGRESS=1 of a more advanced step).

Makefile
docs/TODO
run_argv_test.sh [new file with mode: 0755]
tests/print_argv.mal [new file with mode: 0644]

index 60fc212..3a326e1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -337,7 +337,13 @@ $(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(s
              echo '----------------------------------------------' && \
              echo 'Testing $@, step file: $+, test file: $(test)' && \
              echo 'Running: $(call get_run_prefix,$(impl))../runtest.py $(TEST_OPTS) $(opt_DEFERRABLE) $(opt_OPTIONAL) $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+))' && \
-             $(call get_run_prefix,$(impl))../runtest.py $(TEST_OPTS) $(opt_DEFERRABLE) $(opt_OPTIONAL) $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+)) &&) \
+             $(call get_run_prefix,$(impl))../runtest.py $(TEST_OPTS) $(opt_DEFERRABLE) $(opt_OPTIONAL) $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+)) && \
+             $(if $(filter tests/step6_file.mal,$(test)),\
+               echo '----------------------------------------------' && \
+               echo 'Testing ARGV of $@; step file: $+' && \
+               echo 'Running: $(call get_run_prefix,$(impl))../run_argv_test.sh $(call $(impl)_RUNSTEP,$(step),$(+))' && \
+               $(call get_run_prefix,$(impl))../run_argv_test.sh $(call $(impl)_RUNSTEP,$(step),$(+)) && ,\
+               true && ))\
            true))
 
 # Allow test, tests, test^STEP, test^IMPL, and test^IMPL^STEP
index 5e9ee6f..63df3d1 100644 (file)
--- a/docs/TODO
+++ b/docs/TODO
@@ -9,7 +9,6 @@ General:
     - Finish guide.md
 
 All Implementations:
-    - test that *ARGV* gets set properly
     - regular expression matching in runtest
     - add re (use in rep) everywhere and use that (to avoid printing)
     - per impl tests for step5_tco, or at least a better way of
diff --git a/run_argv_test.sh b/run_argv_test.sh
new file mode 100755 (executable)
index 0000000..fbbe4bc
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+#
+# Usage: run_argv_test.sh <command line arguments to run mal>
+#
+# Example: run_argv_test.sh python step6_file.py
+#
+
+assert_equal() {
+  if [ "$1" = "$2" ] ; then
+    echo "OK: '$1'"
+  else
+    echo "FAIL: Expected '$1' but got '$2'"
+    echo
+    exit 1
+  fi
+}
+
+if [ -z "$1" ] ; then
+  echo "Usage: $0 <command line arguments to run mal>"
+  exit 1
+fi
+
+root="$(dirname $0)"
+
+out="$( $@ $root/tests/print_argv.mal aaa bbb ccc )"
+assert_equal '("aaa" "bbb" "ccc")' "$out"
+
+out="$( $@ $root/tests/print_argv.mal aaa 'bbb ccc' ddd )"
+assert_equal '("aaa" "bbb ccc" "ddd")' "$out"
+
+out="$( $@ $root/tests/print_argv.mal )"
+assert_equal '()' "$out"
+
+echo 'Passed all *ARGV* tests'
+echo
diff --git a/tests/print_argv.mal b/tests/print_argv.mal
new file mode 100644 (file)
index 0000000..7c28dfb
--- /dev/null
@@ -0,0 +1,2 @@
+; Used by the run_argv_test.sh test harness
+(prn *ARGV*)