From a805b721f73268be338edf99ed09f03ac842ef2e Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Fri, 26 Jul 2019 04:24:15 -0700 Subject: [PATCH 1/1] Reworked the test suite so I can create tests for the stdlib. --- Makefile | 16 ++++++++++---- stdlib_tests/0001_hello_world.pvvs | 6 ++++++ stdlib_tests/Makefile | 11 ++++++++++ stdlib_tests/README.md | 1 + stdlib_tests/vv_test.py | 34 ++++++++++++++++++++++++++++++ tests/Makefile | 11 ++++++++++ vv_test.py => tests/vv_test.py | 7 +++--- 7 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 stdlib_tests/0001_hello_world.pvvs create mode 100644 stdlib_tests/Makefile create mode 100644 stdlib_tests/README.md create mode 100755 stdlib_tests/vv_test.py create mode 100644 tests/Makefile rename vv_test.py => tests/vv_test.py (94%) diff --git a/Makefile b/Makefile index 1412ac5..d07a47c 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,17 @@ 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 + +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 index 0000000..49a6c46 --- /dev/null +++ b/stdlib_tests/0001_hello_world.pvvs @@ -0,0 +1,6 @@ +A"Hello, world!\n" +SSSSN | PUSH 0 +NSTTSSSN | JSR > 1000 (printf) +NNN | DIE + +#include diff --git a/stdlib_tests/Makefile b/stdlib_tests/Makefile new file mode 100644 index 0000000..b55caaa --- /dev/null +++ b/stdlib_tests/Makefile @@ -0,0 +1,11 @@ +# (c) 2019 Aaron Taylor +# 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 index 0000000..8a4ec3d --- /dev/null +++ b/stdlib_tests/README.md @@ -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 index 0000000..c1c2006 --- /dev/null +++ b/stdlib_tests/vv_test.py @@ -0,0 +1,34 @@ +#!/usr/local/bin/python3.6 + +# (c) 2019 Aaron Taylor +# 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 index 0000000..1660851 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,11 @@ +# (c) 2019 Aaron Taylor +# All rights reserved. + +all: test + +test: + @echo "Testing vvi:" + @./vv_test.py + +clean: + @rm -f ./test.vvs diff --git a/vv_test.py b/tests/vv_test.py similarity index 94% rename from vv_test.py rename to tests/vv_test.py index a2779ab..9345239 100755 --- a/vv_test.py +++ b/tests/vv_test.py @@ -7,10 +7,10 @@ import os, subprocess -compiler_path = './vvc' -interpreter_path = './vvi' +compiler_path = '../vvc' +interpreter_path = '../vvi' temp_file = './test.vvs' -path_to_tests = './tests/' +path_to_tests = './' src_extension = '.pvvs' tests = [ @@ -40,7 +40,6 @@ tests = [ ] 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]: -- 2.20.1