mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 15:00:12 +00:00
tests: Start using the upstream C TAP harness
Instead of bundling our own copies of Russ's C TAP Harness, start using source pulled from his git repository using the src/external import mechanism. Note that we are not currently building the floating point (is_double) portion of the harness. In the process of doing so, we also upgrade our test harness to the latest upstream version, 1.11. This is somewhat problematic, as there have been some significant code changes since the version bundled with OpenAFS. Work around these by *) Referencing the basic.h header as <tests/tap/basic.h>, rather than just <tap/basic.h>, to match the new upstream layout *) Changing the include path so that the tests/ directory can be found within it. Change-Id: I63efbb30248165e5729005b0a791e7eb7afb051d Reviewed-on: http://gerrit.openafs.org/7374 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Russ Allbery <rra@stanford.edu> Reviewed-by: Derrick Brashear <shadow@dementix.org>
This commit is contained in:
parent
319ec27236
commit
c877c0b419
248
tests/HOWTO
248
tests/HOWTO
@ -1,248 +0,0 @@
|
||||
Writing TAP Tests
|
||||
|
||||
Introduction
|
||||
|
||||
This is a guide for users of the C TAP Harness package or similar
|
||||
TAP-based test harnesses explaining how to write tests. If your
|
||||
package uses C TAP Harness as the test suite driver, you may want to
|
||||
copy this document to an appropriate file name in your test suite as
|
||||
documentation for contributors.
|
||||
|
||||
About TAP
|
||||
|
||||
TAP is the Test Anything Protocol, a protocol for communication
|
||||
between test cases and a test harness. This is the protocol used by
|
||||
Perl for its internal test suite and for nearly all Perl modules,
|
||||
since it's the format used by the build tools for Perl modules to run
|
||||
tests and report their results.
|
||||
|
||||
A TAP-based test suite works with a somewhat different set of
|
||||
assumptions than an xUnit test suite. In TAP, each test case is a
|
||||
separate program. That program, when run, must produce output in the
|
||||
following format:
|
||||
|
||||
1..4
|
||||
ok 1 - the first test
|
||||
ok 2
|
||||
# a diagnostic, ignored by the harness
|
||||
not ok 3 - a failing test
|
||||
ok 4 # skip a skipped test
|
||||
|
||||
The output should all go to standard output. The first line specifies
|
||||
the number of tests to be run, and then each test produces output that
|
||||
looks like either "ok <n>" or "not ok <n>" depending on whether the
|
||||
test succeeded or failed. Additional information about the test can
|
||||
be provided after the "ok <n>" or "not ok <n>", but is optional.
|
||||
Additional diagnostics and information can be provided in lines
|
||||
beginning with a "#".
|
||||
|
||||
Processing directives are supported after the "ok <n>" or "not ok <n>"
|
||||
and start with a "#". The main one of interest is "# skip" which says
|
||||
that the test was skipped rather than successful and optionally gives
|
||||
the reason. Also supported is "# todo", which normally annotates a
|
||||
failing test and indicates that test is expected to fail, optionally
|
||||
providing a reason for why.
|
||||
|
||||
There are three more special cases. First, the initial line stating
|
||||
the number of tests to run, called the plan, may appear at the end of
|
||||
the output instead of the beginning. This can be useful if the number
|
||||
of tests to run is not known in advance. Second, a plan in the form:
|
||||
|
||||
1..0 # skip entire test case skipped
|
||||
|
||||
can be given instead, which indicates that this entire test case has
|
||||
been skipped (generally because it depends on facilities or optional
|
||||
configuration which is not present). Finally, if the test case
|
||||
encounters a fatal error, it should print the text:
|
||||
|
||||
Bail out!
|
||||
|
||||
on standard output, optionally followed by an error message, and then
|
||||
exit. This tells the harness that the test aborted unexpectedly.
|
||||
|
||||
The exit status of a successful test case should always be 0. The
|
||||
harness will report the test as "dubious" if all the tests appeared to
|
||||
succeed but it exited with a non-zero status.
|
||||
|
||||
Writing TAP Tests
|
||||
|
||||
Environment
|
||||
|
||||
One of the special features of C TAP Harness is the environment that
|
||||
it sets up for your test cases. If your test program is called under
|
||||
the runtests driver, the environment variables SOURCE and BUILD will
|
||||
be set to the top of the test directory in the source tree and the top
|
||||
of the build tree, respectively. You can use those environment
|
||||
variables to locate additional test data, programs and libraries built
|
||||
as part of your software build, and other supporting information
|
||||
needed by tests.
|
||||
|
||||
The C and shell TAP libraries support a test_file_path() function,
|
||||
which looks for a file under the build tree and then under the source
|
||||
tree, using the BUILD and SOURCE environment variables, and return the
|
||||
full path to the file. This can be used to locate supporting data
|
||||
files.
|
||||
|
||||
Perl
|
||||
|
||||
Since TAP is the native test framework for Perl, writing TAP tests in
|
||||
Perl is very easy and extremely well-supported. If you've never
|
||||
written tests in Perl before, start by reading the documentation for
|
||||
Test::Tutorial and Test::Simple, which walks you through the basics,
|
||||
including the TAP output syntax. Then, the best Perl module to use
|
||||
for serious testing is Test::More, which provides a lot of additional
|
||||
functions over Test::Simple including support for skipping tests,
|
||||
bailing out, and not planning tests in advance. See the documentation
|
||||
of Test::More for all the details and lots of examples.
|
||||
|
||||
C TAP Harness can run Perl test scripts directly and interpret the
|
||||
results correctly, and similarly the Perl Test::Harness module and
|
||||
prove command can run TAP tests written in other languages using, for
|
||||
example, the TAP library that comes with C TAP Harness. You can, if
|
||||
you wish, use the library that comes with C TAP Harness but use prove
|
||||
instead of runtests for running the test suite.
|
||||
|
||||
C
|
||||
|
||||
C TAP Harness provides a basic TAP library that takes away most of the
|
||||
pain of writing TAP test cases in C. A C test case should start with
|
||||
a call to plan(), passing in the number of tests to run. Then, each
|
||||
test should use is_int(), is_string(), is_double(), or is_hex() as
|
||||
appropriate to compare expected and seen values, or ok() to do a
|
||||
simpler boolean test. The is_*() functions take expected and seen
|
||||
values and then a printf-style format string explaining the test
|
||||
(which may be NULL). ok() takes a boolean and then the printf-style
|
||||
string.
|
||||
|
||||
Here's a complete example test program that uses the C TAP library:
|
||||
|
||||
#include <stddef.h>
|
||||
#include <tap/basic.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
plan(4);
|
||||
|
||||
ok(1, "the first test");
|
||||
is_int(42, 42, NULL);
|
||||
diag("a diagnostic, ignored by the harness");
|
||||
ok(0, "a failing test");
|
||||
skip("a skipped test");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
This test program produces the output shown above in the section on
|
||||
TAP and demonstrates most of the functions. The other functions of
|
||||
interest are sysdiag() (like diag() but adds strerror() results),
|
||||
bail() and sysbail() for fatal errors, skip_block() to skip a whole
|
||||
block of tests, and skip_all() which is called instead of plan() to
|
||||
skip an entire test case.
|
||||
|
||||
The C TAP library also provides plan_lazy(), which can be called
|
||||
instead of plan(). If plan_lazy() is called, the library will keep
|
||||
track of how many test results are reported and will print out the
|
||||
plan at the end of execution of the program. This should normally be
|
||||
avoided since the test may appear to be successful even if it exits
|
||||
prematurely, but it can make writing tests easier in some
|
||||
circumstances.
|
||||
|
||||
Complete API documentation for the basic C TAP library that comes with
|
||||
C TAP Harness is available at:
|
||||
|
||||
<http://www.eyrie.org/~eagle/software/c-tap-harness/>
|
||||
|
||||
It's common to need additional test functions and utility functions
|
||||
for your C tests, particularly if you have to set up and tear down a
|
||||
test environment for your test programs, and it's useful to have them
|
||||
all in the libtap library so that you only have to link your test
|
||||
programs with one library. Rather than editing tap/basic.c and
|
||||
tap/basic.h to add those additional functions, add additional *.c and
|
||||
*.h files into the tap directory with the function implementations and
|
||||
prototypes, and then add those additional objects to the library.
|
||||
That way, you can update tap/basic.c and tap/basic.h from subsequent
|
||||
releases of C TAP Harness without having to merge changes with your
|
||||
own code.
|
||||
|
||||
Libraries of additional useful TAP test functions are available in
|
||||
rra-c-util at:
|
||||
|
||||
<http://www.eyrie.org/~eagle/software/rra-c-util/>
|
||||
|
||||
Some of the code there is particularly useful when testing programs
|
||||
that require Kerberos keys.
|
||||
|
||||
If you implement new test functions that compare an expected and seen
|
||||
value, it's best to name them is_<something> and take the expected
|
||||
value, the seen value, and then a printf-style format string and
|
||||
possible arguments to match the calling convention of the functions
|
||||
provided by C TAP Harness.
|
||||
|
||||
Shell
|
||||
|
||||
C TAP Harness provides a library of shell functions to make it easier
|
||||
to write TAP tests in shell. That library includes much of the same
|
||||
functionality as the C TAP library, but takes its parameters in a
|
||||
somewhat different order to make better use of shell features.
|
||||
|
||||
The libtap.sh file should be installed in a directory named tap in
|
||||
your test suite area. It can then be loaded by tests written in shell
|
||||
using the environment set up by runtests with:
|
||||
|
||||
. "$SOURCE"/tap/libtap.sh
|
||||
|
||||
Here is a complete test case written in shell which produces the same
|
||||
output as the TAP sample above:
|
||||
|
||||
#!/bin/sh
|
||||
|
||||
. "$SOURCE"/tap/libtap.sh
|
||||
cd "$BUILD"
|
||||
|
||||
plan 4
|
||||
ok 'the first test' true
|
||||
ok '' [ 42 -eq 42 ]
|
||||
diag a diagnostic, ignored by the harness
|
||||
ok '' false
|
||||
skip 'a skipped test'
|
||||
|
||||
The shell framework doesn't provide the is_* functions, so you'll use
|
||||
the ok function more. It takes a string describing the text and then
|
||||
treats all of its remaining arguments as a condition, evaluated the
|
||||
same way as the arguments to the "if" statement. If that condition
|
||||
evaluates to true, the test passes; otherwise, the test fails.
|
||||
|
||||
The plan, plan_lazy, diag, and bail functions work the same as with
|
||||
the C library. skip takes a string and skips the next test with that
|
||||
explanation. skip_block takes a count and a string and skips that
|
||||
many tests with that explanation. skip_all takes an optional reason
|
||||
and skips the entire test case.
|
||||
|
||||
Since it's common for shell programs to want to test the output of
|
||||
commands, there's an additional function ok_program provided by the
|
||||
shell test library. It takes the test description string, the
|
||||
expected exit status, the expected program output, and then treats the
|
||||
rest of its arguments as the program to run. That program is run with
|
||||
standard error and standard output combined, and then its exit status
|
||||
and output are tested against the provided values.
|
||||
|
||||
A utility function, strip_colon_error, is provided that runs the
|
||||
command given as its arguments and strips text following a colon and a
|
||||
space from the output (unless there is no whitespace on the line
|
||||
before the colon and the space, normally indicating a prefix of the
|
||||
program name). This function can be used to wrap commands that are
|
||||
expected to fail with output that has a system- or locale-specific
|
||||
error message appended, such as the output of strerror().
|
||||
|
||||
License
|
||||
|
||||
This file is part of the documentation of C TAP Harness, which can be
|
||||
found at <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
|
||||
|
||||
Copyright 2010 Russ Allbery <rra@stanford.edu>
|
||||
|
||||
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.
|
@ -1,6 +1,6 @@
|
||||
# Build rules for the OpenAFS test suite.
|
||||
|
||||
srcdir=@srcdir@
|
||||
srcdir=@srcdir@/../src/external/c-tap-harness/tests
|
||||
abs_top_srcdir=@abs_top_srcdir@
|
||||
abs_top_builddir=@abs_top_builddir@
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
@ -17,6 +17,9 @@ all: runtests
|
||||
runtests: runtests.o
|
||||
$(AFS_LDRULE) runtests.o
|
||||
|
||||
runtests.o: $(srcdir)/runtests.c
|
||||
$(AFS_CCRULE) $(srcdir)/runtests.c
|
||||
|
||||
check test tests: runtests
|
||||
@for A in $(SUBDIRS); do cd $$A && $(MAKE) $@ && cd .. || exit 1; done
|
||||
./libwrap @TOP_OBJDIR@/lib \
|
||||
|
15
tests/README
15
tests/README
@ -3,7 +3,7 @@ intended to become the primary OpenAFS test suite. The tests in this
|
||||
directory are run when "make check" is run at the top level of the OpenAFS
|
||||
tree.
|
||||
|
||||
runtests.c is the test harness, and TESTS is the list of tests that it
|
||||
runtests is the test harness, and TESTS is the list of tests that it
|
||||
will run. If you add a new test, add it to TESTS as well. All tests must
|
||||
be executables (possibly shell scripts or Perl scripts) that end in either
|
||||
".t" or "-t", but should be listed in TESTS without that suffix.
|
||||
@ -19,8 +19,9 @@ level. The Makefile.in in this directory will also need to be modified
|
||||
to recurse into any new directories. See util/Makefile.in for an example
|
||||
of how to write a Makefile.in for a new test directory.
|
||||
|
||||
runtests.c, tap/basic.c, tap/basic.h, tap/libtap.sh, and HOWTO come from
|
||||
the C TAP Harness distribution at:
|
||||
The files comprising the test harness are sourced from the C TAP Harness
|
||||
distribution using the src/external mechanism. The upstream site for that
|
||||
distribution is at:
|
||||
|
||||
http://www.eyrie.org/~eagle/software/c-tap-harness/
|
||||
|
||||
@ -28,5 +29,9 @@ but feel free to propose modifications directly through OpenAFS Gerrit.
|
||||
Russ Allbery will take care of merging modifications upstream. However,
|
||||
OpenAFS-specific modifications should not be made to those files. To add
|
||||
additional OpenAFS-specific code to the TAP library, add additional *.c
|
||||
and *.h (or *.sh) files to the tap directory rather than modifying
|
||||
basic.c, basic.h, or libtap.sh.
|
||||
and *.h (or *.sh) files to the tests/tap directory rather than modifying files
|
||||
in src/external.
|
||||
|
||||
More information can be found in the HOWTO contained in
|
||||
src/external/c-tap-harness/HOWTO
|
||||
|
||||
|
@ -6,7 +6,7 @@ include @TOP_OBJDIR@/src/config/Makefile.pthread
|
||||
|
||||
TESTS = authcon-t superuser-t keys-t realms-t
|
||||
|
||||
MODULE_CFLAGS=-I$(srcdir)/.. -I$(srcdir)/../common/
|
||||
MODULE_CFLAGS=-I$(srcdir)/../.. -I$(srcdir)/../common/
|
||||
|
||||
all check test tests: $(TESTS)
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include <rx/rxkad.h>
|
||||
#include <afs/cellconfig.h>
|
||||
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
#include "common.h"
|
||||
|
||||
int
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include <afs/afsutil.h>
|
||||
#include <rx/rxkad.h>
|
||||
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
#include "test.h"
|
||||
#include "common.h"
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <rx/rxkad.h>
|
||||
#include <afs/cellconfig.h>
|
||||
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
#include "common.h"
|
||||
|
||||
extern int _afsconf_Touch(struct afsconf_dir *adir);
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include <rx/rxkad.h>
|
||||
#include <rx/rx_identity.h>
|
||||
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
#include "test.h"
|
||||
#include "common.h"
|
||||
|
@ -5,7 +5,7 @@ abs_top_builddir=@abs_top_builddir@
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
include @TOP_OBJDIR@/src/config/Makefile.pthread
|
||||
|
||||
MODULE_CFLAGS = -I$(srcdir)/..
|
||||
MODULE_CFLAGS = -I$(srcdir)/../..
|
||||
|
||||
LIBS = ../tap/libtap.a \
|
||||
$(abs_top_builddir)/lib/libcmd.a \
|
||||
|
@ -33,7 +33,7 @@
|
||||
|
||||
#include <afs/cmd.h>
|
||||
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
enum cmdOptions {
|
||||
copt_flag = 0,
|
||||
|
@ -3,7 +3,7 @@ abs_top_builddir=@abs_top_builddir@
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
include @TOP_OBJDIR@/src/config/Makefile.lwp
|
||||
|
||||
MODULE_CFLAGS = -I$(srcdir)/..
|
||||
MODULE_CFLAGS = -I$(srcdir)/../..
|
||||
|
||||
LIBS=../tap/libtap.a $(abs_top_builddir)/lib/libopr.a
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <afs/param.h>
|
||||
|
||||
#include <roken.h>
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
#include <opr/jhash.h>
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
#include <opr/queue.h>
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
#include <afs/opr.h>
|
||||
#include <opr/rbtree.h>
|
||||
|
1172
tests/runtests.c
1172
tests/runtests.c
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@ abs_top_builddir=@abs_top_builddir@
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
include @TOP_OBJDIR@/src/config/Makefile.pthread
|
||||
|
||||
MODULE_CFLAGS = -I$(srcdir)/..
|
||||
MODULE_CFLAGS = -I$(srcdir)/../..
|
||||
|
||||
LIBS = ../tap/libtap.a \
|
||||
$(abs_top_builddir)/lib/libafsrpc.a \
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <roken.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
#include "rx/rx_event.h"
|
||||
#include "rx/rx_clock.h"
|
||||
|
3
tests/tap/.gitignore
vendored
Normal file
3
tests/tap/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/libtap.sh
|
||||
/basic.h
|
||||
/macros.h
|
@ -1,15 +1,25 @@
|
||||
# Build rules for the OpenAFS test suite.
|
||||
|
||||
srcdir=@srcdir@
|
||||
tapdir=$(srcdir)/../../src/external/c-tap-harness/tests/tap
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
include @TOP_OBJDIR@/src/config/Makefile.pthread
|
||||
|
||||
objects = basic.o
|
||||
|
||||
all check test tests: libtap.a
|
||||
all check test tests: libtap.a basic.h macros.h libtap.sh
|
||||
|
||||
basic.o: $(srcdir)/basic.c $(srcdir)/basic.h
|
||||
$(CC) $(AFS_CFLAGS) -I$(srcdir)/.. -c $(srcdir)/basic.c
|
||||
basic.o: $(tapdir)/basic.c $(tapdir)/basic.h
|
||||
$(CC) $(AFS_CFLAGS) @CFLAGS_NOERROR@ -I$(tapdir)/../.. -c $(tapdir)/basic.c
|
||||
|
||||
basic.h: $(tapdir)/basic.h
|
||||
cp $(tapdir)/basic.h basic.h
|
||||
|
||||
macros.h: $(tapdir)/macros.h
|
||||
cp $(tapdir)/macros.h macros.h
|
||||
|
||||
libtap.sh: $(tapdir)/libtap.sh
|
||||
cp $(tapdir)/libtap.sh libtap.sh
|
||||
|
||||
libtap.a: $(objects)
|
||||
$(RM) -f libtap.a
|
||||
@ -19,4 +29,4 @@ libtap.a: $(objects)
|
||||
install:
|
||||
|
||||
clean distclean:
|
||||
$(RM) -f *.o *.a core
|
||||
$(RM) -f *.o *.a core basic.h macros.h libtap.sh
|
||||
|
@ -1,524 +0,0 @@
|
||||
/*
|
||||
* Some utility routines for writing tests.
|
||||
*
|
||||
* Here are a variety of utility routines for writing tests compatible with
|
||||
* the TAP protocol. All routines of the form ok() or is*() take a test
|
||||
* number and some number of appropriate arguments, check to be sure the
|
||||
* results match the expected output using the arguments, and print out
|
||||
* something appropriate for that test number. Other utility routines help in
|
||||
* constructing more complex tests, skipping tests, or setting up the TAP
|
||||
* output format.
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* Copyright 2009, 2010 Russ Allbery <rra@stanford.edu>
|
||||
* Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* Required for isnan() and isinf(). */
|
||||
#ifndef _XOPEN_SOURCE
|
||||
# define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <tap/basic.h>
|
||||
|
||||
/*
|
||||
* The test count. Always contains the number that will be used for the next
|
||||
* test status.
|
||||
*/
|
||||
unsigned long testnum = 1;
|
||||
|
||||
/*
|
||||
* Status information stored so that we can give a test summary at the end of
|
||||
* the test case. We store the planned final test and the count of failures.
|
||||
* We can get the highest test count from testnum.
|
||||
*
|
||||
* We also store the PID of the process that called plan() and only summarize
|
||||
* results when that process exits, so as to not misreport results in forked
|
||||
* processes.
|
||||
*
|
||||
* If _lazy is true, we're doing lazy planning and will print out the plan
|
||||
* based on the last test number at the end of testing.
|
||||
*/
|
||||
static unsigned long _planned = 0;
|
||||
static unsigned long _failed = 0;
|
||||
static pid_t _process = 0;
|
||||
static int _lazy = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Our exit handler. Called on completion of the test to report a summary of
|
||||
* results provided we're still in the original process.
|
||||
*/
|
||||
static void
|
||||
finish(void)
|
||||
{
|
||||
unsigned long highest = testnum - 1;
|
||||
|
||||
if (_planned == 0 && !_lazy)
|
||||
return;
|
||||
fflush(stderr);
|
||||
if (_process != 0 && getpid() == _process) {
|
||||
if (_lazy) {
|
||||
printf("1..%lu\n", highest);
|
||||
_planned = highest;
|
||||
}
|
||||
if (_planned > highest)
|
||||
printf("# Looks like you planned %lu test%s but only ran %lu\n",
|
||||
_planned, (_planned > 1 ? "s" : ""), highest);
|
||||
else if (_planned < highest)
|
||||
printf("# Looks like you planned %lu test%s but ran %lu extra\n",
|
||||
_planned, (_planned > 1 ? "s" : ""), highest - _planned);
|
||||
else if (_failed > 0)
|
||||
printf("# Looks like you failed %lu test%s of %lu\n", _failed,
|
||||
(_failed > 1 ? "s" : ""), _planned);
|
||||
else if (_planned > 1)
|
||||
printf("# All %lu tests successful or skipped\n", _planned);
|
||||
else
|
||||
printf("# %lu test successful or skipped\n", _planned);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize things. Turns on line buffering on stdout and then prints out
|
||||
* the number of tests in the test suite.
|
||||
*/
|
||||
void
|
||||
plan(unsigned long count)
|
||||
{
|
||||
if (setvbuf(stdout, NULL, _IOLBF, BUFSIZ) != 0)
|
||||
fprintf(stderr, "# cannot set stdout to line buffered: %s\n",
|
||||
strerror(errno));
|
||||
fflush(stderr);
|
||||
printf("1..%lu\n", count);
|
||||
testnum = 1;
|
||||
_planned = count;
|
||||
_process = getpid();
|
||||
atexit(finish);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize things for lazy planning, where we'll automatically print out a
|
||||
* plan at the end of the program. Turns on line buffering on stdout as well.
|
||||
*/
|
||||
void
|
||||
plan_lazy(void)
|
||||
{
|
||||
if (setvbuf(stdout, NULL, _IOLBF, BUFSIZ) != 0)
|
||||
fprintf(stderr, "# cannot set stdout to line buffered: %s\n",
|
||||
strerror(errno));
|
||||
testnum = 1;
|
||||
_process = getpid();
|
||||
_lazy = 1;
|
||||
atexit(finish);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Skip the entire test suite and exits. Should be called instead of plan(),
|
||||
* not after it, since it prints out a special plan line.
|
||||
*/
|
||||
void
|
||||
skip_all(const char *format, ...)
|
||||
{
|
||||
fflush(stderr);
|
||||
printf("1..0 # skip");
|
||||
if (format != NULL) {
|
||||
va_list args;
|
||||
|
||||
putchar(' ');
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
putchar('\n');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Print the test description.
|
||||
*/
|
||||
static void
|
||||
print_desc(const char *format, va_list args)
|
||||
{
|
||||
printf(" - ");
|
||||
vprintf(format, args);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Takes a boolean success value and assumes the test passes if that value
|
||||
* is true and fails if that value is false.
|
||||
*/
|
||||
void
|
||||
ok(int success, const char *format, ...)
|
||||
{
|
||||
fflush(stderr);
|
||||
printf("%sok %lu", success ? "" : "not ", testnum++);
|
||||
if (!success)
|
||||
_failed++;
|
||||
if (format != NULL) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
print_desc(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Same as ok(), but takes the format arguments as a va_list.
|
||||
*/
|
||||
void
|
||||
okv(int success, const char *format, va_list args)
|
||||
{
|
||||
fflush(stderr);
|
||||
printf("%sok %lu", success ? "" : "not ", testnum++);
|
||||
if (!success)
|
||||
_failed++;
|
||||
if (format != NULL)
|
||||
print_desc(format, args);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Skip a test.
|
||||
*/
|
||||
void
|
||||
skip(const char *reason, ...)
|
||||
{
|
||||
fflush(stderr);
|
||||
printf("ok %lu # skip", testnum++);
|
||||
if (reason != NULL) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, reason);
|
||||
putchar(' ');
|
||||
vprintf(reason, args);
|
||||
va_end(args);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Report the same status on the next count tests.
|
||||
*/
|
||||
void
|
||||
ok_block(unsigned long count, int status, const char *format, ...)
|
||||
{
|
||||
unsigned long i;
|
||||
|
||||
fflush(stderr);
|
||||
for (i = 0; i < count; i++) {
|
||||
printf("%sok %lu", status ? "" : "not ", testnum++);
|
||||
if (!status)
|
||||
_failed++;
|
||||
if (format != NULL) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
print_desc(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Skip the next count tests.
|
||||
*/
|
||||
void
|
||||
skip_block(unsigned long count, const char *reason, ...)
|
||||
{
|
||||
unsigned long i;
|
||||
|
||||
fflush(stderr);
|
||||
for (i = 0; i < count; i++) {
|
||||
printf("ok %lu # skip", testnum++);
|
||||
if (reason != NULL) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, reason);
|
||||
putchar(' ');
|
||||
vprintf(reason, args);
|
||||
va_end(args);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Takes an expected integer and a seen integer and assumes the test passes
|
||||
* if those two numbers match.
|
||||
*/
|
||||
void
|
||||
is_int(long wanted, long seen, const char *format, ...)
|
||||
{
|
||||
fflush(stderr);
|
||||
if (wanted == seen)
|
||||
printf("ok %lu", testnum++);
|
||||
else {
|
||||
printf("# wanted: %ld\n# seen: %ld\n", wanted, seen);
|
||||
printf("not ok %lu", testnum++);
|
||||
_failed++;
|
||||
}
|
||||
if (format != NULL) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
print_desc(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Takes a string and what the string should be, and assumes the test passes
|
||||
* if those strings match (using strcmp).
|
||||
*/
|
||||
void
|
||||
is_string(const char *wanted, const char *seen, const char *format, ...)
|
||||
{
|
||||
if (wanted == NULL)
|
||||
wanted = "(null)";
|
||||
if (seen == NULL)
|
||||
seen = "(null)";
|
||||
fflush(stderr);
|
||||
if (strcmp(wanted, seen) == 0)
|
||||
printf("ok %lu", testnum++);
|
||||
else {
|
||||
printf("# wanted: %s\n# seen: %s\n", wanted, seen);
|
||||
printf("not ok %lu", testnum++);
|
||||
_failed++;
|
||||
}
|
||||
if (format != NULL) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
print_desc(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Takes an expected double and a seen double and assumes the test passes if
|
||||
* those two numbers are within delta of each other.
|
||||
*/
|
||||
void
|
||||
is_double(double wanted, double seen, double epsilon, const char *format, ...)
|
||||
{
|
||||
fflush(stderr);
|
||||
if ((isnan(wanted) && isnan(seen))
|
||||
|| (isinf(wanted) && isinf(seen) && wanted == seen)
|
||||
|| fabs(wanted - seen) <= epsilon)
|
||||
printf("ok %lu", testnum++);
|
||||
else {
|
||||
printf("# wanted: %g\n# seen: %g\n", wanted, seen);
|
||||
printf("not ok %lu", testnum++);
|
||||
_failed++;
|
||||
}
|
||||
if (format != NULL) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
print_desc(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Takes an expected unsigned long and a seen unsigned long and assumes the
|
||||
* test passes if the two numbers match. Otherwise, reports them in hex.
|
||||
*/
|
||||
void
|
||||
is_hex(unsigned long wanted, unsigned long seen, const char *format, ...)
|
||||
{
|
||||
fflush(stderr);
|
||||
if (wanted == seen)
|
||||
printf("ok %lu", testnum++);
|
||||
else {
|
||||
printf("# wanted: %lx\n# seen: %lx\n", (unsigned long) wanted,
|
||||
(unsigned long) seen);
|
||||
printf("not ok %lu", testnum++);
|
||||
_failed++;
|
||||
}
|
||||
if (format != NULL) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
print_desc(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Bail out with an error.
|
||||
*/
|
||||
void
|
||||
bail(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
fflush(stderr);
|
||||
fflush(stdout);
|
||||
printf("Bail out! ");
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
printf("\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Bail out with an error, appending strerror(errno).
|
||||
*/
|
||||
void
|
||||
sysbail(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int oerrno = errno;
|
||||
|
||||
fflush(stderr);
|
||||
fflush(stdout);
|
||||
printf("Bail out! ");
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
printf(": %s\n", strerror(oerrno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Report a diagnostic to stderr.
|
||||
*/
|
||||
void
|
||||
diag(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
fflush(stderr);
|
||||
fflush(stdout);
|
||||
printf("# ");
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Report a diagnostic to stderr, appending strerror(errno).
|
||||
*/
|
||||
void
|
||||
sysdiag(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int oerrno = errno;
|
||||
|
||||
fflush(stderr);
|
||||
fflush(stdout);
|
||||
printf("# ");
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
printf(": %s\n", strerror(oerrno));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Locate a test file. Given the partial path to a file, look under BUILD and
|
||||
* then SOURCE for the file and return the full path to the file. Returns
|
||||
* NULL if the file doesn't exist. A non-NULL return should be freed with
|
||||
* test_file_path_free().
|
||||
*
|
||||
* This function uses sprintf because it attempts to be independent of all
|
||||
* other portability layers. The use immediately after a memory allocation
|
||||
* should be safe without using snprintf or strlcpy/strlcat.
|
||||
*/
|
||||
char *
|
||||
test_file_path(const char *file)
|
||||
{
|
||||
char *base;
|
||||
char *path = NULL;
|
||||
size_t length;
|
||||
const char *envs[] = { "BUILD", "SOURCE", NULL };
|
||||
int i;
|
||||
|
||||
for (i = 0; envs[i] != NULL; i++) {
|
||||
base = getenv(envs[i]);
|
||||
if (base == NULL)
|
||||
continue;
|
||||
length = strlen(base) + 1 + strlen(file) + 1;
|
||||
path = malloc(length);
|
||||
if (path == NULL)
|
||||
sysbail("cannot allocate memory");
|
||||
sprintf(path, "%s/%s", base, file);
|
||||
if (access(path, R_OK) == 0)
|
||||
break;
|
||||
free(path);
|
||||
path = NULL;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Free a path returned from test_file_path(). This function exists primarily
|
||||
* for Windows, where memory must be freed from the same library domain that
|
||||
* it was allocated from.
|
||||
*/
|
||||
void
|
||||
test_file_path_free(char *path)
|
||||
{
|
||||
if (path != NULL)
|
||||
free(path);
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*
|
||||
* Copyright 2009, 2010 Russ Allbery <rra@stanford.edu>
|
||||
* Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef TAP_BASIC_H
|
||||
#define TAP_BASIC_H 1
|
||||
|
||||
#include <stdarg.h> /* va_list */
|
||||
#include <sys/types.h> /* pid_t */
|
||||
|
||||
/*
|
||||
* __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
|
||||
* could you use the __format__ form of the attributes, which is what we use
|
||||
* (to avoid confusion with other macros).
|
||||
*/
|
||||
#ifndef __attribute__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
||||
# define __attribute__(spec) /* empty */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* BEGIN_DECLS is used at the beginning of declarations so that C++
|
||||
* compilers don't mangle their names. END_DECLS is used at the end.
|
||||
*/
|
||||
#undef BEGIN_DECLS
|
||||
#undef END_DECLS
|
||||
#ifdef __cplusplus
|
||||
# define BEGIN_DECLS extern "C" {
|
||||
# define END_DECLS }
|
||||
#else
|
||||
# define BEGIN_DECLS /* empty */
|
||||
# define END_DECLS /* empty */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Used for iterating through arrays. ARRAY_SIZE returns the number of
|
||||
* elements in the array (useful for a < upper bound in a for loop) and
|
||||
* 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)])
|
||||
|
||||
BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* The test count. Always contains the number that will be used for the next
|
||||
* test status.
|
||||
*/
|
||||
extern unsigned long testnum;
|
||||
|
||||
/* Print out the number of tests and set standard output to line buffered. */
|
||||
void plan(unsigned long count);
|
||||
|
||||
/*
|
||||
* Prepare for lazy planning, in which the plan will be printed automatically
|
||||
* at the end of the test program.
|
||||
*/
|
||||
void plan_lazy(void);
|
||||
|
||||
/* Skip the entire test suite. Call instead of plan. */
|
||||
void skip_all(const char *format, ...)
|
||||
__attribute__((__noreturn__, __format__(printf, 1, 2)));
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
void 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)));
|
||||
|
||||
/* Report the same status on, or skip, the next count tests. */
|
||||
void 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, ...)
|
||||
__attribute__((__format__(printf, 3, 4)));
|
||||
void is_double(double wanted, double seen, double epsilon,
|
||||
const char *format, ...)
|
||||
__attribute__((__format__(printf, 4, 5)));
|
||||
void is_string(const char *wanted, const char *seen, const char *format, ...)
|
||||
__attribute__((__format__(printf, 3, 4)));
|
||||
void is_hex(unsigned long wanted, unsigned long seen, const char *format, ...)
|
||||
__attribute__((__format__(printf, 3, 4)));
|
||||
|
||||
/* Bail out with an error. sysbail appends strerror(errno). */
|
||||
void bail(const char *format, ...)
|
||||
__attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
|
||||
void sysbail(const char *format, ...)
|
||||
__attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
|
||||
|
||||
/* Report a diagnostic to stderr prefixed with #. */
|
||||
void diag(const char *format, ...)
|
||||
__attribute__((__nonnull__, __format__(printf, 1, 2)));
|
||||
void sysdiag(const char *format, ...)
|
||||
__attribute__((__nonnull__, __format__(printf, 1, 2)));
|
||||
|
||||
/*
|
||||
* Find a test file under BUILD or 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__));
|
||||
void test_file_path_free(char *path);
|
||||
|
||||
END_DECLS
|
||||
|
||||
#endif /* TAP_BASIC_H */
|
@ -1,222 +0,0 @@
|
||||
# Shell function library for test cases.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
# Written by Russ Allbery <rra@stanford.edu>
|
||||
# Copyright 2009, 2010 Russ Allbery <rra@stanford.edu>
|
||||
# Copyright 2006, 2007, 2008
|
||||
# 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.
|
||||
|
||||
# Print out the number of test cases we expect to run.
|
||||
plan () {
|
||||
count=1
|
||||
planned="$1"
|
||||
failed=0
|
||||
echo "1..$1"
|
||||
trap finish 0
|
||||
}
|
||||
|
||||
# Prepare for lazy planning.
|
||||
plan_lazy () {
|
||||
count=1
|
||||
planned=0
|
||||
failed=0
|
||||
trap finish 0
|
||||
}
|
||||
|
||||
# Report the test status on exit.
|
||||
finish () {
|
||||
local highest looks
|
||||
highest=`expr "$count" - 1`
|
||||
if [ "$planned" = 0 ] ; then
|
||||
echo "1..$highest"
|
||||
planned="$highest"
|
||||
fi
|
||||
looks='# Looks like you'
|
||||
if [ "$planned" -gt 0 ] ; then
|
||||
if [ "$planned" -gt "$highest" ] ; then
|
||||
if [ "$planned" -gt 1 ] ; then
|
||||
echo "$looks planned $planned tests but only ran $highest"
|
||||
else
|
||||
echo "$looks planned $planned test but only ran $highest"
|
||||
fi
|
||||
elif [ "$planned" -lt "$highest" ] ; then
|
||||
local extra
|
||||
extra=`expr "$highest" - "$planned"`
|
||||
if [ "$planned" -gt 1 ] ; then
|
||||
echo "$looks planned $planned tests but ran $extra extra"
|
||||
else
|
||||
echo "$looks planned $planned test but ran $extra extra"
|
||||
fi
|
||||
elif [ "$failed" -gt 0 ] ; then
|
||||
if [ "$failed" -gt 1 ] ; then
|
||||
echo "$looks failed $failed tests of $planned"
|
||||
else
|
||||
echo "$looks failed $failed test of $planned"
|
||||
fi
|
||||
elif [ "$planned" -gt 1 ] ; then
|
||||
echo "# All $planned tests successful or skipped"
|
||||
else
|
||||
echo "# $planned test successful or skipped"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Skip the entire test suite. Should be run instead of plan.
|
||||
skip_all () {
|
||||
local desc
|
||||
desc="$1"
|
||||
if [ -n "$desc" ] ; then
|
||||
echo "1..0 # skip $desc"
|
||||
else
|
||||
echo "1..0 # skip"
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
# ok takes a test description and a command to run and prints success if that
|
||||
# command is successful, false otherwise. The count starts at 1 and is
|
||||
# updated each time ok is printed.
|
||||
ok () {
|
||||
local desc
|
||||
desc="$1"
|
||||
if [ -n "$desc" ] ; then
|
||||
desc=" - $desc"
|
||||
fi
|
||||
shift
|
||||
if "$@" ; then
|
||||
echo ok $count$desc
|
||||
else
|
||||
echo not ok $count$desc
|
||||
failed=`expr $failed + 1`
|
||||
fi
|
||||
count=`expr $count + 1`
|
||||
}
|
||||
|
||||
# Skip the next test. Takes the reason why the test is skipped.
|
||||
skip () {
|
||||
echo "ok $count # skip $*"
|
||||
count=`expr $count + 1`
|
||||
}
|
||||
|
||||
# Report the same status on a whole set of tests. Takes the count of tests,
|
||||
# the description, and then the command to run to determine the status.
|
||||
ok_block () {
|
||||
local end i desc
|
||||
i=$count
|
||||
end=`expr $count + $1`
|
||||
shift
|
||||
desc="$1"
|
||||
shift
|
||||
while [ "$i" -lt "$end" ] ; do
|
||||
ok "$desc" "$@"
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
}
|
||||
|
||||
# Skip a whole set of tests. Takes the count and then the reason for skipping
|
||||
# the test.
|
||||
skip_block () {
|
||||
local i end
|
||||
i=$count
|
||||
end=`expr $count + $1`
|
||||
shift
|
||||
while [ "$i" -lt "$end" ] ; do
|
||||
skip "$@"
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
}
|
||||
|
||||
# Portable variant of printf '%s\n' "$*". In the majority of cases, this
|
||||
# function is slower than printf, because the latter is often implemented
|
||||
# as a builtin command. The value of the variable IFS is ignored.
|
||||
puts () {
|
||||
cat << EOH
|
||||
$@
|
||||
EOH
|
||||
}
|
||||
|
||||
# Run a program expected to succeed, and print ok if it does and produces the
|
||||
# correct output. Takes the description, expected exit status, the expected
|
||||
# output, the command to run, and then any arguments for that command.
|
||||
# Standard output and standard error are combined when analyzing the output of
|
||||
# the command.
|
||||
#
|
||||
# If the command may contain system-specific error messages in its output,
|
||||
# add strip_colon_error before the command to post-process its output.
|
||||
ok_program () {
|
||||
local desc w_status w_output output status
|
||||
desc="$1"
|
||||
shift
|
||||
w_status="$1"
|
||||
shift
|
||||
w_output="$1"
|
||||
shift
|
||||
output=`"$@" 2>&1`
|
||||
status=$?
|
||||
if [ $status = $w_status ] && [ x"$output" = x"$w_output" ] ; then
|
||||
ok "$desc" true
|
||||
else
|
||||
echo "# saw: ($status) $output"
|
||||
echo "# not: ($w_status) $w_output"
|
||||
ok "$desc" false
|
||||
fi
|
||||
}
|
||||
|
||||
# Strip a colon and everything after it off the output of a command, as long
|
||||
# as that colon comes after at least one whitespace character. (This is done
|
||||
# to avoid stripping the name of the program from the start of an error
|
||||
# message.) This is used to remove system-specific error messages (coming
|
||||
# from strerror, for example).
|
||||
strip_colon_error() {
|
||||
local output status
|
||||
output=`"$@" 2>&1`
|
||||
status=$?
|
||||
output=`puts "$output" | sed 's/^\([^ ]* [^:]*\):.*/\1/'`
|
||||
puts "$output"
|
||||
return $status
|
||||
}
|
||||
|
||||
# Bail out with an error message.
|
||||
bail () {
|
||||
echo 'Bail out!' "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Output a diagnostic on standard error, preceded by the required # mark.
|
||||
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.
|
||||
test_file_path () {
|
||||
if [ -n "$BUILD" ] && [ -f "$BUILD/$1" ] ; then
|
||||
puts "$BUILD/$1"
|
||||
elif [ -n "$SOURCE" ] && [ -f "$SOURCE/$1" ] ; then
|
||||
puts "$SOURCE/$1"
|
||||
else
|
||||
echo ''
|
||||
fi
|
||||
}
|
@ -5,7 +5,7 @@ abs_top_builddir=@abs_top_builddir@
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
include @TOP_OBJDIR@/src/config/Makefile.lwp
|
||||
|
||||
MODULE_CFLAGS = -I$(srcdir)/..
|
||||
MODULE_CFLAGS = -I$(srcdir)/../..
|
||||
|
||||
LIBS = ../tap/libtap.a \
|
||||
$(abs_top_builddir)/lib/util.a \
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <afs/param.h>
|
||||
|
||||
#include <afs/afsutil.h>
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <afs/ktime.h>
|
||||
#include <afs/afsutil.h>
|
||||
#include <afs/afsutil_prototypes.h>
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
static struct testTime {
|
||||
char *time;
|
||||
|
@ -6,7 +6,7 @@ include @TOP_OBJDIR@/src/config/Makefile.pthread
|
||||
|
||||
TESTS = vos-t
|
||||
|
||||
MODULE_CFLAGS=-I$(srcdir)/.. -I$(srcdir)/../common/
|
||||
MODULE_CFLAGS=-I$(srcdir)/../.. -I$(srcdir)/../common/
|
||||
|
||||
all check test tests: $(TESTS)
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <afs/vldbint.h>
|
||||
#include <afs/cellconfig.h>
|
||||
|
||||
#include <tap/basic.h>
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user