testing A natural way to test the components of a Jack compiler it is to see how they handle some representative Jack programs. We have included a number of Jack programs from the nand2tetris files together with a number of our own smaller examples. The tests for each component program are all run in the same way. Just run make with no arguments and every component program will be compiled and run using all the tests in the tests directory. To allow you to implement your component programs in any order, the test scripts will use working versions of the component programs not being tested. Here is a snippet of the output you may see if you just run make. Notes: Make will automatically add files to svn if they are missing and it may commit them too but, if not, you may have to perform the commit. The warning will keep appearing until a file has been committed to svn for the first time.The reminder to run svn update and svn commit should appear every hour. It is important to always run svn update when you start work and svn commit when you make logbook entries or take a break.The reminder to write in your logbook should appear every half hour. If you logbook does not record your progress as you work your final mark for an assignment may be capped at 25 or in some cases reduced to 0.The Test column can be used to refer to a specific test if you wish to inspect the actual output from the test.The Program column tells you what program was running including any command line arguments it was passed.The Output column shows you whether or not your program produced the expected standard output (file 1). If it did the column will have a green background, if it did not it will have a red background and if the test does not care, a ? will be displayed.The Errors column shows you whether or not your program produced the expected standard error (file 2).The Status columns shows you the exit status returned when your program terminated.The Test Result column shows you whether or not your program passed the test overall. This will either be Test Passed in green or Test Failed in red.The Description column may tell you something about the nature of the test or the input.You must use make to compile and test your programs so that the updates/log file can help record your progress and provide some additional information, such as source file changes, that can be later integrated into your logbook. Running Individual Tests The tests in the tests directory can run individually if necessary. If you fail a test and want to see what was actually produced by your program you can run the test in a number of ways. In the following examples the parser program has an error when trying to parse types, it does not read the next token: You can run a single test and also see the live output too: In this case the parser program has a trace write added at the start of parsing a function. Trace writes are disabled when testing your programs but the test script also runs your program with trace writes enabled to help you with debugging. If there are trace writes a star will be displayed next to the F* or P* in the Output and Error columns. To see the differences between the expected and actual output we can show the test. To use less to view the output you can use less instead of show. This example shows the instruction with the error, the + line is output that is not expected and the – line is a line of output that is missing. The error message was not written to standard output so the entire output appears to be missing. To see more detail such as as the names of the input files, names of the test output files and any trace writes, we Show the test. To use less to view the output you can use Less instead of Show. This example shows the differences between the program output with and without the traces writes. Your Own Tests You can construct your own command pipelines to try different ways of testing your programs. For example, you could pretty print the output of an optimiser as Jack code, or run the optimiser over its own output, or run the parser over the output of the pretty printer. Here is an example of pretty printing optimiser output. % cat Main.jack | ./parser | ./optimiser-r | ./pretty > Prettier.jack This might transform: class Main{function void main(){var int a;let a = 1;return;let a=2;}} into: class Main { function void main() { var int a ; let a = 1 ; return ; } } The following command should also perform the same transformation: % cat Main.jack | ./parser | ./optimiser-r | ./pretty | ./parser | ./optimiser-r | ./pretty > Prettier.jack Testing Everything If you want to run all of the tests at once, you can use the command: % make If you want to run all of the tests at once using working versions of the component programs, you can use the command: % make working