Import of code from c-tap-harness

This commit updates the code imported from c-tap-harness to
abdb66561ffd4d2f238fdb06f448ccf09d80c059 (release/4.7)

Upstream changes are:

Daniel Collins (1):
      Add is_blob() test function.

Daniel Kahn Gillmor (1):
      LICENSE: use https for all URLs

Daria Brashear (1):
      Add verbose mode environment variable to runtests

Julien ÉLIE (2):
      Document -v in usage and comments of runtests
      Avoid realloc of zero length in tests/runtests.c

Marc Dionne (1):
      Add test_cleanup_register_with_data

Russ Allbery (115):
      clang --analyze cleanups for runtests
      Modernize POD tests
      Update README to my current layout
      Explicitly note that test programs must be executable
      Fix comment typo in tests/runtests.c
      Switch to a copyright-format 1.0 LICENSE file
      Flush harness output after each line
      Show the test count as ? when the plan is deferred
      More correctly backspace over test counts when aborting
      Refactor test list handling
      Allow passing tests on the runtests command line
      Don't allow command-line arguments if a list was given
      Search for tests under the name given as well
      Release 2.0
      Fix backward incompatibility when searching for tests
      Document decision to ignore TAP version directives
      Release 2.1
      Document different runtests behavior in bail handling
      Change exit status of bail to 255
      Release 2.2
      Add a new test_cleanup_register C API
      Add warn_unused_result attributes
      Add portability for warn_unsed_result attributes to tap/macros.h
      Minor coding style fix (spacing) in runtests.c
      Split the runtests usage string for ISO C90 string limits
      Include stddef.h
      Diagnose failure to register the exit handler
      Use diag internally in the basic C TAP library
      Some additional comments about cleanup functions
      Move repetitive printing code in the C TAP library to a macro
      Set a flag when bailing for more correct cleanup
      Change my email address to eagle@eyrie.org
      Release 2.3
      Add diag_file_add and diag_file_remove functions
      Don't die for unknown files passed to diag_file_remove
      Release 2.4
      Update comment about AIX and WCOREDUMP
      Don't test for NULL before calling free
      Be more careful about file descriptors in child processes
      Run cleanup functions in non-primary processes as well
      Release 3.0
      Update collective package copyright notices at start of LICENSE
      Check integer overflows on memory allocation, fix string creation
      Switch POD spelling test to use Lancaster consensus variable
      Add new bnrealloc API for brealloc with checked multiplication
      Rename nrealloc to reallocarray
      Return the test status from test functions
      Fix the overflow check for breallocarray
      Fix the overflow check for xreallocarray in runtests
      Restructure test result reallocation in runtests
      Change diag and sysdiag to always return true
      Release 3.1
      Fix typos in basic.c and basic.h
      Fix usage message when running runtests with no arguments
      Update introductory runtests comments for current syntax
      Add the -l flag to suggested runtests invocation in README
      Support comments and blank lines in test lists
      Release 3.2
      Update licensing information
      Various improvements to verbose support
      Compile warning-free with Clang, check Autoconf macros
      Release 3.3
      Remove unnecessary assert.h include in tap/basic.c
      Fix some additional -v documentation issues
      Rebalance usage to avoid too-long strings
      Fix segfault in runtests with empty test list
      Release 3.4
      Document running autogen if starting from Git
      Rename autogen to bootstrap
      Support and prefer C_TAP_SOURCE and C_TAP_BUILD
      Fix comment typo in tests/runtests.c
      Add missing va_end to is_double
      Release 4.0
      Fix all non-https www.eyrie.org URLs
      Add is_bool C test function
      Add DocKnot metadata and a Markdown README file
      Update documentation for new DocKnot standards
      Release 4.1
      Use more defaults from DocKnot templates
      Fix new fall-through warning in GCC 7
      Use compiler warnings from rra-c-util, fix issues
      Merge pull request #4 from solemnwarning/master
      Coding style fixes and NEWS for is_blob
      Re-enable -Wunknown-pragmas for GCC
      Avoid zero-length realloc allocations in breallocarray
      Update copyright date on tests/runtests.c
      Release 4.2
      Add SPDX-License-Identifier headers to source files
      Add and run new check-cppcheck target
      Fix instructions for running one test
      Identify values as left and right
      Fix is_string comparisons with NULL pointers
      Add support for running tests under valgrind
      Replace putc with fprintf
      Update shared files from rra-c-util
      Release 4.3
      Update NEWS date for 4.3 release
      Collapse some copyright dates
      NEWS and coding style for test_cleanup_register_with_data
      Remove unused variables caught by Clang scan-build
      Update to rra-c-util 8.0
      Fix error checking in bstrndup
      Release 4.4
      Add support for C++
      Document that C TAP Harness can be built as C++
      Release 4.5
      Regenerate README files
      Reformat using clang-format 10
      Update to rra-c-util 8.1
      Release 4.6
      Fix spelling errors caught by codespell
      Protect the test suite against C_TAP_VERBOSE
      Switch to GitHub Actions for CI
      Add NEWS entry for GCC 10 warning fixes
      Release 4.7

Change-Id: I5a78215bf99b53bd848f0fa6bb9092deab38f24e
Reviewed-on: https://gerrit.openafs.org/14294
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
This commit is contained in:
Russ Allbery 2020-08-03 20:59:25 -04:00 committed by Benjamin Kaduk
parent eccd4b9778
commit 3f377aa117
11 changed files with 2225 additions and 782 deletions

View File

@ -1 +1 @@
d3fc03606efc8e76ff34f04470e6133db25a3982
abdb66561ffd4d2f238fdb06f448ccf09d80c059

View File

