Added basic test system for VVhitespace interpreter.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Thu, 4 Jul 2019 21:02:38 +0000 (14:02 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Thu, 4 Jul 2019 21:02:38 +0000 (14:02 -0700)
Makefile
tests/0001_push_printchar_exit.pvvs [new file with mode: 0644]
tests/1001_stack_operations.pvvs [new file with mode: 0644]
vv_compiler.c
vv_interpreter.c
vv_test.py [new file with mode: 0755]

index 5ff4f11..6759c97 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,5 +18,9 @@ vvi:
 vvc:
        $(CC) $(CC_FLAGS) -o $@ vv_compiler.c
 
 vvc:
        $(CC) $(CC_FLAGS) -o $@ vv_compiler.c
 
+test: all
+       @echo "Starting test suite..."
+       @./vv_test.py
+
 clean:
        @rm -f vvc vvc.core vvi vvi.core
 clean:
        @rm -f vvc vvc.core vvi vvi.core
diff --git a/tests/0001_push_printchar_exit.pvvs b/tests/0001_push_printchar_exit.pvvs
new file mode 100644 (file)
index 0000000..9e1a327
--- /dev/null
@@ -0,0 +1,7 @@
+# This test verifies we can push a number on the stack, print it as a
+# character, and cleanly exit. These three functions form a basis for further
+# tests.
+
+SSSTSSSSSTN     | ST: Push +65 (ASCII A)
+TNSS            | IO: Output character
+NNN             | FC: Terminate program
diff --git a/tests/1001_stack_operations.pvvs b/tests/1001_stack_operations.pvvs
new file mode 100644 (file)
index 0000000..d8333e4
--- /dev/null
@@ -0,0 +1,10 @@
+# This test verifies operations under the Stack IMP ([Space]).
+
+SSSTSSSSSTN     | ST: Push +65 (ASCII A)
+SSSTSSSSTSN     | ST: Push +66 (ASCII B)
+SNS             | ST: Duplicate TOS
+TNSS            | IO: Output character
+SNT             | ST: Swap TOS and NOS
+SNN             | ST: Discard TOS
+TNSS            | IO: Output character
+NNN             | FC: Terminate program
index 3153eee..7ab1e06 100644 (file)
@@ -108,7 +108,5 @@ main(int argc, char ** argv)
     fclose(input);
     fclose(output);
 
     fclose(input);
     fclose(output);
 
-    printf("Successfully converted source code.\n");
-
     exit(EXIT_SUCCESS);
 }
     exit(EXIT_SUCCESS);
 }
index 39210f1..8d4db24 100644 (file)
@@ -49,7 +49,6 @@ stdin_empty(void)
 void
 ws_die(size_t * pc, char * msg)
 {
 void
 ws_die(size_t * pc, char * msg)
 {
-    printf("\n");
     printf("SIM_ERROR @ PC %lu: %s\n", *pc, msg);
     fflush(stdout);
     exit(EXIT_FAILURE);
     printf("SIM_ERROR @ PC %lu: %s\n", *pc, msg);
     fflush(stdout);
     exit(EXIT_FAILURE);
@@ -223,7 +222,6 @@ process_imp_flowcontrol(uint8_t * code, size_t * pc, int32_t ** sp, uint32_t * l
     switch (next_code_byte(code,pc)) {
         case '\n':
             /* Technically another LF is required but we ignore it. */
     switch (next_code_byte(code,pc)) {
         case '\n':
             /* Technically another LF is required but we ignore it. */
-            printf("\n");
             fflush(stdout);
             exit(EXIT_SUCCESS);
         case ' ':
             fflush(stdout);
             exit(EXIT_SUCCESS);
         case ' ':
diff --git a/vv_test.py b/vv_test.py
new file mode 100755 (executable)
index 0000000..46f5bc9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/local/bin/python3.6
+
+# (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
+# All rights reserved.
+
+# Quick and dirty tests for the VVhitespace interpreter.
+
+import os, subprocess
+
+compiler_path = './vvc'
+interpreter_path = './vvi'
+temp_file = './test.vvs'
+path_to_tests = './tests/'
+src_extension = '.pvvs'
+
+tests = [
+        ['0001_push_printchar_exit', 'A'],
+        ['1001_stack_operations', 'BB']
+        ] 
+
+for test in tests:
+    subprocess.run([compiler_path, '-i', path_to_tests + test[0] + src_extension, '-o', temp_file])
+    result = subprocess.run([interpreter_path, '-i', temp_file], stdout=subprocess.PIPE)
+    if result.stdout.decode('utf-8') != test[1]:
+        print(test[0])
+    else:
+        print('.', end='')
+    os.remove(temp_file)
+
+print("")