Updated vvi tests README with info about adding new tests.
[vvhitespace] / tests / README.md
CommitLineData
0cd0f6f3
AT
1# Overview #
2
3This folder contains tests for the VVhitespace interpreter (`vvi`).
4
749143b9 5
0cd0f6f3
AT
6# Instructions #
7
8Edit the shebang in `vv_test.py` to match your environment. For example:
9
10 FreeBSD 12: #!/usr/local/bin/python3.6
11 Debian 9 : #!/usr/bin/python3
12
13Build `vvc` and `vvi` in the source tree, if you haven't already.
14
15 vvs-repo/tests % cd .. && make clean all && cd tests
749143b9
AT
16 cc -Wall -std=c99 -o vvc vv_compiler.c
17 cc -Wall -std=c99 -o vvi vv_interpreter.c
18 vvs-repo/tests %
0cd0f6f3
AT
19
20Alternatively, edit the configuration block in `vv_test.py` to provide
21appropriate paths relative to this `tests` folder.
22
23 compiler_path = '../vvc'
24 interpreter_path = '../vvi'
25
26With configuration now complete, execute the tests via `make test`. A dot will
27appear for every successfully completed test. For example:
28
29 vvs-repo/tests % make test
30 Testing vvi:
31 .......................
32 vvs-repo/tests %
33
34If a test should fail, the name of the test will be printed in place of its
35dot. For example, with an induced failure in the division command:
36
37 vvs-repo/tests % make test
38 Testing vvi:
39 ........
40 2004_arithmetic_division
41 Expected: A
42 Received: A113
43 ..............
44 vvs-repo/tests %
45
46If testing is aborted prematurely, say by a Ctrl-C initiated SIGINT, use `make
47clean` to remove any temporary files.
749143b9
AT
48
49
50# Add New Test #
51
52Consider the test `5003_io_input_character.pvvs` as an example, reproduced
53below with line numbers.
54
55 1: SSSTN | ST: Push +1
56 2: TNTS | IO: Input character
57 3: SSSTN | ST: Push +1
58 4: TTT | HP: Load
59 5: TNSS | IO: Output character
60 6: NNN | FC: Terminate program
61
62With the goal of testing the `get character from user` instruction, the test
63begins on lines 1-2 by setting up for and then using this instruction. Lines
643-5 print the result and line 6 terminates the test.
65
66Once you have written a test of this form, add it to the `tests` array in the
67file `vv_test.py`. The three fields are:
68
69 ['filename_without_extension', 'string for stdin', 'string for expected stdout']
70
71Continuing the same example:
72
73 ['5003_io_input_character', 'A', 'A'],
74
75Note that the first field was the name of the file in which our test was saved,
76minus the extension. These filenames should be numbered, grouped by category
77and ordered by dependency.
78
79The second field is a string from which our test program may read. Since this
80is a test of reading an input character, the string is populated with `A`.
81
82The final field is the expected output from our test. In this example, this is
83simply the same character that was read from the previous field, `A`.
84
85Each time the test is executed by `vv_test.py` it will be fed the input from
86the second field and the output will be compared against the third field. If
87there is any mismatch, the test has failed and the user will be alerted with an
88error.
89