| 1 | # Overview # |
| 2 | |
| 3 | This folder contains tests for the VVhitespace standard library ('stdlib'). |
| 4 | |
| 5 | |
| 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/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 | |
| 20 | Alternatively, edit the configuration block in `vv_test.py` to provide |
| 21 | appropriate paths relative to this `stdlib_tests` folder. |
| 22 | |
| 23 | compiler_path = '../vvc' |
| 24 | interpreter_path = '../vvi' |
| 25 | include_path = '-I../stdlib' |
| 26 | |
| 27 | With configuration now complete, execute the tests via `make test`. A dot will |
| 28 | appear 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 | |
| 35 | If a test should fail, the name of the test will be printed in place of its |
| 36 | dot. For example, by breaking the `and` subroutine, the corresponding test |
| 37 | fails 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 | |
| 56 | If testing is aborted prematurely, say by a Ctrl-C initiated SIGINT, use `make |
| 57 | clean` to remove any temporary files. |
| 58 | |
| 59 | |
| 60 | # Add New Test # |
| 61 | |
| 62 | Most tests consist of four basic parts: |
| 63 | |
| 64 | 1. Perform a test. |
| 65 | 2. Print a result. |
| 66 | 3. Die. |
| 67 | 4. Dependencies |
| 68 | |
| 69 | With that framework in mind, consider `0001_dumpstack.pvvs`, the first test, |
| 70 | with 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 | |
| 80 | Comparing this to the four part framework, we see that lines 1-4 perform the |
| 81 | test and print the result, combined in this case since our test function's goal |
| 82 | is to print something. Line 5 then terminates the program, after which the |
| 83 | dependencies are included on line 7. |
| 84 | |
| 85 | Once you have written a test of this form, add it to the `tests` array in the |
| 86 | file `vv_test.py`. The three fields are: |
| 87 | |
| 88 | ['filename_without_extension', 'string for stdin', 'string for expected stdout'] |
| 89 | |
| 90 | Continuing with the same example: |
| 91 | |
| 92 | ['0001_dumpstack', '', 'TOS:\n2:\t+42\n1:\t+255\n'], |
| 93 | |
| 94 | Note that the first field was the name of the file in which our test was saved, |
| 95 | minus the extension. These filenames should be numbered, grouped by category |
| 96 | and ordered by dependency. |
| 97 | |
| 98 | The second field is empty since our test doesn't require any simulated input |
| 99 | from the user. |
| 100 | |
| 101 | The final field is the expected output from our test. In this example, with |
| 102 | tabs and newlines expanded: |
| 103 | |
| 104 | TOS: |
| 105 | 2: +42 |
| 106 | 1: +255 |
| 107 | |
| 108 | Each time the test is executed by `vv_test.py` it will be fed the input from |
| 109 | the second field and the output will be compared against the third field. If |
| 110 | there is any mismatch, the test has failed and the user will be alerted with an |
| 111 | error. |
| 112 | |