| 1 | #!/usr/local/bin/python3.6 |
| 2 | |
| 3 | # (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com> |
| 4 | # All rights reserved. |
| 5 | |
| 6 | # Quick and dirty tests for the VVhitespace interpreter. |
| 7 | |
| 8 | import os, subprocess |
| 9 | |
| 10 | compiler_path = './vvc' |
| 11 | interpreter_path = './vvi' |
| 12 | temp_file = './test.vvs' |
| 13 | path_to_tests = './tests/' |
| 14 | src_extension = '.pvvs' |
| 15 | |
| 16 | tests = [ |
| 17 | ['0001_push_printchar_exit', 'A'], |
| 18 | ['1001_stack_push', 'A'], |
| 19 | ['1002_stack_dup', 'AA'], |
| 20 | ['1003_stack_swap', 'AB'], |
| 21 | ['1004_stack_drop', 'A'], |
| 22 | ['2001_arithmetic_addition', 'B'], |
| 23 | ['2002_arithmetic_subtraction', 'A'], |
| 24 | ['2003_arithmetic_multiplication', 'B'], |
| 25 | ['2004_arithmetic_division', 'A'], |
| 26 | ['2005_arithmetic_remainder', 'A'], |
| 27 | ['3001_heap', 'BCA'], |
| 28 | ['4001_flowcontrol_exit', ''], |
| 29 | ['4002_flowcontrol_unconditional_jump_to_label', 'A'], |
| 30 | ['4003_flowcontrol_jump_if_tos_is_zero', 'A'], |
| 31 | ['4004_flowcontrol_jump_if_tos_is_negative', 'A'], |
| 32 | ['4005_flowcontrol_jump_to_subroutine', 'A'], |
| 33 | ['4006_flowcontrol_return_from_subroutine', 'A'], |
| 34 | ['5001_io_output_character', 'A'], |
| 35 | ['5002_io_output_digit', '2'], |
| 36 | ] |
| 37 | |
| 38 | for test in tests: |
| 39 | # TODO: Catch stderr |
| 40 | subprocess.run([compiler_path, '-i', path_to_tests + test[0] + src_extension, '-o', temp_file]) |
| 41 | result = subprocess.run([interpreter_path, '-i', temp_file], stdout=subprocess.PIPE) |
| 42 | if result.stdout.decode('utf-8') != test[1]: |
| 43 | print('\n' + test[0]) |
| 44 | else: |
| 45 | print('.', end='', flush=True) |
| 46 | os.remove(temp_file) |
| 47 | |
| 48 | print("") |