@ -1,138 +1,154 @@
The C TAP Harness package as a whole is:
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Comment: This file documents the copyright statements and licenses for
every file in this package in a machine-readable format. For a less
detailed, higher-level overview, see README.
.
For any copyright year range specified as YYYY-ZZZZ in this file, the
range specifies every single year in that closed interval.
Copyright 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Russ Allbery <rra@stanford.edu>
Copyright 2006, 2007, 2008, 2009, 2011, 2012
The Board of Trustees of the Leland Stanford Junior University
Files: *
Copyright: 2000-2001, 2004, 2006-2020 Russ Allbery <eagle@eyrie.org>
2001-2002, 2004-2014
The Board of Trustees of the Leland Stanford Junior University
License: Expat
and released under the following license:
Files: .clang-format docs/api/bail.3 docs/api/bail.pod
docs/api/bcalloc_type.3 docs/api/bcalloc_type.pod docs/api/bmalloc.3
docs/api/bmalloc.pod docs/api/breallocarray.3 docs/api/breallocarray.pod
docs/api/diag.3 docs/api/diag.pod docs/api/diag_file_add.3
docs/api/diag_file_add.pod docs/api/is_int.3 docs/api/is_int.pod
docs/api/ok.3 docs/api/ok.pod docs/api/plan.3 docs/api/plan.pod
docs/api/skip.3 docs/api/skip.pod docs/api/skip_all.3
docs/api/skip_all.pod docs/api/test_cleanup_register.3
docs/api/test_cleanup_register.pod docs/api/test_file_path.3
docs/api/test_file_path.pod docs/api/test_tmpdir.3
docs/api/test_tmpdir.pod docs/runtests.1 docs/runtests.pod
docs/writing-tests tests/data/cppcheck.supp
Copyright: 2009-2020 Russ Allbery <eagle@eyrie.org>
License: all-permissive
Copying and distribution of this file, with or without modification, are
permitted in any medium without royalty provided the copyright notice and
this notice are preserved. This file is offered as-is, without any
warranty.
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:
Files: Makefile.in
Copyright: 1994-2020 Free Software Foundation, Inc.
2008-2020 Russ Allbery <eagle@eyrie.org>
License: FSF-unlimited and Expat
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
Files: aclocal.m4
Copyright: 1996-2020 Free Software Foundation, Inc.
License: FSF-unlimited
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.
Files: build-aux/ar-lib build-aux/compile build-aux/depcomp
build-aux/missing
Copyright: 1996-2020 Free Software Foundation, Inc.
License: GPL-2+ with Autoconf exception or Expat
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.
Files: build-aux/install-sh
Copyright: 1994 X Consortium
License: X11
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 X CONSORTIUM 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.
.
Except as contained in this notice, the name of the X Consortium shall
not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization from the X
Consortium.
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 this file. Of the files intended to be
copied into other packages, only docs/writing-tests has a different
license notice, and its requirements are met by preserving the license
section of that document in any derivative works.
Files: configure
Copyright: 1992-1996, 1998-2012 Free Software Foundation, Inc.
License: FSF-configure
This script is free software; the Free Software Foundation gives unlimited
permission to copy, distribute and modify it.
Collected copyright notices for the entire package:
Files: m4/cc-flags.m4
Copyright: 2006, 2009, 2016 Internet Systems Consortium, Inc.
2016-2020 Russ Allbery <eagle@eyrie.org>
License: ISC
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
.
THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Copyright 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Russ Allbery <rra@stanford.edu>
Copyright 2006, 2007, 2008, 2009, 2011, 2012
The Board of Trustees of the Leland Stanford Junior University
Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
Copyright 1994 X Consortium
Files: m4/clang.m4
Copyright: 2015 Russ Allbery <eagle@eyrie.org>
License: unlimited
This file is free software; the authors give unlimited permission to copy
and/or distribute it, with or without modifications, as long as this
notice is preserved.
The file docs/writing-tests is released under the following license:
License: Expat
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.
Copying and distribution of this file, with or without modification, are
permitted in any medium without royalty provided the copyright notice
and this notice are preserved. This file is offered as-is, without any
warranty.
License: FSF-unlimited
This file is free software; the Free Software Foundation gives unlimited
permission to copy and/or distribute it, with or without modifications, as
long as this notice is preserved.
.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The files Makefile.in and aclocal.m4 are generated by GNU Automake and
released under the following copyright and license:
License: GPL-2+ with Autoconf exception
This file is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
.
You should have received a copy of the GNU General Public License along
with this program. If not, see <https://www.gnu.org/licenses/>.
.
As a special exception to the GNU General Public License, if you
distribute this file as part of a program that contains a configuration
script generated by Autoconf, you may include it under the same
distribution terms that you use for the rest of that program.
Comment: The option described in the license has been accepted and these
files are distributed under the same terms as the package as a whole, as
described at the top of this file.
Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
Foundation, Inc. This file is free software; the Free Software
Foundation gives unlimited permission to copy and/or distribute it, with
or without modifications, as long as this notice is preserved.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY, to the extent permitted by law; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
The file configure is generated by GNU Autoconf and is released under the
following copyright and license:
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
Foundation, Inc. This configure script is free software; the Free
Software Foundation gives unlimited permission to copy, distribute and
modify it.
The files build-aux/compile, build-aux/depcomp, and build-aux/missing are
taken from GNU Automake and are released under the following copyright and
license:
Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
As a special exception to the GNU General Public License, if you
distribute this file as part of a program that contains a configuration
script generated by Autoconf, you may include it under the same
distribution terms that you use for the rest of that program.
For the C TAP Harness distribution, the option described in the last
paragraph has been accepted and these files are distributed under the same
terms as the C TAP Harness package as a whole, as described at the top of
this file.
The file build-aux/install-sh is released under the following copyright
and license:
Copyright (C) 1994 X Consortium
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 X CONSORTIUM 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.
Except as contained in this notice, the name of the X Consortium shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from the X Consortium.
FSF changes to this file are in the public domain.

