6 Sparse has a number of test cases in its validation directory. The test-suite
7 script aims at making automated checking of these tests possible. It works by
8 embedding tags in C comments in the test cases.
10 check-name: (mandatory)
13 check-description: (optional)
14 A description of what the test checks.
16 check-command: (optional)
17 There are different kinds of tests. Some can validate the sparse
18 preprocessor, while others will use sparse, cgcc, or even other backends
19 of the library. check-command allows you to give a custom command to
21 The '$file' string is special. It will be expanded to the file name at
23 It defaults to "sparse $file".
25 check-exit-value: (optional)
26 The expected exit value of check-command. It defaults to 0.
28 check-timeout: (optional)
29 The maximum expected duration of check-command, in seconds.
32 check-output-start / check-output-end (optional)
33 The expected output (stdout and stderr) of check-command lies between
34 those two tags. It defaults to no output.
36 check-output-ignore / check-error-ignore (optional)
37 Don't check the expected output (stdout or stderr) of check-command
38 (useful when this output is not comparable or if you're only interested
40 By default this check is done.
42 check-known-to-fail (optional)
43 Mark the test as being known to fail.
45 check-output-contains: <pattern> (optional)
46 Check that the output (stdout) contains the given pattern.
47 Several such tags can be given, in which case the output
48 must contains all the patterns.
50 check-output-excludes: <pattern> (optional)
51 Similar than the above one, but with opposite logic.
52 Check that the output (stdout) doesn't contain the given pattern.
53 Several such tags can be given, in which case the output
54 must contains none of the patterns.
56 check-output-pattern-<nbr>-times: <pattern> (optional)
57 Similar to the contains/excludes above, but with full control
58 of the number of times the pattern should occur in the output.
63 The test-suite script is called through the check target of the Makefile. It
64 will try to check every test case it finds (find validation -name '*.c').
66 It can be called to check a single test with:
68 $ ./test-suite single preprocessor/preprocessor1.c
69 TEST Preprocessor #1 (preprocessor/preprocessor1.c)
70 preprocessor/preprocessor1.c passed !
76 test-suite comes with a format command to make a test easier to write:
78 test-suite format file [name [cmd]]
81 check-name value. If no name is provided, it defaults to the file name.
83 check-command value. If no cmd is provided, it defaults to
86 The output of the test-suite format command can be redirected into the
87 test case to create a test-suite formatted file.
89 $ ./test-suite format bad-assignment.c Assignment >> bad-assignment.c
93 * check-name: bad assignment
95 * check-command: sparse $file
99 bad-assignment.c:3:6: error: Expected ; at end of statement
100 bad-assignment.c:3:6: error: got \
104 You can define the check-command you want to use for the test. $file will be
105 extended to the file name at run time.
107 $ ./test-suite format validation/preprocessor2.c "Preprocessor #2" \
108 "sparse -E \$file" >> validation/preprocessor2.c
110 cat validation/preprocessor2.c
112 * This one we happen to get right.
114 * It should result in a simple
118 * for a proper preprocessor.
122 #define UNARY(x) BINARY(x)
123 #define BINARY(x, y) x + y
127 * check-name: Preprocessor #2
129 * check-command: sparse -E $file
130 * check-exit-value: 0