Skip to content

Commit 1bfdf6e

Browse files
committed
regression test readme
1 parent b376087 commit 1bfdf6e

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

test/regression/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Regression Tests
2+
3+
This directory contains regression tests for GUFI.
4+
5+
## Usage
6+
7+
Each regression test consists of at least two files: a bash script and
8+
a corresponding .expected file. There might be additional files, such
9+
as Python scripts, associated with each test. The test scripts will
10+
not be installed. They will be copied to `test/regression` and
11+
modified to replace CMake variables.
12+
13+
To run all tests, run `ctest` or `make test`. To run a single test,
14+
run the script file directly. The individual script files should pass
15+
when running from any writable directory that allows for extended
16+
attributes to be applied to filesystem entries. Note that some test
17+
scripts require `sudo`. All of tests should pass with or without
18+
`sudo`.
19+
20+
The output of a test script will be printed to standard out as well as
21+
a corresponding .out file. The diff between the .expected file and
22+
.outfile will also be printed (the regression tests can be thought of
23+
as known answer tests). If a regression test's .expected needs to be
24+
updated, the .out file can be used to directly overwrite the .expected
25+
file with `cat` and a redirect, `cp`, or `mv`.
26+
27+
## Common Files
28+
29+
- `setup.sh` contains common functions, variables, setup code, cleanup code, etc.
30+
- `replace`: replaces environment-specific text with common text,
31+
such as the actual path to an executable with the name
32+
- When adding a new test, add variables containing patterns to
33+
replace and modify this function to do the replacement
34+
35+
- `run_sort`: runs the given command, printing the command as well
36+
as the sorted output, passed into `replace`
37+
38+
- `run_no_sort`: runs the given command, printing the command as
39+
well as the unsorted output, passed into `replace`
40+
41+
- `setup_cleanup`: function that is called on exit of script
42+
- Wrap this with a test-specific cleanup function if the test
43+
requires custom cleanup
44+
45+
- `generatetree.sh` generates a fixed source tree with known properties
46+
- This is the most commonly used script/tree
47+
- This is generally automatically called through sourcing `setup.sh`
48+
49+
- `rollup_tree.sh` generates a fixed tree with known properties for
50+
testing rollups with
51+
- Requires `sudo`
52+
53+
- `gufi_tool.py` fakes entry points into Python tools in order to use
54+
a test configuration file instead of the real one
55+
56+
## Test Script Structure
57+
1. `#!/usr/bin/env bash`
58+
2. License
59+
3. `set -e`
60+
4. `. setup.sh 1`
61+
- Pass in `0` if the source tree and index do not need to be generated
62+
5. Define variables
63+
6. If necessary, set up a cleanup exit function and call it
64+
- Call `setup_cleanup` in this function
65+
7. Define the name where the output will be written to
66+
- `OUTPUT="<name>.out"`
67+
8. Define functions
68+
9. Run tests in a subshell
69+
- `tee` all output to `"${OUTPUT}"`
70+
10. `@DIFF@ @CMAKE_CURRENT_BINARY_DIR@/<name>.expected "${OUTPUT}"`
71+
11. `rm "${OUTPUT}"`
72+
- This only happens if `@DIFF@` returned 0
73+
74+
## Adding a New Test Script
75+
1. Create an empty test script with the name `<name>.sh.in` in this directory
76+
2. Create an empty .expected file in this directory
77+
3. Add the test script and expected file to git
78+
4. Add `<name>` to the appropriate location in `CMakeLists.txt`
79+
5. Add contents into the test script
80+
- See [Test Script Structure](#test-script-structure)
81+
6. Rebuild to get the latest test script into the build directory
82+
- Will be called `<name>.sh`
83+
7. If not satisfied with the tests or output, go to step 5
84+
8. Overwrite the source .expected file with `<name>.output`
85+
9. If available, run `make shellcheck` to find issues in the test script
86+
10. Commit and push

0 commit comments

Comments
 (0)