Added tests for stdlib stack functions. Fixed some small bugs.
[vvhitespace] / stdlib_tests / vv_test.py
CommitLineData
a805b721
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 stdlib.
7
8import os, subprocess
9
10preprocessor = 'cpp'
11include_path = '-I../stdlib'
12cpp_temp_file = 'test.pvvs'
13compiler_path = '../vvc'
14interpreter_path = '../vvi'
15temp_file = './test.vvs'
16path_to_tests = './'
17src_extension = '.pvvs'
18
19tests = [
20 # Format: ['filename_without_extension', 'string for stdin', 'string for expected stdout']
c6e2791f
AT
21 ['0001_dumpstack', '', 'TOS:\n1:\t+42\n0:\t+255\n'],
22 ['0002_dumpheap', '', '32:\t+255\n33:\t+42\n'],
d8954ff0
AT
23 ['1001_stackrotate', '', 'TOS:\n13:\t+1\n12:\t+244\n11:\t+1\n10:\t+1\n9:\t+1\n8:\t+1\n7:\t+1\n6:\t+243\n5:\t+1\n4:\t+1\n3:\t+1\n2:\t+1\n1:\t+1\n0:\t+242\n'],
24 ['1002_stackrotatereverse', '', 'TOS:\n13:\t+1\n12:\t+244\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\n0:\t+1\n'],
25 ['1003_deepdup', '', '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\n0:\t+244\n'],
a805b721
AT
26 ]
27
28for test in tests:
29 subprocess.run([preprocessor, include_path, "-o", cpp_temp_file, path_to_tests + test[0] + src_extension])
30 subprocess.run([compiler_path, '-i', cpp_temp_file, '-o', temp_file])
31 result = subprocess.run([interpreter_path, '-i', temp_file], stdout=subprocess.PIPE, input=test[1].encode('utf-8'))
32 if result.stdout.decode('utf-8') != test[2]:
33 print('\n' + test[0])
34 else:
35 print('.', end='', flush=True)
9f7f68e5 36 os.remove(cpp_temp_file)
a805b721
AT
37 os.remove(temp_file)
38
39print("")