The testing framework
There is a fairly simple automatic testing framwork that is run at build time. There are three sorts of test - code tests run a custom piece of CanalPlan code and check the specific results; page tests generate an HTML page as though by a user and match the results against expected values; and generate tests generate a gazetteer page
Creating a test
To add a new test:
- create a directory in build/auto_test/tests/ with a name that vaguely describes the test (an _ at the start of the name disables the test)
- in that directory, create the following files:
- config.txt - some configuration detail
- For a code test:
- test.can - the actual test
- For a page test - NOTE: there aren't any of these at the moment:
- cgi_query - the cgi parameters to be passed to the page
- data_tests - a series of tests to be run on the data generated for the page
- html_tests - a series of tests to be run on the HTML produced
- For a generate test there are no extra files
Running tests
The test will now be automatically run during build publish or you can run them at any time by being in the build/auto_test directory and typing make or by running make autotests at the top level.
config.txt
This should consist of lines consisting of a tag, a colon and a value. Valid tags are:
- title - the text printed to describe the test when it is run by the framework
- type - one of code, page or generate, as described above
- page - for page tests, the file in cgi-bin to be run to generate the page. For generate tests, the file in pages/code/script to be run to generate the page
- args - for generate tests only, the parameters to be passed to the program
test.can
For code type tests. This should be a standalone program in the CanalPlan programming language. Specific points to note are:
- at the start add the line "../include system.config.fileroot+'build/auto_test/utils.can' as 'test$'
- when, and only when, all tests have completed successfully it should execute test$success to indicate success.
- all references to files should use system.config.fileroot rather than relative paths. You may need to edit any files it includes from the main codebase to use that form as well (it's entirely valid throughout the package, but lots of early coding used relative paths and they haven't all been transitioned).
- The output from print commands is redirected to log.txt and will be displayed by the test harness only if the test fails.
cgi_query
For page type tests. A series of name/value pairs on separate lines that will be passed to the script in the form of CGI input
data_tests
For page type tests.
html_tests
For page type tests.
