Commit | Line | Data |
---|---|---|
6e942bd8 AT |
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 = [ | |
a2664738 AT |
17 | # Format: ['filename_without_extension', 'string for stdin', 'string for expected stdout'] |
18 | ['0001_push_printchar_exit', '', 'A'], | |
19 | ['1001_stack_push', '', 'A'], | |
20 | ['1002_stack_dup', '', 'AA'], | |
21 | ['1003_stack_swap', '', 'AB'], | |
22 | ['1004_stack_drop', '', 'A'], | |
23 | ['2001_arithmetic_addition', '', 'B'], | |
24 | ['2002_arithmetic_subtraction', '', 'A'], | |
25 | ['2003_arithmetic_multiplication', '', 'B'], | |
26 | ['2004_arithmetic_division', '', 'A'], | |
27 | ['2005_arithmetic_remainder', '', 'A'], | |
28 | ['3001_heap', '', 'BCA'], | |
29 | ['4001_flowcontrol_exit', '', ''], | |
30 | ['4002_flowcontrol_unconditional_jump_to_label', '', 'A'], | |
31 | ['4003_flowcontrol_jump_if_tos_is_zero', '', 'A'], | |
32 | ['4004_flowcontrol_jump_if_tos_is_negative', '', 'A'], | |
33 | ['4005_flowcontrol_jump_to_subroutine', '', 'A'], | |
34 | ['4006_flowcontrol_return_from_subroutine', '', 'A'], | |
84c650ed | 35 | ['4100_flowcontrol_branches_not_taken', '', 'A'], |
a2664738 AT |
36 | ['5001_io_output_character', '', 'A'], |
37 | ['5002_io_output_digit', '', '2'], | |
38 | ['5003_io_input_character', 'A', 'A'], | |
39 | ['5004_io_input_digit', '1', '1'], | |
6e942bd8 AT |
40 | ] |
41 | ||
42 | for test in tests: | |
665e21b4 | 43 | # TODO: Catch stderr |
6e942bd8 | 44 | subprocess.run([compiler_path, '-i', path_to_tests + test[0] + src_extension, '-o', temp_file]) |
a2664738 AT |
45 | result = subprocess.run([interpreter_path, '-i', temp_file], stdout=subprocess.PIPE, input=test[1].encode('utf-8')) |
46 | if result.stdout.decode('utf-8') != test[2]: | |
665e21b4 | 47 | print('\n' + test[0]) |
6e942bd8 | 48 | else: |
665e21b4 | 49 | print('.', end='', flush=True) |
6e942bd8 AT |
50 | os.remove(temp_file) |
51 | ||
52 | print("") |