Reworked the test suite so I can create tests for the stdlib.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 26 Jul 2019 11:24:15 +0000 (04:24 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 26 Jul 2019 11:24:15 +0000 (04:24 -0700)
Makefile
stdlib_tests/0001_hello_world.pvvs [new file with mode: 0644]
stdlib_tests/Makefile [new file with mode: 0644]
stdlib_tests/README.md [new file with mode: 0644]
stdlib_tests/vv_test.py [new file with mode: 0755]
tests/Makefile [new file with mode: 0644]
tests/vv_test.py [new file with mode: 0755]
vv_test.py [deleted file]

index 1412ac5..d07a47c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,9 +18,17 @@ 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
+
+test: testvvi teststdlib
+
+testvvi: all
+       @cd tests; make test
+
+teststdlib: all
+       @cd stdlib_tests; make test
+
+testclean:
+       @cd tests; make clean
+       @cd stdlib_tests; make clean
diff --git a/stdlib_tests/0001_hello_world.pvvs b/stdlib_tests/0001_hello_world.pvvs
new file mode 100644 (file)
index 0000000..49a6c46
--- /dev/null
@@ -0,0 +1,6 @@
+A"Hello, world!\n"
+SSSSN           | PUSH 0
+NSTTSSSN        | JSR > 1000 (printf)
+NNN             | DIE
+
+#include <stdio.pvvs>
diff --git a/stdlib_tests/Makefile b/stdlib_tests/Makefile
new file mode 100644 (file)
index 0000000..b55caaa
--- /dev/null
@@ -0,0 +1,11 @@
+# (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
+# All rights reserved.
+
+all: test
+
+test:
+       @echo "Testing stdlib:"
+       @./vv_test.py
+
+clean:
+       @rm -f ./test.vvs ./test.pvvs
diff --git a/stdlib_tests/README.md b/stdlib_tests/README.md
new file mode 100644 (file)
index 0000000..8a4ec3d
--- /dev/null
@@ -0,0 +1 @@
+This folder contains tests for the VVS stdlib that are called from `vv_test.py`.
diff --git a/stdlib_tests/vv_test.py b/stdlib_tests/vv_test.py
new file mode 100755 (executable)
index 0000000..c1c2006
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/local/bin/python3.6
+
+# (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
+# All rights reserved.
+
+# Quick and dirty tests for the VVhitespace stdlib.
+
+import os, subprocess
+
+preprocessor = 'cpp'
+include_path = '-I../stdlib'
+cpp_temp_file = 'test.pvvs'
+compiler_path = '../vvc'
+interpreter_path = '../vvi'
+temp_file = './test.vvs'
+path_to_tests = './'
+src_extension = '.pvvs'
+
+tests = [
+        # Format: ['filename_without_extension', 'string for stdin', 'string for expected stdout']
+        ['0001_hello_world', '', 'Hello, world!\n'],
+        ] 
+
+for test in tests:
+    subprocess.run([preprocessor, include_path, "-o", cpp_temp_file, path_to_tests + test[0] + src_extension])
+    subprocess.run([compiler_path, '-i', cpp_temp_file, '-o', temp_file])
+    result = subprocess.run([interpreter_path, '-i', temp_file], stdout=subprocess.PIPE, input=test[1].encode('utf-8'))
+    if result.stdout.decode('utf-8') != test[2]:
+        print('\n' + test[0])
+    else:
+        print('.', end='', flush=True)
+    os.remove(temp_file)
+
+print("")
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644 (file)
index 0000000..1660851
--- /dev/null
@@ -0,0 +1,11 @@
+# (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
+# All rights reserved.
+
+all: test
+
+test:
+       @echo "Testing vvi:"
+       @./vv_test.py
+
+clean:
+       @rm -f ./test.vvs
diff --git a/tests/vv_test.py b/tests/vv_test.py
new file mode 100755 (executable)
index 0000000..9345239
--- /dev/null
@@ -0,0 +1,51 @@
+#!/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 = './'
+src_extension = '.pvvs'
+
+tests = [
+        # Format: ['filename_without_extension', 'string for stdin', 'string for expected stdout']
+        ['0001_push_printchar_exit', '', 'A'],
+        ['1001_stack_push', '', 'A'],
+        ['1002_stack_dup', '', 'AA'],
+        ['1003_stack_swap', '', 'AB'],
+        ['1004_stack_drop', '', 'A'],
+        ['2001_arithmetic_addition', '', 'B'],
+        ['2002_arithmetic_subtraction', '', 'A'],
+        ['2003_arithmetic_multiplication', '', 'B'],
+        ['2004_arithmetic_division', '', 'A'],
+        ['2005_arithmetic_remainder', '', 'A'],
+        ['3001_heap', '', 'BCA'],
+        ['4001_flowcontrol_exit', '', ''],
+        ['4002_flowcontrol_unconditional_jump_to_label', '', 'A'],
+        ['4003_flowcontrol_jump_if_tos_is_zero', '', 'A'],
+        ['4004_flowcontrol_jump_if_tos_is_negative', '', 'A'],
+        ['4005_flowcontrol_jump_to_subroutine', '', 'A'],
+        ['4006_flowcontrol_return_from_subroutine', '', 'A'],
+        ['4100_flowcontrol_branches_not_taken', '', 'A'],
+        ['5001_io_output_character', '', 'A'],
+        ['5002_io_output_digit', '', '2'],
+        ['5003_io_input_character', 'A', 'A'],
+        ['5004_io_input_digit', '1', '1'],
+        ] 
+
+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, input=test[1].encode('utf-8'))
+    if result.stdout.decode('utf-8') != test[2]:
+        print('\n' + test[0])
+    else:
+        print('.', end='', flush=True)
+    os.remove(temp_file)
+
+print("")
diff --git a/vv_test.py b/vv_test.py
deleted file mode 100755 (executable)
index a2779ab..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/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 = [
-        # Format: ['filename_without_extension', 'string for stdin', 'string for expected stdout']
-        ['0001_push_printchar_exit', '', 'A'],
-        ['1001_stack_push', '', 'A'],
-        ['1002_stack_dup', '', 'AA'],
-        ['1003_stack_swap', '', 'AB'],
-        ['1004_stack_drop', '', 'A'],
-        ['2001_arithmetic_addition', '', 'B'],
-        ['2002_arithmetic_subtraction', '', 'A'],
-        ['2003_arithmetic_multiplication', '', 'B'],
-        ['2004_arithmetic_division', '', 'A'],
-        ['2005_arithmetic_remainder', '', 'A'],
-        ['3001_heap', '', 'BCA'],
-        ['4001_flowcontrol_exit', '', ''],
-        ['4002_flowcontrol_unconditional_jump_to_label', '', 'A'],
-        ['4003_flowcontrol_jump_if_tos_is_zero', '', 'A'],
-        ['4004_flowcontrol_jump_if_tos_is_negative', '', 'A'],
-        ['4005_flowcontrol_jump_to_subroutine', '', 'A'],
-        ['4006_flowcontrol_return_from_subroutine', '', 'A'],
-        ['4100_flowcontrol_branches_not_taken', '', 'A'],
-        ['5001_io_output_character', '', 'A'],
-        ['5002_io_output_digit', '', '2'],
-        ['5003_io_input_character', 'A', 'A'],
-        ['5004_io_input_digit', '1', '1'],
-        ] 
-
-for test in tests:
-    # TODO: Catch stderr
-    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, input=test[1].encode('utf-8'))
-    if result.stdout.decode('utf-8') != test[2]:
-        print('\n' + test[0])
-    else:
-        print('.', end='', flush=True)
-    os.remove(temp_file)
-
-print("")