forked from rra/c-tap-harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
280 lines (206 loc) · 12 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
C TAP Harness 3.4
(C harness for running TAP-compliant tests)
Written by Russ Allbery <[email protected]>
Copyright 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
2013, 2014, 2015, 2016 Russ Allbery <[email protected]>. This software is
distributed under a BSD-style license. Please see the LICENSE section
below for more information.
BLURB
C TAP Harness is a pure-C implementation of TAP, the Test Anything
Protocol. TAP is the text-based protocol used by Perl's test suite.
This package provides a harness similar to Perl's Test::Harness for
running tests, with some additional features useful for test suites in
packages that use Autoconf and Automake, and C and shell libraries to
make writing TAP-compliant test programs easier.
DESCRIPTION
This package started as the runtests program I wrote for INN in 2000 to
serve as the basis for a new test suite using a test protocol similar to
that used for Perl modules. When I started maintaining additional C
packages, I adopted runtests for the test suite driver of those as well,
resulting in further improvements but also separate copies of the same
program in different distributions. The C TAP Harness distribution
merges all the various versions into a single code base that all my
packages can pull from.
C TAP Harness provides a full TAP specification (apart from a few
possible edge cases) and has additional special features for supporting
builds outside the source directory. It's mostly useful for packages
using Autoconf and Automake and because it doesn't assume or require
Perl.
The runtests program can be built with knowledge of the source and build
directory and pass that knowledge on to test scripts, and will search
for test scripts in both the source and build directory. This makes it
easier for packages using Autoconf and Automake and supporting
out-of-tree builds to build some test programs, ship others, and run
them all regardless of what tree they're in. It also makes it easier
for test cases to find their supporting files when they run.
Also included in this package are C and shell libraries that provide
utility functions for writing test scripts that use TAP to report
exists.
REQUIREMENTS
C TAP Harness requires a C compiler to build. Any ISO C89 or later C
compiler on a system supporting the Single UNIX Specification, version 3
(SUSv3) should be sufficient. This should not be a problem on any
modern system. The test suite and shell library require a
Bourne-compatible shell. Outside of the test suite, C TAP Harness has
no other prerequisites or requirements.
To run the test suite, you will need Perl plus the Perl module
Test::More, which comes with Perl 5.8 or later.
To test the documentation, you will additionally need Test::Pod and
Test::Spelling, along with a spelling checker supported by
Test::Spelling. Both are available from CPAN. The tests will be
skipped without interfering with the rest of the tests if these modules
are not installed. Spelling tests are disabled by default since
spelling dictionaries differ too much between systems. To enable those
tests, set AUTHOR_TESTING to a true value.
To bootstrap from a Git checkout, or if you change the Automake files
and need to regenerate Makefile.in, you will need Automake 1.11 or
later. For bootstrap or if you change configure.ac or any of the m4
files it includes and need to regenerate configure or config.h.in, you
will need Autoconf 2.64 or later. Perl is also required to generate the
manual page from a fresh Git checkout.
BUILDING AND TESTING
If starting from a Git clone instead of a release tarball, first run:
./autogen
You can build C TAP Harness and run its internal test suite with:
./configure
make
make check
While there is a configure script, it exists just to drive the build
system and do some path substitution and isn't doing portability
probes. Pass --enable-silent-rules to configure for a quieter build
(similar to the Linux kernel).
Use make warnings instead of make to build with full GCC compiler
warnings (requires a relatively current version of GCC).
If a test fails, you can run a single test with verbose output via:
./runtests -b `pwd`/tests -s `pwd`/tests -o <name-of-test>
Do this instead of running the test program directly since it will
ensure that necessary environment variables are set up. You may need to
change the -s option if you build with a separate build directory from
the source directory.
USING THE HARNESS
While there is an install target that installs runtests in the default
binary directory (/usr/local/bin by default) and installs the man pages,
one normally wouldn't install anything from this package. Instead, the
code is intended to be copied into your package and refreshed from the
latest release of C TAP Harness for each release.
You can obviously copy the code and integrate it however works best for
your package and your build system. Here's how I do it for my packages
as an example:
* Create a tests directory and copy tests/runtests.c into it. Create a
tests/tap subdirectory and copy the portions of the TAP library (from
tests/tap) that I need for that package into it. The TAP library is
designed to let you drop in additional source and header files for
additional utility functions that are useful in your package.
* Add code to my top-level Makefile.am (I always use a non-recursive
Makefile with subdir-objects set) to build runtests and the test
library:
check_PROGRAMS = tests/runtests
tests_runtests_CPPFLAGS = -DC_TAP_SOURCE='"$(abs_top_srcdir)/tests"' \
-DC_TAP_BUILD='"$(abs_top_builddir)/tests"'
check_LIBRARIES = tests/tap/libtap.a
tests_tap_libtap_a_CPPFLAGS = -I$(abs_top_srcdir)/tests
tests_tap_libtap_a_SOURCES = tests/tap/basic.c tests/tap/basic.h \
tests/tap/float.c tests/tap/float.h tests/tap/macros.h
Omit float.c and float.h from the last line if your package doesn't
need the is_double function. Building the build and source
directories into runtests will let tests/runtests -o <test> to work
for users without requiring that they set any other variables, even if
they're doing an out-of-source build.
Add additional source files and headers that should go into the TAP
library if you added extra utility functions for your package.
* Add code to Makefile.am to run the test suite:
check-local: $(check_PROGRAMS)
cd tests && ./runtests -l $(abs_top_srcdir)/tests/TESTS
See the Makefile.am in this package for an example (although note that
it keeps runtests in an unusual location).
* List the test programs in the TESTS file. This should have the name
of the test executable with the trailing "-t" or ".t" (you can use
either extension as you prefer) omitted.
Test programs must be executable.
For any test programs that need to be compiled, add build rules for
them in Makefile.am, simliar to:
tests_libtap_c_basic_LDADD = tests/tap/libtap.a
and add them to check_PROGRAMS. If you include the float.c add-on in
your libtap library, you will need to add -lm to the _LDADD setting
for all test programs linked against it.
A more complex example from the remctl package that needs additional
libraries:
tests_client_open_t_LDFLAGS = $(GSSAPI_LDFLAGS)
tests_client_open_t_LDADD = client/libremctl.la tests/tap/libtap.a \
util/libutil.la $(GSSAPI_LIBS)
If the test program doesn't need to be compiled, add it to EXTRA_DIST
so that it will be included in the distribution.
* If you have test programs written in shell, copy tests/tap/libtap.sh
the tap subdirectory of your tests directory and add it to EXTRA_DIST.
Shell programs should start with:
. "${C_TAP_SOURCE}/tap/libtap.sh"
and can then use the functions defined in the library.
* Optionally copy docs/writing-tests into your package somewhere, such
as tests/README, as instructions to contributors on how to write tests
for this framework.
If you have configuration files that the user must create to enable some
of the tests, conventionally they go into tests/config.
If you have data files that your test cases use, conventionally they go
into tests/data. You can then find the data directory relative to the
C_TAP_SOURCE environment variable (set by runtests) in your test
program. If you have data that's compiled or generated by Autoconf, it
will be relative to the BUILD environment variable. Don't forget to add
test data to EXTRA_DIST as necessary.
For more TAP library add-ons, generally ones that rely on additional
portability code not shipped in this package or with narrower uses, see
the rra-c-util package:
http://www.eyrie.org/~eagle/software/rra-c-util/
There are several additional TAP library add-ons in the tests/tap
directory in that package. It's also an example of how to use this test
harness in another package.
SUPPORT
The C TAP Harness web page at:
http://www.eyrie.org/~eagle/software/c-tap-harness/
will always have the current version of this package, the current
documentation, and pointers to any additional resources.
For commentary and bug tracking, I am using the github wiki and issue
tracker at:
http://github.com/rra/c-tap-harness
on an experimental basis. If you like using the github facilities, try
filing issues or adding supplemental documentation there.
SOURCE REPOSITORY
C TAP Harness is maintained using Git. You can access the current
source by cloning the repository at:
git://git.eyrie.org/devel/c-tap-harness.git
or view the repository via the web at:
http://git.eyrie.org/?p=devel/c-tap-harness.git
You can also access it via github at:
http://github.com/rra/c-tap-harness
When contributing modifications, either patches (possibly generated by
git-format-patch) or Git pull requests are welcome.
LICENSE
The C TAP Harness package as a whole is covered by the following
copyright statement and license:
Copyright 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
2013, 2014, 2015, 2016 Russ Allbery <[email protected]>
Copyright 2006, 2007, 2008, 2009, 2011, 2012, 2013
The Board of Trustees of the Leland Stanford Junior University
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
All individual files without an explicit exception below are released
under this license. Some files may have additional copyright holders as
noted in those files. There is detailed information about the licensing
of each file in the LICENSE file in this distribution.
Some files in this distribution are individually released under
different licenses, all of which are compatible with the above general
package license but which may require preservation of additional
notices. All required notices are preserved in the LICENSE file.