View File

@ -1,5 +1,275 @@
User-Visible C TAP Harness Changes
C TAP Harness 4.7 (2020-05-16)
Allow the package test suite to be run with C_TAP_VERBOSE without
breaking test results via inheritance of that setting.
Fix warnings with GCC 10.
C TAP Harness 4.6 (2020-01-07)
Reformat all C source using clang-format 10 and the formatting rules
specified in .clang-format.
Update to rra-c-util 8.1:
* Drop support for Perl versions prior to Perl 5.8.
C TAP Harness 4.5 (2019-08-31)
Add new bcalloc_type and breallocarray_type macros that take a type
instead of a size as their third argument and cast the return value to
a pointer to that type. These are more friendly to C++ code than
C-style allocation functions returning void *.
The test harness and libtap C library can now alternatively be
compiled with a C++ compiler, making it easier to incorporate them
into a C++ project. Thanks to Peter Paris for the initial report.
C TAP Harness 4.4 (2018-12-25)
Add test_cleanup_register_with_data to the C TAP library. This is the
same as test_cleanup_register except takes a generic pointer, which is
then passed to the cleanup function as a third argument. This should
have been the only API from the beginning, but test_cleanup_register
is preserved for backward compatibility. Patch from Marc Dionne.
Fix error checking for malloc failure in bstrndup function (caught by
cppcheck).
Update to rra-c-util 8.0:
* Skip tests requiring Test::More if it isn't available.
* Check for pre-SPDX license grant strings.
* Improved test for obsolete strings in package source files.
C TAP Harness 4.3 (2018-05-06)
Add support for valgrind and libtool test options in test lists. Test
lists now take a space-separated set of options after the test name.
If the valgrind option is present and C_TAP_VALGRIND is set in the
environment, the test will be run by passing it as an option to the
command given in C_TAP_VALGRIND. If the libtool option is also set,
valgrind will be run via the libtool script set in C_TAP_LIBTOOL,
using --mode=execute, so that valgrind will run on the underlying
binary and not the libtool shell wrapper.
On test failures, report the values as left and right instead of
wanted and seen. This idea is stolen from the Rust assert framework.
It avoids having to care about the order in which values are passed
into the test functions.
Fix is_string comparisons involving NULL pointers so that the string
"(null)" will no longer compare equal to NULL (although the diagnostic
output on test failure is still mildly confusing).
Add new check-cppcheck target that runs cppcheck on all source code,
and fix one unnecessary check for NULL that it uncovered.
Add SPDX-License-Identifier headers to all substantial source files,
and add a test to check for them. This imports more supporting test
machinery whose canonical home is in rra-c-util. If you want to use
files in tests/tap/perl, copy them from rra-c-util instead of this
package.
C TAP Harness now imports the Perl test modules from rra-c-util to
support some checks, so tests/docs/pod-spelling-t and tests/docs/pod-t
have been updated to the versions from rra-c-util. Projects that were
previously copying those tests should be able to continue to use them,
but will now need the modules in tests/tap/perl (the canonical version
of which are maintained in rra-c-util).
C TAP Harness 4.2 (2017-12-30)
Add is_blob function to the C test library. This tests whether two
regions of memory are identical, similar to ok(memcmp(...)) but
reporting where the regions differ. Patch from Daniel Collins.
Avoid zero-length realloc allocations in breallocarray.
Fix new fall-through warning in GCC 7.
Switch to the compiler warning Autoconf macros and warning set from
rra-c-util with the addition of -ansi -pedantic for GCC and
-pedantic-errors for Clang. Add some casts to fix warnings from
-Wconversion, and suppress some spurious warnings from Clang about
tests/tap/float.c.
C TAP Harness 4.1 (2016-12-23)
Add is_bool function to the C test library. This compares its two
arguments only for their truthfulness. is_bool(true, arg) is the same
as ok(arg), but there are times (such as when testing for a false
value) where this allows for clearer code or clearer output.
C TAP Harness 4.0 (2016-05-07)
When building runtests, one must now set the C_TAP_SOURCE and
C_TAP_BUILD C preprocessor symbols to the source and build
directories, instead of SOURCE and BUILD. An updated Makefile.am
recipe is documented in README.
runtests now sets C_TAP_SOURCE and C_TAP_BUILD in the environment in
addition to SOURCE and BUILD. All test programs using this harness
should switch to the new C_TAP_SOURCE and C_TAP_BUILD environment
variables. SOURCE and BUILD are very generic and may conflict with
other programs and uses, and setting them will be removed in a later
version.
The TAP test libraries (C and shell) now use C_TAP_SOURCE and
C_TAP_BUILD environment variables instead of SOURCE and BUILD for the
test_file_path() and test_tmpdir() functions. If you were using these
libraries with another test harness, you will need to set the new
environment variables.
Fix missing va_end() call in is_double(), which would have caused
compilation failures or other problems on some platforms. Thanks,
Julien ÉLIE.
Rename the script to bootstrap from a Git checkout to bootstrap,
matching the emerging consensus in the Autoconf world.
C TAP Harness 3.4 (2015-08-18)
Fix segfault in runtests when given a test list containing only
comments and blank lines. Thanks, aherbert.
C TAP Harness 3.3 (2015-04-26)
If runtests is given the -v option, or if the environment variable
C_TAP_VERBOSE is set, the complete output of each test program will be
shown instead of the summary of total and failing tests. Based on
work by D. Brashear.
C TAP Harness now compiles cleanly with Clang with -Weverything
-Wno-padded -pedantic-errors, and automatically detects Clang and
switches warning flags for make warnings.
C TAP Harness 3.2 (2014-12-25)
The runtests harness now supports ignoring comments and blank lines in
the test list specified with -l. Leading whitespace before the test
name is also ignored.
C TAP Harness 3.1 (2014-07-02)
ok, okv, and all is_* functions now return true if the test succeeds
and false if it fails, matching the return status of the corresponding
Perl Test::More functions. This allows more succinct code when the
actions of a test program should vary based on the success or failure
of previous tests. Based on a patch by Peter Pöschl.
diag and sysdiag now always return 1, making it easier to insert calls
into compound statements when debugging tests. Based on a patch by
Peter Pöschl.
Add new breallocarray API that does the same as realloc but takes
calloc-style arguments to specify the size and checks internally for
integer overflow. Inspired by the OpenBSD reallocarray function.
Check for integer overflows on memory allocation. All the possible
issues for this code are rather theoretical, but one may as well
strive for correctness.
Replace all uses of sprintf with a simpler string concatenation
function that checks for allocation overflow. (The standards
assumptions for this package don't permit assuming asprintf or a
sufficiently non-broken snprintf to simulate asprintf.)
C TAP Harness 3.0 (2014-01-28)
The test_cleanup_register API has changed in this release. Cleanup
functions must now take two parameters, not one, and are called from
all test processes, not just the primary one. The new second argument
indicates whether the cleanup function was called in the primary
process (the one in which plan or plan_lazy was called). External
resources, such as files, should generally only be freed when the
cleanup function is called in the primary process, but tests may want
to free internal resources, like memory, in all processes to ease
analysis with tools like valgrind.
When running test programs from a list, reopen standard input for each
program to /dev/null, and be more careful about closing all duplicates
of file descriptors left behind after setting up standard output and
standard error so that extraneous file descriptors aren't leaked to
the child process.
C TAP Harness 2.4 (2013-12-25)
Add new diag_file_add and diag_file_remove APIs to the basic C TAP
library. These functions manage a list of registered file that
contains supplemental diagnostic information. Each registered file is
checked before each output function for any new lines, and any lines
are displayed as if they'd been passed to diag(). This can be useful
if, for example, the test involves a background daemon whose output
can be logged to a disk file.
C TAP Harness 2.3 (2013-11-13)
Add new test_cleanup_register API to the basic C TAP library. This
registers a C callback function that's called during exit from the
test and passed in a boolean argument indicating whether the test
succeeded or failed.
Suppress lazy plans and the summary of tests at the end of a test
program if the program aborted with bail or sysbail.
Add warn_unused_result gcc attributes to the C TAP library functions
where ignoring the return value is almost certainly a bug (such as all
the malloc functions).
Add portability for warn_unsed_result attributes to tap/macros.h.
C TAP Harness 2.2 (2013-08-14)
bail and sysbail now exit with status 255 to match the behavior of
BAIL_OUT in Perl's Test::More.
Document that runtests handling of test cases that bail out differs
from the documented behavior of BAIL_OUT in Perl's Test::More and the
behavior of prove, and document why.
C TAP Harness 2.1 (2013-03-15)
When locating test programs, try a suffix (-t, .t, or no suffix) with
all bases before moving on to the next suffix. The behavior in the
previous release was not backward-compatible: it would find the
unsuffixed helper program in the build directory instead of the actual
test in the source directory for some rra-c-util tests when the build
directory and the source directory weren't the same.
Document that TAP version directives in the TAP output are ignored.
C TAP Harness 2.0 (2013-03-14)
The default behavior of tests/runtests has changed to make it act more
like other test drivers. Now, to provide a file containing a list of
tests, use the -l option. Existing users should add -l to the command
line in front of the test list. Otherwise, the command-line arguments
are taken as tests to run, as if they were all listed in a test list
file.
runtests now tries the test name without any extension if the test
name with either -t or .t was not found. It also does not consider a
directory to be a valid test when searching for the executable, even
if the directory is executable.
Flush the harness output after each test. This effectively implements
line buffering even when standard output is not a terminal and
therefore output isn't flushed after each line of test output.
When displaying partial status of tests with a deferred plan, show the
total number of tests as ? rather than the number of tests seen so
far. This matches the behavior of Perl's prove utility.
More correctly handle backspacing over the test count in several abort
cases when reporting status to a terminal.
Add GCC annotations to some internal functions in runtests to help
clang --analyze better understand code correctness. Remove a dead
store caught by clang --analyze.
C TAP Harness 1.12 (2012-05-11)
Fix additional uses of local in the shell TAP library for portability
@ -54,7 +324,7 @@ C TAP Harness 1.11 (2012-04-25)
Move the is_double C TAP test function into a separate source file.
Including this function may require linking with libm on some
platforms, which is undesireable if the package otherwise doesn't use
platforms, which is undesirable if the package otherwise doesn't use
math functions. The new tests/tap/float.c and tests/tap/float.h files
need only be included in a package that wants to do floating point
tests. Users of is_double will now need to include tests/tap/float.h

