From 6e942bd8524e9393f61a0358a0282b2641f9d3d7 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Thu, 4 Jul 2019 14:02:38 -0700 Subject: [PATCH] Added basic test system for VVhitespace interpreter. --- Makefile | 4 ++++ tests/0001_push_printchar_exit.pvvs | 7 +++++++ tests/1001_stack_operations.pvvs | 10 ++++++++++ vv_compiler.c | 2 -- vv_interpreter.c | 2 -- vv_test.py | 30 +++++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 tests/0001_push_printchar_exit.pvvs create mode 100644 tests/1001_stack_operations.pvvs create mode 100755 vv_test.py diff --git a/Makefile b/Makefile index 5ff4f11..6759c97 100644 --- a/Makefile +++ b/Makefile @@ -18,5 +18,9 @@ vvi: 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 diff --git a/tests/0001_push_printchar_exit.pvvs b/tests/0001_push_printchar_exit.pvvs new file mode 100644 index 0000000..9e1a327 --- /dev/null +++ b/tests/0001_push_printchar_exit.pvvs @@ -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 index 0000000..d8333e4 --- /dev/null +++ b/tests/1001_stack_operations.pvvs @@ -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 diff --git a/vv_compiler.c b/vv_compiler.c index 3153eee..7ab1e06 100644 --- a/vv_compiler.c +++ b/vv_compiler.c @@ -108,7 +108,5 @@ main(int argc, char ** argv) fclose(input); fclose(output); - printf("Successfully converted source code.\n"); - exit(EXIT_SUCCESS); } diff --git a/vv_interpreter.c b/vv_interpreter.c index 39210f1..8d4db24 100644 --- a/vv_interpreter.c +++ b/vv_interpreter.c @@ -49,7 +49,6 @@ stdin_empty(void) void ws_die(size_t * pc, char * msg) { - printf("\n"); 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. */ - printf("\n"); fflush(stdout); exit(EXIT_SUCCESS); case ' ': diff --git a/vv_test.py b/vv_test.py new file mode 100755 index 0000000..46f5bc9 --- /dev/null +++ b/vv_test.py @@ -0,0 +1,30 @@ +#!/usr/local/bin/python3.6 + +# (c) 2019 Aaron Taylor +# 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("") -- 2.20.1