generate platform_ops.h from platform_ops.proto, and reduce dependencies
[proto.git] / src / README.prototest
blob70f80099c84bc9411d962fa8cdc29f69a9ab6bfc
1 PROTOTEST LONG HELP + TUTORIAL
3 prototest is a regression tester for MIT Proto.
5 1. REQUIREMENTS
7 prototest requires Python v. 2.5
10 2. BASICS
12 Dump Directory:
13   IF prototest is not in the same directory as proto
14   OR you're telling proto to output to a custom location,
15   THEN use the -d option to tell prototest the path to the dump files.
16   DO NOT use --dump-stem when running proto... this will break prototest
17   as it uses its own naming conventions)
19 Terminology:
20   Test File: Is a file containing one or more tests
21   Test: is a group of assertions that work on the log generated by the
22     same proto command
23   Assertion: is a claim about the expected value. Currently only numerical 
24     assertions (=, > , <, >=, ~=, !=...) are supported.
27 3. USING PROTOTEST
29 The usage is:
31   python prototest.py input [other options]
33 Input can be one of:
34   * Test File
35   * Test Suite (A file containing a list of paths to test files. Paths can be 
36     be absolute paths or relative to prototest)
37   * Test Directory 
39 When you pass a test suite or a test directory all test files (files with 
40 extension .test) will be run sequentially.
42 The result of each test file is written to the same directory as the
43 test file.  The result file has a ".RESULT" appended to the name of
44 the test file.
46 Other Options:
47     * Verbosity (-v): There are currently 4 verbosity levels, numbered 0 through 3, 
48       which control the output verbosity (default is 1). 0 gives you the most
49       terse output, while 4 will display the test file parser messages
50       (useful if you want to "debug" your test files).
51     * Dumpdir (-d): Allows you to manually set proto dump directory. 
52     * Recursive (-r): In directory mode, enabling this option will find testfiles
53       in subdirectories as well. (WARNING: could be slow if you have a LOT of 
54       files in subdirectories. Where LOT means order 50,000 files). 
56 4. WRITING A TEST FILE
57 Test files should have a ".test" extension.  Please see the test/
58 subdirectory for examples of test files.
60 Adding Comments:
61 - Use // to start a comment
62 - Comment must exist in its own line (You cannot attach a comment to
63   the end of a non-comment line)
65 Creating Tests:
66 - Use 'test: <commands for proto>' to create a test
67 - WARNING: do not use "dump stem" AT ALL. This will break prototest.
68 - WARNING: do not change the dump directory, unless you HAVE to. If
69   you change the dump directory, be sure to specify its location when
70   you run prototest.
71 - TIP: Use --headless to run the simulator without the GUI (results in
72   speedups)
73 - A test needs to have at least one assertion to be run.
75 Adding Assertions to a Test:
76 - Use "<operator> <line#> <col#> <expected value> [<other args>] 
77 - Note that both LINE and COLUMN numberings start from ZERO. 
78 - Use -1, -2, ... to access the last, second last, ... columns of line.
79 - You can use "_" (without the quotes) as your column number if you want to
80   compare with the whole line. 
81 - Numerical operators supported at present: =, > , < , >= , <= , != ,
82   ~= (the last two are not equal to, and nearly equal to)
83 - Use "is_nan" operator to check for NaN
84 - Nearly equal to takes in "tolerance" as other args.
85 - You can add as many assertions as necessary (on separate lines)
87 Other Lines:
88 - At present, all other lines are ignored, but do not rely on this
89   behavior to comment your files; Use // to explicitly mark your
90   comments.
93 5. CREATING TEST SUITES TO RUN TESTS IN BATCH MODE
94 Instead of simply putting your test files in a single directory and running
95 all tests in the directory, you can create a test suite file with just the tests
96 you need.
98 To create a test suite file, simply create a file with paths (either absolute
99 or relative to prototest) and name it blah.testsuite
101 Example of a testsuite:
102 ./tests/math.test
103 ./tests/mathlib.test
104 ./tests/vector.test
106 6. EXTENDING PROTOTEST BY ADDING YOUR OWN OPERATORS
107 - Your function should take in either:
108     * value in the dumpfile ("actual value) and the "expected value" [IN THAT
109       ORDER].
110     * -OR- a list of arguments (for functions that require other supporting 
111       parameters). This function should return another function that takes in
112       an actual value and an expected value.
113 - The operation will be carried out as: [actual] {OPERATOR} [expected]. E.g.
114   if your function is ">", you will be performing [actual] > [expected]. 
115 - Your function should return "TRUE" if the operator criteria is satisfied, and
116   FALSE in all other cases. For example, if your operator is >, your function 
117   should return TRUE whenever (actual value) > (expected value).
118 - Often, your function might require other supporting arguments (besides actual 
119   & expected value). In this case, use currying. E.g. the ~= (nearly equal) 
120   operator requires "error tolerance" as optional argument. So, we create a 
121   function that takes in a list of arguments as values, and returns a function
122   of appropriate type: 
123   (lambda arg_list: (lambda act, exp: abs(act - exp) <= arg_list[0]))
124 - Add your function to the appropriate dictionary in ConfigParser in prototest. 
125   We currently have two dictionaries: "numeric_fns" and "string_fns". The dict
126   entries have the symbol as key, and a tuple of the function and a description
127   as the value. If you add new dictionaries, you will need to make necessary
128   changes in the "run" method of ConfigParser.
130 6. CHANGELOG
132 Changelog:
134 0.75 [kanak]
135 * CHANGED: "_" is now used to determine if function takes in whole line, rather
136   than negative numbers. This change was necessary because we can use -ve number
137   to access the list backwards, which IMO is a powerful feature to have.
138   (Note: compiler tests still work because using -1 on a list with only one 
139   element gives you that same element).
140 * REFACTORED: definitions of string functions now
141   match the definitions of numeric functions (i.e. no extra "1" or "0" switch
142   to determine if function accepts whole line is required).
143 * ADDED: "has" string function
144 * CHANGED: Minor indentation and documentation
146 0.74 [kanak]
147 * Added a recursively scan directory option.
149 0.73 [kanak]
150 * Added an explicit "Test Suite Input mode" for times when running an entire
151   test directory is overkill
152 * Improved Output display: 
153     - A primitive progress bar which display a "." for every 5 tests run
154     - Instead of just saying passed all tests, it says passed all X tests. where
155       X is the number of tests.
157 0.72 [Jake]
158 * Whole line testing added (to test p2b)
160 0.71 [kanak]
161 * Verbosity Level 0 now makes tests headless if they aren't already.
163 0.7 Final: UI changes, fixed unwanted seperator lines in log file,
164   fixed crash when using string comparisons.
165 0.7 beta 2: bugs fixed. Other than slight changes to the UI, code is ready.
166 0.7 beta 1: initial build
168 0.7 [kanak]
169 New version number to reflect massive change in functionality;
170 * Directories are now supported as inputs.
171 * Class structure was overhauled to Test Suite -> Test File -> Tests
172   -> Assertions.
173 * Major refactoring of the "Main" method, which is now a lot shorter
174   since behaviors such as writing to log files have been moved to
175   appropriate classes / methods.
177 0.61 [kanak]
178 * CHANGED: Curried functions are now generalized (now accept list
179   instead of disparate elements)
180 * ADDED: String comparisons (to support "is_nan" test)
181 * ADDED: "is_nan" comparison operator which tests if number returned is nan
183 0.60 [kanak]
184 * REFACTORED: Code is now much more readable, and adheres to the
185   python style guide (http://www.python.org/dev/peps/pep-0008/). Major
186   Violations included: Using something other than 4 spaces for tabs,
187   too long statements, concatenating statements into a single line,
188   too many branches (partially resolved), and overly long functions.
189   Non standard tabbing is a big problem because indentation is all too
190   important in python.
192 0.57 [kanak]
193 * REFACTORED: the "main" method, which was becoming a jungle of "if
194   verbosity"s in light of the following changes:
195 * ADDED: a "failed" attribute in test to determine whether a test was
196   successful (instead of len(test.failedAssertions) == 0)
197 * REMOVED: -n (no proto output) command line switch. The switch was
198   redundant in light of new verbosity levels:
199 * CHANGED: verbosity levels.
200   #VERBOSITY LEVELS:
201   #0: log failed tests only, don't even display the successful tests
202   #1 (Default): log only failed tests, "all assertions passed"
203    displayed for successful tests
204   #2: log both failed and successful tests
205   #3: like #2, but also displays parser output.
206   
207 0.562 [kanak]
208 * ADDED: -noprotooutput switch to prevent prototest from writing
209   proto's stdout/stderr in the results file
210 * CHANGED: instead of allpass, we now compute the number of tests
211   passed. So "X out of Y tests passed" is displayed instead of
212   unhelpful FAIL. (If all tests are passed, "ALL TESTS ARE PASSED" is
213   still displayed)
214 * CHANGED: optparse's arguments are now assigned by tuple unpacking
215   (more concise).
217 0.561 [kanak]
218 * CHANGED: Parser now outputs its guts only when verbosity level is 3
219   or greater.
221 0.56 [kanak]
222 * FIXED: turns out the verbose mode wasn't really working-> it was
223   using an invalid action "check" instead of "store", since "type" was
224   not defined it was "storing" strings instead of ints.
225 * CHANGED: Verbose mode 2 now prints successfull assertions as well
226   (useful in verifying mathematical functions)
228 0.551 [kanak]
229 * CHANGED: Default value for verbosity is "0" instead of "False" (for
230   consistency)
231 * ADDED: Dump file  location is printed in log by default
232 * ADDED: "~=" comparison to sampletest. (To test if the comparison
233   works... pychecker claimed that the function had an unused
234   parameter)
236 0.55: [jake]
237 * CHANGED: Output is now prettier
238 * CHANGED: Before each test, a dot prints on the console, showing how
239   execution is running
240 * CHANGED: verbose -> verbosity, now with multiple levels: verbosity 1
241   shows testing, verbosity 2 shows parsing of assertion files
243 0.54:
244 * FIXED: Crash when the "actual value" is non-numeric
246 0.53:
247 * ADDED: -d command line option to explicitly set dumpfile path
248 * UPDATED: readme
250 0.52:
251 * FIXED: Prototest doesn't find dump directory when executed from a
252   different location
253 * FIXED: Prototest now crashes with "IOError: <testconfig> file
254   couldn't be found" instead of a cryptic "Unbound Error" when config
255   file doesn't exist
256 * FIXED: Missing Dumpfile now throws MissingDumpFileException and
257   marks all tests as failed instead of "Unforseen Error Occurred"
258 * FIXED: Unforseen error now appends the name /details of exception
259   instead of just saying "Unforseen error"
260 * FIXED: Unwanted newlines when printing parser output in verbose mode
261 * FIXED: Linecache doesn't throw IndexOutOfBounds leading to
262   "UnboundVariable" exceptions
263 * VERIFIED: Py3K compliance
264 * CHANGED: thread is now executed using subprocess instead of
265   "deprecated" os.system. Advantages include: proto launched as
266   separate thread, can do "nifty" stuff like kill thread etc.
267 * CHANGED: "Version" is now a variable instead of a hard coded string
268   so referencing it is easier.
269 * CHANGED: verbose mode now writes successful tests as well, and
270   displays the "exceptions"
271 * CHANGED: log file now has a "---" delimiter between tests
272 * ADDED: MissingDumpFileException to be thrown when dumpfile doesn't exist
274 0.51:
275 * FIXED: Missing Paren, and other bugs [JAKE]
276 * CHANGED: Output is now prettier [JAKE]
278 0.5:
279 Major Refactoring: code has been simplified and better documented
280 * Uses dictionary lookup instead of genAssert
281 * Uses curried version of "nearly equal to"
282 * LongHelp and Changelog moved to external file
284 0.41:
285 * CHANGED prototest now looks at return code of proto before running
286   assertions. A non-zero assertions means tests are not run.
288 0.4:
289 * FIXED crash when line/column not found (now adds "exception" to the
290   assertion)
291 * FIXED crash when dump file not found (now adds "exception" to the test)
292 * FIXED reads long lines due to linecache's weird "indexing starts
293   from 1" behavior
294 * FIXED comparisons fail because numbers were being compared to strings
295 * FIXED output generator displays "FAILED X TESTS" repeatedly as a
296   result of problem with join
297 * FIXED noisy output even when in non-verbose mode
298 * CHANGED the output log generation. Log generation is now simplified.
299 * REVERTED command execution is done by os.system instead of
300   check_call because check_call gives weird errors when trying to use
301   -dump-stem
303 0.2:
304 * ADDED randomized dump file name generation
305 * ADDED long help option
306 * CHANGED reading the proto dump log file is done by linecache instead
307   of the "naive method".
308 * CHANGED command line parsing is done by python's optparse module
309 * CHANGED proto is now executed by using the subprocess module's
310   "check_call" method instead of os.system
311 * and other minor bug fixes and optimizations, primarily in the
312   configparser method
314 0.1: Initial port to python from java