View File

@ -1,12 +1,12 @@
C TAP Harness 1.12
C TAP Harness 4.7
(C harness for running TAP-compliant tests)
Maintained by Russ Allbery <eagle@eyrie.org>
Written by Russ Allbery <rra@stanford.edu>
Copyright 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Russ Allbery <rra@stanford.edu>. This software is distributed under a
BSD-style license. Please see the file LICENSE in the distribution for
more information.
Copyright 2000-2001, 2004, 2006-2020 Russ Allbery <eagle@eyrie.org>.
Copyright 2006-2009, 2011-2013 The Board of Trustees of the Leland
Stanford Junior University. This software is distributed under a
BSD-style license. Please see the section LICENSE below for more
information.
BLURB
@ -28,7 +28,7 @@ DESCRIPTION
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
C TAP Harness provides a full TAP specification driver (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
@ -44,7 +44,11 @@ DESCRIPTION
Also included in this package are C and shell libraries that provide
utility functions for writing test scripts that use TAP to report
exists.
results. The C library also provides a variety of utility functions
useful for test programs running as part of an Automake-built package:
finding test data files, creating temporary files, reporting output from
external programs running in the background, and similar common
problems.
REQUIREMENTS
@ -55,50 +59,68 @@ REQUIREMENTS
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 modules
Test::More and Test::Pod. Test::More comes with Perl 5.8 and later.
Test::Pod is available from CPAN and currently must be installed
separately, but the POD tests will be skipped without interfering with
the rest of the tests if it's not installed.
To check spelling in the POD documentation, Pod::Spell (available from
CPAN) and either aspell or ispell with the american dictionary are also
required. The user's path is searched for aspell or ispell and aspell
is preferred. Spelling tests are disabled by default since spelling
dictionaries differ too much between systems. To enable those tests,
set RRA_MAINTAINER_TESTS to a true value.
C TAP Harness can also be built with a C++ compiler and should be
similarly portable to any recent C++ compiler, although it is only
tested with g++.
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.
will need Autoconf 2.64 or later. Perl is also required to generate
manual pages from a fresh Git checkout.
BUILDING AND TESTING
BUILDING
You can build C TAP Harness and run its internal test suite with:
You can build C TAP Harness with the standard commands:
./configure
make
If you are building from a Git clone, first run ./bootstrap in the
source directory to generate the build files. Building outside of the
source directory is also supported, if you wish, by creating an empty
directory and then running configure with the correct relative path.
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
compiler warnings (requires either GCC or Clang and may require a
relatively current version of the compiler).
Installing C TAP Harness is not normally done. Instead, see the section
on using the harness below.
TESTING
C TAP Harness comes with a comprehensive test suite, which you can run
after building with:
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>
tests/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.
change the -s option argument if you build with a separate build
directory from the source directory.
To run the test suite, you will need Perl 5.8 or later. The following
additional Perl modules will be used by the test suite if present:
* Test::Pod
* Test::Spelling
All are available on CPAN. Those tests will be skipped if the modules
are not available.
To enable tests that don't detect functionality problems but are used to
sanity-check the release, set the environment variable RELEASE_TESTING
to a true value. To enable tests that may be sensitive to the local
environment or that produce a lot of false positives without uncovering
many problems, set the environment variable AUTHOR_TESTING to a true
value.
USING THE HARNESS
@ -123,8 +145,8 @@ USING THE HARNESS
library:
check_PROGRAMS = tests/runtests
tests_runtests_CPPFLAGS = -DSOURCE='"$(abs_top_srcdir)/tests"' \
-DBUILD='"$(abs_top_builddir)/tests"'
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 \
@ -132,8 +154,8 @@ USING THE HARNESS
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
directories into runtests will let tests/runtests -o <test> 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
@ -142,16 +164,18 @@ USING THE HARNESS
* Add code to Makefile.am to run the test suite:
check-local: $(check_PROGRAMS)
cd tests && ./runtests $(abs_top_srcdir)/tests/TESTS
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).
See the Makefile.am in this package for an example.
* 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. For any test programs that
need to be compiled, add build rules for them in Makefile.am, simliar
to:
* List the test programs in the tests/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, similar to:
tests_libtap_c_basic_LDADD = tests/tap/libtap.a
@ -173,7 +197,7 @@ USING THE HARNESS
the tap subdirectory of your tests directory and add it to EXTRA_DIST.
Shell programs should start with:
. "${SOURCE}/tap/libtap.sh"
. "${C_TAP_SOURCE}/tap/libtap.sh"
and can then use the functions defined in the library.
@ -186,43 +210,93 @@ USING THE HARNESS
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
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.
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:
the rra-c-util package [1]. 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.
http://www.eyrie.org/~eagle/software/rra-c-util/
[1] https://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.
HOMEPAGE AND SOURCE REPOSITORY
SUPPORT
The C TAP Harness web page at:
http://www.eyrie.org/~eagle/software/c-tap-harness/
https://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.
C TAP Harness is maintained using Git. You can access the current
source by cloning the repository at:
For bug tracking, use the issue tracker on GitHub:
git://git.eyrie.org/devel/c-tap-harness.git
https://github.com/rra/c-tap-harness/issues
However, please be aware that I tend to be extremely busy and work
projects often take priority. I'll save your report and get to it as
soon as I can, but it may take me a couple of months.
SOURCE REPOSITORY
C TAP Harness is maintained using Git. You can access the current
source on GitHub at:
https://github.com/rra/c-tap-harness
or by cloning the repository at:
https://git.eyrie.org/git/devel/c-tap-harness.git
or view the repository via the web at:
http://git.eyrie.org/?p=devel/c-tap-harness.git
https://git.eyrie.org/?p=devel/c-tap-harness.git
C TAP Harness is also available via github at:
The eyrie.org repository is the canonical one, maintained by the author,
but using GitHub is probably more convenient for most purposes. Pull
requests are gratefully reviewed and normally accepted.
http://github.com/rra/c-tap-harness
LICENSE
and the github wiki and issue tracker are available on an experimental
basis. If you like using the github facilities, try filing issues or
adding supplemental documentation there.
The C TAP Harness package as a whole is covered by the following
copyright statement and license:
Copyright 2000-2001, 2004, 2006-2020 Russ Allbery <eagle@eyrie.org>
Copyright 2006-2009, 2011-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.
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, and detailed information about the
licensing of each file, are recorded in the LICENSE file.
Files covered by a license with an assigned SPDX License Identifier
include SPDX-License-Identifier tags to enable automated processing of
license information. See https://spdx.org/licenses/ for more
information.
For any copyright range specified by files in this package as YYYY-ZZZZ,
the range specifies every single year in that closed interval.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,10 +2,11 @@
* Basic utility routines for the TAP protocol.
*
* This file is part of C TAP Harness. The current version plus supporting
* documentation is at <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
* documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
* Copyright 2009, 2010, 2011, 2012 Russ Allbery <rra@stanford.edu>
* Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011, 2012
* Written by Russ Allbery <eagle@eyrie.org>
* Copyright 2009-2019 Russ Allbery <eagle@eyrie.org>
* Copyright 2001-2002, 2004-2008, 2011-2012, 2014
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@ -25,14 +26,16 @@
* 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.
*
* SPDX-License-Identifier: MIT
*/
#ifndef TAP_BASIC_H
#define TAP_BASIC_H 1
#include <stdarg.h> /* va_list */
#include <stddef.h> /* size_t */
#include <tests/tap/macros.h>
#include <stdarg.h> /* va_list */
#include <sys/types.h> /* size_t */
/*
* Used for iterating through arrays. ARRAY_SIZE returns the number of
@ -40,8 +43,8 @@
* ARRAY_END returns a pointer to the element past the end (ISO C99 makes it
* legal to refer to such a pointer as long as it's never dereferenced).
*/
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#define ARRAY_END(array) (&(array)[ARRAY_SIZE(array)])
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#define ARRAY_END(array) (&(array)[ARRAY_SIZE(array)])
BEGIN_DECLS
@ -55,7 +58,7 @@ extern unsigned long testnum;
void plan(unsigned long count);
/*
* Prepare for lazy planning, in which the plan will be printed automatically
* Prepare for lazy planning, in which the plan will be printed automatically
* at the end of the test program.
*/
void plan_lazy(void);
@ -67,27 +70,40 @@ void skip_all(const char *format, ...)
/*
* Basic reporting functions. The okv() function is the same as ok() but
* takes the test description as a va_list to make it easier to reuse the
* reporting infrastructure when writing new tests.
* reporting infrastructure when writing new tests. ok() and okv() return the
* value of the success argument.
*/
void ok(int success, const char *format, ...)
int ok(int success, const char *format, ...)
__attribute__((__format__(printf, 2, 3)));
void okv(int success, const char *format, va_list args);
void skip(const char *reason, ...)
__attribute__((__format__(printf, 1, 2)));
int okv(int success, const char *format, va_list args)
__attribute__((__format__(printf, 2, 0)));
void skip(const char *reason, ...) __attribute__((__format__(printf, 1, 2)));
/* Report the same status on, or skip, the next count tests. */
void ok_block(unsigned long count, int success, const char *format, ...)
/*
* Report the same status on, or skip, the next count tests. ok_block()
* returns the value of the success argument.
*/
int ok_block(unsigned long count, int success, const char *format, ...)
__attribute__((__format__(printf, 3, 4)));
void skip_block(unsigned long count, const char *reason, ...)
__attribute__((__format__(printf, 2, 3)));
/* Check an expected value against a seen value. */
void is_int(long wanted, long seen, const char *format, ...)
/*
* Compare two values. Returns true if the test passes and false if it fails.
* is_bool takes an int since the bool type isn't fully portable yet, but
* interprets both arguments for their truth value, not for their numeric
* value.
*/
int is_bool(int, int, const char *format, ...)
__attribute__((__format__(printf, 3, 4)));
void is_string(const char *wanted, const char *seen, const char *format, ...)
int is_int(long, long, const char *format, ...)
__attribute__((__format__(printf, 3, 4)));
void is_hex(unsigned long wanted, unsigned long seen, const char *format, ...)
int is_string(const char *, const char *, const char *format, ...)
__attribute__((__format__(printf, 3, 4)));
int is_hex(unsigned long, unsigned long, const char *format, ...)
__attribute__((__format__(printf, 3, 4)));
int is_blob(const void *, const void *, size_t, const char *format, ...)
__attribute__((__format__(printf, 4, 5)));
/* Bail out with an error. sysbail appends strerror(errno). */
void bail(const char *format, ...)
@ -96,39 +112,81 @@ void sysbail(const char *format, ...)
__attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
/* Report a diagnostic to stderr prefixed with #. */
void diag(const char *format, ...)
int diag(const char *format, ...)
__attribute__((__nonnull__, __format__(printf, 1, 2)));
void sysdiag(const char *format, ...)
int sysdiag(const char *format, ...)
__attribute__((__nonnull__, __format__(printf, 1, 2)));
/*
* Register or unregister a file that contains supplementary diagnostics.
* Before any other output, all registered files will be read, line by line,
* and each line will be reported as a diagnostic as if it were passed to
* diag(). Nul characters are not supported in these files and will result in
* truncated output.
*/
void diag_file_add(const char *file) __attribute__((__nonnull__));
void diag_file_remove(const char *file) __attribute__((__nonnull__));
/* Allocate memory, reporting a fatal error with bail on failure. */
void *bcalloc(size_t, size_t)
__attribute__((__alloc_size__(1, 2), __malloc__));
__attribute__((__alloc_size__(1, 2), __malloc__, __warn_unused_result__));
void *bmalloc(size_t)
__attribute__((__alloc_size__(1), __malloc__));
__attribute__((__alloc_size__(1), __malloc__, __warn_unused_result__));
void *breallocarray(void *, size_t, size_t)
__attribute__((__alloc_size__(2, 3), __malloc__, __warn_unused_result__));
void *brealloc(void *, size_t)
__attribute__((__alloc_size__(2), __malloc__));
__attribute__((__alloc_size__(2), __malloc__, __warn_unused_result__));
char *bstrdup(const char *)
__attribute__((__malloc__, __nonnull__));
__attribute__((__malloc__, __nonnull__, __warn_unused_result__));
char *bstrndup(const char *, size_t)
__attribute__((__malloc__, __nonnull__));
__attribute__((__malloc__, __nonnull__, __warn_unused_result__));
/*
* Find a test file under BUILD or SOURCE, returning the full path. The
* returned path should be freed with test_file_path_free().
* Macros that cast the return value from b* memory functions, making them
* usable in C++ code and providing some additional type safety.
*/
#define bcalloc_type(n, type) ((type *) bcalloc((n), sizeof(type)))
#define breallocarray_type(p, n, type) \
((type *) breallocarray((p), (n), sizeof(type)))
/*
* Find a test file under C_TAP_BUILD or C_TAP_SOURCE, returning the full
* path. The returned path should be freed with test_file_path_free().
*/
char *test_file_path(const char *file)
__attribute__((__malloc__, __nonnull__));
__attribute__((__malloc__, __nonnull__, __warn_unused_result__));
void test_file_path_free(char *path);
/*
* Create a temporary directory relative to BUILD and return the path. The
* returned path should be freed with test_tmpdir_free.
* Create a temporary directory relative to C_TAP_BUILD and return the path.
* The returned path should be freed with test_tmpdir_free().
*/
char *test_tmpdir(void)
__attribute__((__malloc__));
char *test_tmpdir(void) __attribute__((__malloc__, __warn_unused_result__));
void test_tmpdir_free(char *path);
/*
* Register a cleanup function that is called when testing ends. All such
* registered functions will be run during atexit handling (and are therefore
* subject to all the same constraints and caveats as atexit functions).
*
* The function must return void and will be passed two arguments: an int that
* will be true if the test completed successfully and false otherwise, and an
* int that will be true if the cleanup function is run in the primary process
* (the one that called plan or plan_lazy) and false otherwise. If
* test_cleanup_register_with_data is used instead, a generic pointer can be
* provided and will be passed to the cleanup function as a third argument.
*
* test_cleanup_register_with_data is the better API and should have been the
* only API. test_cleanup_register was an API error preserved for backward
* cmpatibility.
*/
typedef void (*test_cleanup_func)(int, int);
typedef void (*test_cleanup_func_with_data)(int, int, void *);
void test_cleanup_register(test_cleanup_func) __attribute__((__nonnull__));
void test_cleanup_register_with_data(test_cleanup_func_with_data, void *)
__attribute__((__nonnull__));
END_DECLS
#endif /* TAP_BASIC_H */

