| 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 stdlib. |
| 7 | |
| 8 | import os, subprocess |
| 9 | |
| 10 | preprocessor = 'cpp' |
| 11 | include_path = '-I../stdlib' |
| 12 | cpp_temp_file = 'test.pvvs' |
| 13 | compiler_path = '../vvc' |
| 14 | interpreter_path = '../vvi' |
| 15 | temp_file = './test.vvs' |
| 16 | path_to_tests = './' |
| 17 | src_extension = '.pvvs' |
| 18 | |
| 19 | tests = [ |
| 20 | # Format: ['filename_without_extension', 'string for stdin', 'string for expected stdout'] |
| 21 | ['0001_dumpstack', '', 'TOS:\n2:\t+42\n1:\t+255\n'], |
| 22 | ['0002_dumpheap', '', '32:\t+255\n33:\t+42\n'], |
| 23 | ['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'], |
| 24 | ['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'], |
| 25 | ['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'], |
| 26 | ['2001_spew', '', '32:\t+242\n33:\t+243\n34:\t+244\n'], |
| 27 | ['2002_slurp', '', 'TOS:\n3:\t+242\n2:\t+243\n1:\t+244\n'], |
| 28 | ['2003_memset', '', '32:\t+42\n33:\t+42\n'], |
| 29 | ['2004_memcpy', '', '34:\t+42\n35:\t+42\n'], |
| 30 | ['2005_memcmp', '', '+1'], |
| 31 | ['2006_memsrch', '', '+32'], |
| 32 | ['2007_memrand', '', ''], |
| 33 | ['3001_not', '', '-1+0-6148914691236517206+6148914691236517205'], |
| 34 | ['3002_lshift', '', '+1+2+4611686018427387904-9223372036854775808-9223372036854775808+0'], |
| 35 | ['3003_rshift', '', '+1+1+1-4611686018427387903-576460752303423478-1-1'], |
| 36 | ['3004_and', '', '+0+0+1+1+42'], |
| 37 | ['3005_or', '', '+0+1+1-1-1'], |
| 38 | ] |
| 39 | |
| 40 | for test in tests: |
| 41 | subprocess.run([preprocessor, include_path, "-o", cpp_temp_file, path_to_tests + test[0] + src_extension]) |
| 42 | subprocess.run([compiler_path, '-i', cpp_temp_file, '-o', temp_file]) |
| 43 | result = subprocess.run([interpreter_path, '-i', temp_file], stdout=subprocess.PIPE, input=test[1].encode('utf-8')) |
| 44 | if result.stdout.decode('utf-8') != test[2]: |
| 45 | print('\n' + test[0]) |
| 46 | else: |
| 47 | print('.', end='', flush=True) |
| 48 | os.remove(cpp_temp_file) |
| 49 | os.remove(temp_file) |
| 50 | |
| 51 | print("") |