xref: /freebsd/contrib/atf/atf-sh/atf-check.1 (revision 730cecb05aaf016ac52ef7cfc691ccec3a0408cd)
1.\"
2.\" Automated Testing Framework (atf)
3.\"
4.\" Copyright (c) 2008 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20.\" IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28.\"
29.Dd June 27, 2010
30.Dt ATF-CHECK 1
31.Os
32.Sh NAME
33.Nm atf-check
34.Nd executes a command and analyzes its results
35.Sh SYNOPSIS
36.Nm
37.Op Fl s Ar qual:value
38.Op Fl o Ar action:arg ...
39.Op Fl e Ar action:arg ...
40.Op Fl x
41.Ar command
42.Nm
43.Fl h
44.Sh DESCRIPTION
45.Nm
46executes a given command and analyzes its results, including
47exit code, stdout and stderr.
48.Pp
49In the first synopsis form,
50.Nm
51will execute the provided command and apply checks specified
52by arguments.
53By default it will act as if it was run with
54.Fl s
55.Ar exit:0
56.Fl o
57.Ar empty
58.Fl e
59.Ar empty .
60Multiple checks for the same output channel are allowed and, if specified,
61their results will be combined as a logical and (meaning that the output must
62match all the provided checks).
63.Pp
64In the second synopsis form,
65.Nm
66will print information about all supported options and their purpose.
67.Pp
68The following options are available:
69.Bl -tag  -width XqualXvalueXX
70.It Fl h
71Shows a short summary of all available options and their purpose.
72.It Fl s Ar qual:value
73Analyzes termination status.
74Must be one of:
75.Bl -tag -width signal:<value> -compact
76.It Ar exit:<value>
77checks that the program exited cleanly and that its exit status is equal to
78.Va value .
79The exit code can be omitted altogether, in which case any clean exit is
80accepted.
81.It Ar ignore
82ignores the exit check.
83.It Ar signal:<value>
84checks that the program exited due to a signal and that the signal that
85terminated it is
86.Va value .
87The signal can be specified both as a number or as a name, or it can also
88be omitted altogether, in which case any signal is accepted.
89.El
90.Pp
91Most of these checkers can be prefixed by the
92.Sq not-
93string, which effectively reverses the check.
94.It Fl o Ar action:arg
95Analyzes standard output.
96Must be one of:
97.Bl -tag -width inline:<value> -compact
98.It Ar empty
99checks that stdout is empty
100.It Ar ignore
101ignores stdout
102.It Ar file:<path>
103compares stdout with given file
104.It Ar inline:<value>
105compares stdout with inline value
106.It Ar match:<regexp>
107looks for a regular expression in stdout
108.It Ar save:<path>
109saves stdout to given file
110.El
111.Pp
112Most of these checkers can be prefixed by the
113.Sq not-
114string, which effectively reverses the check.
115.It Fl e Ar action:arg
116Analyzes standard error (syntax identical to above)
117.It Fl x
118Executes
119.Ar command
120as a shell command line, executing it with the system shell defined by
121.Va ATF_SHELL
122in
123.Xr atf-config 1 .
124You should avoid using this flag if at all possible to prevent shell quoting
125issues.
126.El
127.Sh EXIT STATUS
128.Nm
129exits 0 on success, and other (unspecified) value on failure.
130.Sh EXAMPLES
131.Bd -literal -offset indent
132# Exit code 0, nothing on stdout/stderr
133atf-check 'true'
134
135# Typical usage if failure is expected
136atf-check -s not-exit:0 'false'
137
138# Checking stdout/stderr
139echo foobar >expout
140atf-check -o file:expout -e inline:"xx\etyy\en" \e
141    'echo foobar ; printf "xx\etyy\en" >&2'
142
143# Checking for a crash
144atf-check -s signal:sigsegv my_program
145
146# Combined checks
147atf-check -o match:foo -o not-match:bar echo foo baz
148.Ed
149.Sh SEE ALSO
150.Xr atf-config 1 ,
151.Xr atf 7
152