Updates to `tests/` for release. Mostly adding comments and improving the README.
[vvhitespace] / tests / vv_test.py
... / ...
CommitLineData
1#!/usr/local/bin/python3.6
2
3# (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
4# See LICENSE.txt file for copyright and license details.
5
6# Quick and dirty tests for the VVhitespace interpreter.
7# Invoke directly or see README.md in this folder for more details.
8
9# Configuration Options
10# All paths are relative to the PWD environment variable of the invoked script.
11compiler_path = '../vvc'
12interpreter_path = '../vvi'
13temp_file = './test.vvs'
14path_to_tests = './'
15src_extension = '.pvvs'
16
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']
20tests = [
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'],
30 ['2005_arithmetic_remainder', '', 'A113'],
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'],
38 ['4100_flowcontrol_branches_not_taken', '', 'A'],
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'],
43 ['6001_push_intmin', '', '1'],
44 ]
45
46# ------------------------------------------------------------------------------
47
48import os, subprocess
49
50for test in tests:
51 subprocess.run([compiler_path, '-i', path_to_tests + test[0] + src_extension, '-o', temp_file])
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]:
54 print('\n' + test[0])
55 print('\tExpected: ' + test[2])
56 print('\tReceived: ' + result.stdout.decode('utf-8'))
57 else:
58 print('.', end='', flush=True)
59 os.remove(temp_file)
60
61print("")