Commit | Line | Data |
---|---|---|
6e942bd8 AT |
1 | #!/usr/local/bin/python3.6 |
2 | ||
3 | # (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com> | |
0cd0f6f3 | 4 | # See LICENSE.txt file for copyright and license details. |
6e942bd8 AT |
5 | |
6 | # Quick and dirty tests for the VVhitespace interpreter. | |
0cd0f6f3 | 7 | # Invoke directly or see README.md in this folder for more details. |
6e942bd8 | 8 | |
0cd0f6f3 AT |
9 | # Configuration Options |
10 | # All paths are relative to the PWD environment variable of the invoked script. | |
a805b721 AT |
11 | compiler_path = '../vvc' |
12 | interpreter_path = '../vvi' | |
6e942bd8 | 13 | temp_file = './test.vvs' |
a805b721 | 14 | path_to_tests = './' |
6e942bd8 AT |
15 | src_extension = '.pvvs' |
16 | ||
0cd0f6f3 AT |
17 | # List of tests to perform. |
18 | # Tests should be ordered such that later tests rely exclusively on previously tested commands. | |
19 | # Test Entry Format: ['filename_without_extension', 'string for stdin', 'string for expected stdout'] | |
6e942bd8 | 20 | tests = [ |
a2664738 AT |
21 | ['0001_push_printchar_exit', '', 'A'], |
22 | ['1001_stack_push', '', 'A'], | |
23 | ['1002_stack_dup', '', 'AA'], | |
24 | ['1003_stack_swap', '', 'AB'], | |
25 | ['1004_stack_drop', '', 'A'], | |
26 | ['2001_arithmetic_addition', '', 'B'], | |
27 | ['2002_arithmetic_subtraction', '', 'A'], | |
28 | ['2003_arithmetic_multiplication', '', 'B'], | |
29 | ['2004_arithmetic_division', '', 'A'], | |
9e28c156 | 30 | ['2005_arithmetic_remainder', '', 'A113'], |
a2664738 AT |
31 | ['3001_heap', '', 'BCA'], |
32 | ['4001_flowcontrol_exit', '', ''], | |
33 | ['4002_flowcontrol_unconditional_jump_to_label', '', 'A'], | |
34 | ['4003_flowcontrol_jump_if_tos_is_zero', '', 'A'], | |
35 | ['4004_flowcontrol_jump_if_tos_is_negative', '', 'A'], | |
36 | ['4005_flowcontrol_jump_to_subroutine', '', 'A'], | |
37 | ['4006_flowcontrol_return_from_subroutine', '', 'A'], | |
84c650ed | 38 | ['4100_flowcontrol_branches_not_taken', '', 'A'], |
a2664738 AT |
39 | ['5001_io_output_character', '', 'A'], |
40 | ['5002_io_output_digit', '', '2'], | |
41 | ['5003_io_input_character', 'A', 'A'], | |
42 | ['5004_io_input_digit', '1', '1'], | |
6b5e4b38 | 43 | ['6001_push_intmin', '', '1'], |
6e942bd8 AT |
44 | ] |
45 | ||
0cd0f6f3 AT |
46 | # ------------------------------------------------------------------------------ |
47 | ||
48 | import os, subprocess | |
49 | ||
6e942bd8 AT |
50 | for test in tests: |
51 | subprocess.run([compiler_path, '-i', path_to_tests + test[0] + src_extension, '-o', temp_file]) | |
a2664738 AT |
52 | result = subprocess.run([interpreter_path, '-i', temp_file], stdout=subprocess.PIPE, input=test[1].encode('utf-8')) |
53 | if result.stdout.decode('utf-8') != test[2]: | |
665e21b4 | 54 | print('\n' + test[0]) |
0cd0f6f3 AT |
55 | print('\tExpected: ' + test[2]) |
56 | print('\tReceived: ' + result.stdout.decode('utf-8')) | |
6e942bd8 | 57 | else: |
665e21b4 | 58 | print('.', end='', flush=True) |
6e942bd8 AT |
59 | os.remove(temp_file) |
60 | ||
61 | print("") |