Commit | Line | Data |
---|---|---|
a805b721 AT |
1 | #!/usr/local/bin/python3.6 |
2 | ||
3 | # (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com> | |
aa1914c3 | 4 | # See LICENSE.txt file for copyright and license details. |
a805b721 AT |
5 | |
6 | # Quick and dirty tests for the VVhitespace stdlib. | |
aa1914c3 | 7 | # Invoke directly or see README.md in this folder for more details. |
a805b721 | 8 | |
aa1914c3 AT |
9 | # Configuration Options |
10 | # All paths are relative to the PWD environment variable of the invoked script. | |
a805b721 AT |
11 | preprocessor = 'cpp' |
12 | include_path = '-I../stdlib' | |
13 | cpp_temp_file = 'test.pvvs' | |
14 | compiler_path = '../vvc' | |
15 | interpreter_path = '../vvi' | |
16 | temp_file = './test.vvs' | |
17 | path_to_tests = './' | |
18 | src_extension = '.pvvs' | |
19 | ||
aa1914c3 AT |
20 | # List of tests to perform. |
21 | # Tests should be ordered such that later tests rely exclusively on previously tested commands. | |
22 | # Format: ['filename_without_extension', 'string for stdin', 'string for expected stdout'] | |
a805b721 | 23 | tests = [ |
63a60fe0 | 24 | ['0001_dumpstack', '', 'TOS:\n2:\t+42\n1:\t+255\n'], |
aa1914c3 AT |
25 | ['0002_stdlib_version', '', 'TOS:\n1:\t+1\n'], |
26 | ['0003_dumpheap', '', '32:\t+255\n33:\t+42\n'], | |
63a60fe0 AT |
27 | ['1001_stackrotate', '', 'TOS:\n14:\t+1\n13:\t+244\n12:\t+1\n11:\t+1\n10:\t+1\n9:\t+1\n8:\t+1\n7:\t+243\n6:\t+1\n5:\t+1\n4:\t+1\n3:\t+1\n2:\t+1\n1:\t+242\n'], |
28 | ['1002_stackrotatereverse', '', 'TOS:\n14:\t+1\n13:\t+244\n12:\t+1\n11:\t+1\n10:\t+1\n9:\t+1\n8:\t+1\n7:\t+1\n6:\t+1\n5:\t+1\n4:\t+1\n3:\t+1\n2:\t+1\n1:\t+1\n'], | |
29 | ['1003_deepdup', '', 'TOS:\n15:\t+1\n14:\t+244\n13:\t+1\n12:\t+1\n11:\t+1\n10:\t+1\n9:\t+1\n8:\t+1\n7:\t+1\n6:\t+1\n5:\t+1\n4:\t+1\n3:\t+1\n2:\t+1\n1:\t+244\n'], | |
ec58aa1c AT |
30 | ['2001_spew', '', '32:\t+242\n33:\t+243\n34:\t+244\n'], |
31 | ['2002_slurp', '', 'TOS:\n3:\t+242\n2:\t+243\n1:\t+244\n'], | |
24a242ac AT |
32 | ['2003_memset', '', '32:\t+42\n33:\t+42\n'], |
33 | ['2004_memcpy', '', '34:\t+42\n35:\t+42\n'], | |
eabd8f3e | 34 | ['2005_memcmp', '', '+1'], |
096fa8e2 | 35 | ['2006_memsrch', '', '+32'], |
60d04456 | 36 | ['2007_memrand', '', ''], |
24e4f91b | 37 | ['3001_not', '', '-1+0-6148914691236517206+6148914691236517205'], |
fe5f81e6 | 38 | ['3002_lshift', '', '+1+2+4611686018427387904-9223372036854775808-9223372036854775808+0'], |
8b4ce1c2 | 39 | ['3003_rshift', '', '+1+1+1-4611686018427387903-576460752303423478-1-1'], |
36c8fa87 | 40 | ['3004_and', '', '+0+0+1+1+42'], |
8fcdc866 | 41 | ['3005_or', '', '+0+1+1-1-1'], |
08402297 | 42 | ['3006_xor', '', '+0+1+0-2-1'], |
9c88539c | 43 | ['4001_strlen', '', '+11'], |
0e0d0a4a | 44 | ['4002_isdigit', '', '+0+1+1+0'], |
fada5085 | 45 | ['4003_get_user_string', 'aas\nasdf', '+0a+1as\n+2asd+3'], |
7359501c AT |
46 | ['5001_abs', '', '+1+1+0+0'], |
47 | ['5002_random', '', ''], | |
37372ed0 | 48 | ['5003_gcd', '', '+0+4+4+3+3+3'], |
d5a0b337 | 49 | ['5004_fastrand', '', ''], |
08a3a286 AT |
50 | ['6001_printstackstring', '', 'test'], |
51 | ['6002_printheapstring', '', 'test'], | |
52 | ['6003_printnumbersign', '', '+-'], | |
53 | ['6004_printnumbermagnitude', '', '323209223372036854775808'], | |
54 | ['6005_printstacknumber', '', '+32-32+0-9223372036854775808'], | |
55 | ['6006_printf_staticstackstring', '', 'test'], | |
56 | ['6007_printf_staticheapstring', '', 'test'], | |
57 | ['6008_printf_escapedstackstring', '', '\\%\t\n'], | |
58 | ['6009_printf_substitutedstackstring', '', 'Atest142+42'], | |
b6bea2cf | 59 | ['7001_atoi', '', '+42+42-42+0+0+0'], |
a805b721 AT |
60 | ] |
61 | ||
aa1914c3 AT |
62 | # ------------------------------------------------------------------------------ |
63 | ||
64 | import os, subprocess | |
65 | ||
a805b721 AT |
66 | for test in tests: |
67 | subprocess.run([preprocessor, include_path, "-o", cpp_temp_file, path_to_tests + test[0] + src_extension]) | |
68 | subprocess.run([compiler_path, '-i', cpp_temp_file, '-o', temp_file]) | |
69 | result = subprocess.run([interpreter_path, '-i', temp_file], stdout=subprocess.PIPE, input=test[1].encode('utf-8')) | |
70 | if result.stdout.decode('utf-8') != test[2]: | |
71 | print('\n' + test[0]) | |
aa1914c3 AT |
72 | print('\tExpected: ' + test[2]) |
73 | print('\tReceived: ' + result.stdout.decode('utf-8')) | |
a805b721 AT |
74 | else: |
75 | print('.', end='', flush=True) | |
9f7f68e5 | 76 | os.remove(cpp_temp_file) |
a805b721 AT |
77 | os.remove(temp_file) |
78 | ||
79 | print("") |