Updates to `stdlib_tests/` for release.
[vvhitespace] / stdlib_tests / README.md
CommitLineData
aa1914c3
AT
1# Overview #
2
3This folder contains tests for the VVhitespace standard library ('stdlib').
4
5
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/stdlib_tests % cd .. && make clean all && cd stdlib_tests
16 cc -Wall -std=c99 -o vvc vv_compiler.c
17 cc -Wall -std=c99 -o vvi vv_interpreter.c
18 vvs-repo/stdlib_tests %
19
20Alternatively, edit the configuration block in `vv_test.py` to provide
21appropriate paths relative to this `stdlib_tests` folder.
22
23 compiler_path = '../vvc'
24 interpreter_path = '../vvi'
25 include_path = '-I../stdlib'
26
27With configuration now complete, execute the tests via `make test`. A dot will
28appear for every successfully completed test. For example:
29
30 vvs-repo/stdlib_tests % make test
31 Testing stdlib:
32 ..................................
33 vvs-repo/stdlib_tests %
34
35If a test should fail, the name of the test will be printed in place of its
36dot. For example, by breaking the `and` subroutine, the corresponding test
37fails for `and` and for all subroutines which depend on `and`.
38
39 vvs-repo/stdlib_tests % make test
40 Testing stdlib:
41 ................
42 3004_and
43 Expected: +0+0+1+1+42
44 Received: +3+3+4+4+45
45
46 3005_or
47 Expected: +0+1+1-1-1
48 Received: -3-2-2-4-4
49
50 3006_xor
51 Expected: +0+1+0-2-1
52 Received: -1-1-3-5-1
53 ...............
54 vvs-repo/stdlib_tests %
55
56If testing is aborted prematurely, say by a Ctrl-C initiated SIGINT, use `make
57clean` to remove any temporary files.
58
59
60# Add New Test #
61
62Most tests consist of four basic parts:
63
64 1. Perform a test.
65 2. Print a result.
66 3. Die.
67 4. Dependencies
68
69With that framework in mind, consider `0001_dumpstack.pvvs`, the first test,
70with line numbers for reference.
71
72 1: SSSTTTTTTTTN | PUSH 255
73 2: SSSTSTSTSN | PUSH 42
74 3: SSSTSN | PUSH 2 (count)
75 4: NSTTTTSSTN | JSR > 111001 (dumpstack)
76 5: NNN | DIE
77 6:
78 7: #include <debug.pvvs>
79
80Comparing this to the four part framework, we see that lines 1-4 perform the
81test and print the result, combined in this case since our test function's goal
82is to print something. Line 5 then terminates the program, after which the
83dependencies are included on line 7.
84
85Once you have written a test of this form, add it to the `tests` array in the
86file `vv_test.py`. The three fields are:
87
88 ['filename_without_extension', 'string for stdin', 'string for expected stdout']
89
90Continuing with the same example:
91
92 ['0001_dumpstack', '', 'TOS:\n2:\t+42\n1:\t+255\n'],
93
94Note that the first field was the name of the file in which our test was saved,
95minus the extension. These filenames should be numbered, grouped by category
96and ordered by dependency.
97
98The second field is empty since our test doesn't require any simulated input
99from the user.
100
101The final field is the expected output from our test. In this example, with
102tabs and newlines expanded:
103
104 TOS:
105 2: +42
106 1: +255
107
108Each time the test is executed by `vv_test.py` it will be fed the input from
109the second field and the output will be compared against the third field. If
110there is any mismatch, the test has failed and the user will be alerted with an
111error.
2c2764b7 112