-This folder contains tests for `vvi` that are called from `vv_test.py`.
+# Overview #
+
+This folder contains tests for the VVhitespace interpreter (`vvi`).
+
+# Instructions #
+
+Edit the shebang in `vv_test.py` to match your environment. For example:
+
+ FreeBSD 12: #!/usr/local/bin/python3.6
+ Debian 9 : #!/usr/bin/python3
+
+Build `vvc` and `vvi` in the source tree, if you haven't already.
+
+ vvs-repo/tests % cd .. && make clean all && cd tests
+
+Alternatively, edit the configuration block in `vv_test.py` to provide
+appropriate paths relative to this `tests` folder.
+
+ compiler_path = '../vvc'
+ interpreter_path = '../vvi'
+
+With configuration now complete, execute the tests via `make test`. A dot will
+appear for every successfully completed test. For example:
+
+ vvs-repo/tests % make test
+ Testing vvi:
+ .......................
+ vvs-repo/tests %
+
+If a test should fail, the name of the test will be printed in place of its
+dot. For example, with an induced failure in the division command:
+
+ vvs-repo/tests % make test
+ Testing vvi:
+ ........
+ 2004_arithmetic_division
+ Expected: A
+ Received: A113
+ ..............
+ vvs-repo/tests %
+
+If testing is aborted prematurely, say by a Ctrl-C initiated SIGINT, use `make
+clean` to remove any temporary files.
#!/usr/local/bin/python3.6
# (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
-# All rights reserved.
+# See LICENSE.txt file for copyright and license details.
# Quick and dirty tests for the VVhitespace interpreter.
+# Invoke directly or see README.md in this folder for more details.
-import os, subprocess
-
+# Configuration Options
+# All paths are relative to the PWD environment variable of the invoked script.
compiler_path = '../vvc'
interpreter_path = '../vvi'
temp_file = './test.vvs'
path_to_tests = './'
src_extension = '.pvvs'
+# List of tests to perform.
+# Tests should be ordered such that later tests rely exclusively on previously tested commands.
+# Test Entry Format: ['filename_without_extension', 'string for stdin', 'string for expected stdout']
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'],
['6001_push_intmin', '', '1'],
]
+# ------------------------------------------------------------------------------
+
+import os, subprocess
+
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])
+ print('\tExpected: ' + test[2])
+ print('\tReceived: ' + result.stdout.decode('utf-8'))
else:
print('.', end='', flush=True)
os.remove(temp_file)