Commit | Line | Data |
---|---|---|
0cd0f6f3 AT |
1 | # Overview # |
2 | ||
3 | This folder contains tests for the VVhitespace interpreter (`vvi`). | |
4 | ||
749143b9 | 5 | |
0cd0f6f3 AT |
6 | # Instructions # |
7 | ||
8 | Edit 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 | ||
13 | Build `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 | |
20 | Alternatively, edit the configuration block in `vv_test.py` to provide | |
21 | appropriate paths relative to this `tests` folder. | |
22 | ||
23 | compiler_path = '../vvc' | |
24 | interpreter_path = '../vvi' | |
25 | ||
26 | With configuration now complete, execute the tests via `make test`. A dot will | |
27 | appear for every successfully completed test. For example: | |
28 | ||
29 | vvs-repo/tests % make test | |
30 | Testing vvi: | |
31 | ....................... | |
32 | vvs-repo/tests % | |
33 | ||
34 | If a test should fail, the name of the test will be printed in place of its | |
35 | dot. 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 | ||
46 | If testing is aborted prematurely, say by a Ctrl-C initiated SIGINT, use `make | |
47 | clean` to remove any temporary files. | |
749143b9 AT |
48 | |
49 | ||
50 | # Add New Test # | |
51 | ||
52 | Consider the test `5003_io_input_character.pvvs` as an example, reproduced | |
53 | below 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 | ||
62 | With the goal of testing the `get character from user` instruction, the test | |
63 | begins on lines 1-2 by setting up for and then using this instruction. Lines | |
64 | 3-5 print the result and line 6 terminates the test. | |
65 | ||
66 | Once you have written a test of this form, add it to the `tests` array in the | |
67 | file `vv_test.py`. The three fields are: | |
68 | ||
69 | ['filename_without_extension', 'string for stdin', 'string for expected stdout'] | |
70 | ||
71 | Continuing the same example: | |
72 | ||
73 | ['5003_io_input_character', 'A', 'A'], | |
74 | ||
75 | Note that the first field was the name of the file in which our test was saved, | |
76 | minus the extension. These filenames should be numbered, grouped by category | |
77 | and ordered by dependency. | |
78 | ||
79 | The second field is a string from which our test program may read. Since this | |
80 | is a test of reading an input character, the string is populated with `A`. | |
81 | ||
82 | The final field is the expected output from our test. In this example, this is | |
83 | simply the same character that was read from the previous field, `A`. | |
84 | ||
85 | Each time the test is executed by `vv_test.py` it will be fed the input from | |
86 | the second field and the output will be compared against the third field. If | |
87 | there is any mismatch, the test has failed and the user will be alerted with an | |
88 | error. | |
89 |