View File

@ -8,9 +8,9 @@
* otherwise care about floating point.
*
* This file is part of C TAP Harness. The current version plus supporting
* documentation is at <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
* documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
* Copyright 2008, 2010, 2012 Russ Allbery <rra@stanford.edu>
* Copyright 2008, 2010, 2012-2019 Russ Allbery <eagle@eyrie.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -29,13 +29,15 @@
* 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.
*
* SPDX-License-Identifier: MIT
*/
/* Required for isnan() and isinf(). */
#if defined(__STRICT_ANSI__) || defined(PEDANTIC)
# ifndef _XOPEN_SOURCE
# define _XOPEN_SOURCE 600
# endif
# ifndef _XOPEN_SOURCE
# define _XOPEN_SOURCE 600
# endif
#endif
#include <math.h>
@ -46,22 +48,49 @@
#include <tests/tap/float.h>
/*
* Takes an expected double and a seen double and assumes the test passes if
* those two numbers are within delta of each other.
* Clang 4.0.1 gets very confused by this file and produces warnings about
* floating point implicit conversion from the isnan() and isinf() macros.
*/
void
is_double(double wanted, double seen, double epsilon, const char *format, ...)
#if defined(__llvm__) || defined(__clang__)
# pragma clang diagnostic ignored "-Wconversion"
# pragma clang diagnostic ignored "-Wdouble-promotion"
#endif
/*
* Returns true if the two doubles are equal infinities, false otherwise.
* This requires a bit of machination since isinf is not required to return
* different values for positive and negative infinity, and we're trying to
* avoid direct comparisons between floating point numbers.
*/
static int
is_equal_infinity(double left, double right)
{
if (!isinf(left) || !isinf(right))
return 0;
return !!(left < 0) == !!(right < 0);
}
/*
* Takes two doubles and requires they be within epsilon of each other.
*/
int
is_double(double left, double right, double epsilon, const char *format, ...)
{
va_list args;
int success;
va_start(args, format);
fflush(stderr);
if ((isnan(wanted) && isnan(seen))
|| (isinf(wanted) && isinf(seen) && wanted == seen)
|| fabs(wanted - seen) <= epsilon)
if ((isnan(left) && isnan(right)) || is_equal_infinity(left, right)
|| fabs(left - right) <= epsilon) {
success = 1;
okv(1, format, args);
else {
printf("# wanted: %g\n# seen: %g\n", wanted, seen);
} else {
success = 0;
diag(" left: %g", left);
diag("right: %g", right);
okv(0, format, args);
}
va_end(args);
return success;
}

View File

@ -2,9 +2,9 @@
* Floating point check function for the TAP protocol.
*
* This file is part of C TAP Harness. The current version plus supporting
* documentation is at <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
* documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
* Copyright 2008, 2010, 2012 Russ Allbery <rra@stanford.edu>
* Copyright 2008, 2010, 2012, 2014, 2018 Russ Allbery <eagle@eyrie.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -23,6 +23,8 @@
* 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.
*
* SPDX-License-Identifier: MIT
*/
#ifndef TAP_FLOAT_H
@ -32,9 +34,8 @@
BEGIN_DECLS
/* Check an expected value against a seen value within epsilon. */
void is_double(double wanted, double seen, double epsilon,
const char *format, ...)
/* Compare two values within epsilon. */
int is_double(double, double, double epsilon, const char *format, ...)
__attribute__((__format__(printf, 4, 5)));
END_DECLS

View File

@ -7,11 +7,11 @@
#
# This file provides a TAP-compatible shell function library useful for
# writing test cases. It is part of C TAP Harness, which can be found at
# <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
# <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
#
# Written by Russ Allbery <rra@stanford.edu>
# Copyright 2009, 2010, 2011, 2012 Russ Allbery <rra@stanford.edu>
# Copyright 2006, 2007, 2008
# Written by Russ Allbery <eagle@eyrie.org>
# Copyright 2009-2012, 2016 Russ Allbery <eagle@eyrie.org>
# Copyright 2006-2008, 2013
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
@ -31,6 +31,8 @@
# 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.
#
# SPDX-License-Identifier: MIT
# Print out the number of test cases we expect to run.
plan () {
@ -204,7 +206,7 @@ strip_colon_error() {
# Bail out with an error message.
bail () {
echo 'Bail out!' "$@"
exit 1
exit 255
}
# Output a diagnostic on standard error, preceded by the required # mark.
@ -212,32 +214,32 @@ diag () {
echo '#' "$@"
}
# Search for the given file first in $BUILD and then in $SOURCE and echo the
# path where the file was found, or the empty string if the file wasn't
# found.
# Search for the given file first in $C_TAP_BUILD and then in $C_TAP_SOURCE
# and echo the path where the file was found, or the empty string if the file
# wasn't found.
#
# This macro uses puts, so don't run it using backticks inside double quotes
# or bizarre quoting behavior will happen with Solaris sh.
test_file_path () {
if [ -n "$BUILD" ] && [ -f "$BUILD/$1" ] ; then
puts "$BUILD/$1"
elif [ -n "$SOURCE" ] && [ -f "$SOURCE/$1" ] ; then
puts "$SOURCE/$1"
if [ -n "$C_TAP_BUILD" ] && [ -f "$C_TAP_BUILD/$1" ] ; then
puts "$C_TAP_BUILD/$1"
elif [ -n "$C_TAP_SOURCE" ] && [ -f "$C_TAP_SOURCE/$1" ] ; then
puts "$C_TAP_SOURCE/$1"
else
echo ''
fi
}
# Create $BUILD/tmp for use by tests for storing temporary files and return
# the path (via standard output).
# Create $C_TAP_BUILD/tmp for use by tests for storing temporary files and
# return the path (via standard output).
#
# This macro uses puts, so don't run it using backticks inside double quotes
# or bizarre quoting behavior will happen with Solaris sh.
test_tmpdir () {
if [ -z "$BUILD" ] ; then
if [ -z "$C_TAP_BUILD" ] ; then
tap_tmpdir="./tmp"
else
tap_tmpdir="$BUILD"/tmp
tap_tmpdir="$C_TAP_BUILD"/tmp
fi
if [ ! -d "$tap_tmpdir" ] ; then
mkdir "$tap_tmpdir" || bail "Error creating $tap_tmpdir"

View File

@ -6,9 +6,9 @@
* everyone can pull them in.
*
* This file is part of C TAP Harness. The current version plus supporting
* documentation is at <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
* documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
* Copyright 2008, 2012 Russ Allbery <rra@stanford.edu>
* Copyright 2008, 2012-2013, 2015 Russ Allbery <eagle@eyrie.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -27,6 +27,8 @@
* 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.
*
* SPDX-License-Identifier: MIT
*/
#ifndef TAP_MACROS_H
@ -40,9 +42,9 @@
* the other attributes to work with GCC versions between 2.7 and 2.96.
*/
#ifndef __attribute__
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
# define __attribute__(spec) /* empty */
# endif
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
# define __attribute__(spec) /* empty */
# endif
#endif
/*
@ -53,9 +55,18 @@
* variadic macro support.
*/
#if !defined(__attribute__) && !defined(__alloc_size__)
# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
# define __alloc_size__(spec, args...) /* empty */
# endif
# if defined(__GNUC__) && !defined(__clang__)
# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
# define __alloc_size__(spec, args...) /* empty */
# endif
# endif
#endif
/* Suppress __warn_unused_result__ if gcc is too old. */
#if !defined(__attribute__) && !defined(__warn_unused_result__)
# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
# define __warn_unused_result__ /* empty */
# endif
#endif
/*
@ -65,7 +76,7 @@
* compilation context, but there's no push and pop available.
*/
#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__))
# pragma GCC diagnostic ignored "-Wattributes"
# pragma GCC diagnostic ignored "-Wattributes"
#endif
/* Used for unused parameters to silence gcc warnings. */
@ -78,11 +89,11 @@
#undef BEGIN_DECLS
#undef END_DECLS
#ifdef __cplusplus
# define BEGIN_DECLS extern "C" {
# define END_DECLS }
# define BEGIN_DECLS extern "C" {
# define END_DECLS }
#else
# define BEGIN_DECLS /* empty */
# define END_DECLS /* empty */
# define BEGIN_DECLS /* empty */
# define END_DECLS /* empty */
#endif
#endif /* TAP_MACROS_H */