raz / doc / raztest.1

250 lines · 5.5 KiB · raw · history · last change c9ee56dd

1.\" raztest(1) - build and run the tests of a raz program
2.Dd October 22, 2026
3.Dt RAZTEST 1
4.Os
5.Sh NAME
6.Nm raztest
7.Nd build and run the tests of a raz program
8.Sh SYNOPSIS
9.Nm
10.Op Fl I Ar dir
11.Op Fl j Ar n
12.Op Fl t Ar secs
13.Op Fl o Ar dir
14.Op Fl r Ar text
15.Op Fl w
16.Op Fl \-tap
17.Op Fl \-junit Ar file
18.Op Fl \-seed Ar n
19.Op Fl \-fuzz Ar secs
20.Ar file.raz Ns | Ns Ar dir ...
21.Sh DESCRIPTION
22.Nm
23builds each test with
24.Ic raz -Werror ,
25runs it, and says which passed.
26A test is a module whose
27.Ic main
28is its test: it passes if it builds and then exits with status 0, as a
29program that checks with the library's
30.Ic Check
31does when no check fails.
32.Pp
33The tests are the files given.
34A directory gives each
35.Pa *.raz
36directly in it that has a line starting
37.Ql proc main* ,
38in the order of their names.
39A test's name is its file's, without
40.Pa .raz ;
41two tests may not share one.
42.Pp
43Each test is built into the
44.Fl o
45directory as
46.Ar name ,
47and run there with standard input from
48.Pa /dev/null ,
49in a process group of its own.
50What the compiler writes, and then what the test writes on standard
51output and standard error, goes to
52.Ar name Ns .out
53beside it, which stays for a look afterwards.
54A build or a run that takes longer than the
55.Fl t
56seconds has its process group killed.
57.Pp
58As each test ends,
59.Nm
60writes a line for it, in the order the tests were given: the word
61.Ql ok ,
62.Ql FAIL
63or
64.Ql TIMEOUT ,
65the file, for a failure what failed,
66such as
67.Ql doesn't compile ,
68.Ql status 1
69or
70.Ql signal 11 ,
71and the seconds it took to build and run.
72Under a failure comes its
73.Pa .out ,
74indented by four spaces.
75Last comes a summary:
76.Bd -literal -offset indent
7712 passed, 1 failed, 0 timed out, 3.41s
78.Ed
79.Pp
80The three words are in colour when standard output is a terminal.
81.Pp
82With
83.Fl \-tap
84standard output is TAP version 14 instead: the lines
85.Ql TAP version 14
86and
87.Ql 1..N ,
88then for each test
89.Ql ok K - file
90or
91.Ql not ok K - file # status 1
92(the same reason as the
93.Ql FAIL
94line, or
95.Ql timed out ) ,
96with a failure's
97.Pa .out
98under it as comment lines starting with
99.Ql # ,
100and the summary as a last comment line.
101There is no colour.
102.Sh OPTIONS
103.Bl -tag -width "--junit file"
104.It Fl I Ar dir
105Look for modules in
106.Ar dir
107too, as
108.Ic raz -I
109does.
110It may be given more than once.
111.It Fl j Ar n
112Build and run
113.Ar n
114tests at once; 1 if not given.
115.It Fl t Ar secs
116Kill a build, or a run, that takes longer than
117.Ar secs
118seconds; 60 if not given.
119.It Fl o Ar dir
120Put the programs and their
121.Pa .out
122files in
123.Ar dir ,
124made if it isn't there;
125.Pa build/raztest
126if not given.
127.It Fl r Ar text
128Run only the tests whose name holds
129.Ar text .
130.It Fl w , Fl \-watch
131Run the tests, then run them all again whenever a file changes, until
132interrupted.
133Watched are the
134.Pa *.raz
135files directly in the directory of each test file given, in each
136directory given, and in each
137.Fl I
138directory, not those below them.
139The files' times and sizes are looked at every 300 ms, and a change is
140waited out until the files stay as they are for one look, since an
141editor writes in steps.
142All the tests run again, not only those a change reaches.
143The operands are read again each time, so a new test file is found.
144On a terminal the screen is cleared before each run, and
145.Ql watching N files; ^C stops
146is written after the summary.
147With
148.Fl \-junit
149the file is written again after each run.
150.It Fl \-tap
151Write TAP instead of the usual lines.
152.It Fl \-junit Ar file
153Besides the usual output, write the results to
154.Ar file
155as JUnit XML, which CI services read: one
156.Ql testcase
157for each test, its
158.Ql classname
159the file, with a
160.Ql failure
161holding the log for one that failed or timed out.
162The directory of
163.Ar file
164must exist; if it can't be written, the status is 2.
165Control bytes XML 1.0 forbids in a log are written as
166.Ql \&? ;
167invalid UTF-8 is passed through.
168.It Fl \-seed Ar n
169For tests that use the library's
170.Ic Prop :
171set
172.Ev PROP_SEED
173to
174.Ar n ,
175a whole number from 0, so that their fresh cases are those of an
176earlier run, which a failing property names.
177.It Fl \-fuzz Ar secs
178For tests that use
179.Ic Prop :
180set
181.Ev PROP_TIME
182to
183.Ar secs ,
184so that each property is tried on fresh cases for that many seconds,
185not on 100 of them.
186It raises
187.Fl t
188to
189.Ar secs
190+ 60, unless
191.Fl t
192is given.
193That is enough for one property in a test; a test with several
194properties needs
195.Fl t
196to say more.
197.It Fl h , Fl \-help
198Say the options, and exit.
199.El
200.Sh ENVIRONMENT
201.Bl -tag -width "NO_COLOR"
202.It Ev RAZ
203The compiler; if unset,
204.Ic raz
205on the
206.Ev PATH .
207.It Ev NO_COLOR
208If set and not empty, no colour.
209.El
210.Sh EXIT STATUS
2110 if every test passed; 1 if one failed or timed out; 2 for a mistake
212in the command line, a file that isn't there, or an output directory
213that can't be made.
214Stopped by an interrupt or a hangup, it kills the tests under way and
215exits with 128 and the signal's number.
216.Sh EXAMPLES
217Run a project's tests, four at a time:
218.Bd -literal -offset indent
219raztest -j 4 -I src test
220.Ed
221.Pp
222In CI, with a report for the service to show:
223.Bd -literal -offset indent
224raztest -j 4 -I src --junit build/junit.xml test
225.Ed
226.Pp
227Fuzz each property of the tests in
228.Pa test
229for ten minutes:
230.Bd -literal -offset indent
231raztest -I src --fuzz 600 test
232.Ed
233.Pp
234A Makefile's check that uses
235.Nm
236where it is installed, and its own loop where it isn't:
237.Bd -literal -offset indent
238check:
239 @if command -v raztest >/dev/null; then raztest -I src test; \e
240 else fail=0; for f in test/*.raz; do \e
241 raz -Werror -I src -o build/t $$f && build/t || fail=1; \e
242 done; test $$fail = 0; fi
243.Ed
244.Sh SEE ALSO
245.Xr raz 1 ,
246.Xr raz-lib 3
247.Sh BUGS
248.Fl j
249doesn't default to the number of processors, which the library can't
250tell yet.