mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 06:50:12 +00:00
Import C TAP Harness 1.2 as a testing harness
Creates a new top-level tests directory that will be used for all future automated test code eventually. Import runtests and the basic TAP library from C TAP Harness 1.2. Add top-level check and test targets that build the full source tree and then the new tests directory, and then runs runtests on the test list. Change-Id: I896f8ae488cd1dfa8529a10b4b479e45e7c67afe Reviewed-on: http://gerrit.openafs.org/2062 Tested-by: Derrick Brashear <shadow@dementia.org> Reviewed-by: Derrick Brashear <shadow@dementia.org>
This commit is contained in:
parent
f7cb812d07
commit
194c3f10d4
@ -628,6 +628,9 @@ finale_nolibafs: project cmd comerr afsd butc tbutc tbudb libuafs audit kauth lo
|
||||
platform kopenafs authtools
|
||||
+${COMPILE_PART1} finale ${COMPILE_PART2}
|
||||
|
||||
check test: finale
|
||||
cd tests && $(MAKE) check
|
||||
|
||||
# Use washtool to ensure MakefileProto is current and obj/libafs exists.
|
||||
|
||||
force:
|
||||
@ -868,6 +871,8 @@ distclean: clean
|
||||
src/vol/test/Makefile \
|
||||
src/volser/Makefile \
|
||||
src/xstat/Makefile \
|
||||
tests/Makefile \
|
||||
tests/tap/Makefile \
|
||||
src/helper-splint.sh
|
||||
if test -d doc/man-pages ; then \
|
||||
rm -f doc/man-pages/Makefile doc/man-pages/install-man ; \
|
||||
|
@ -174,7 +174,9 @@ src/vol/Makefile \
|
||||
src/vol/test/Makefile \
|
||||
src/volser/Makefile \
|
||||
src/xstat/Makefile \
|
||||
src/helper-splint.sh,
|
||||
src/helper-splint.sh \
|
||||
tests/Makefile \
|
||||
tests/tap/Makefile,
|
||||
|
||||
[chmod a+x src/config/shlib-build
|
||||
chmod a+x src/config/shlib-install])
|
||||
|
5
tests/.gitignore
vendored
Normal file
5
tests/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# After changing this file, please run
|
||||
# git ls-files -i --exclude-standard
|
||||
# to check that you haven't inadvertently ignored any tracked files.
|
||||
|
||||
/runtests
|
28
tests/Makefile.in
Normal file
28
tests/Makefile.in
Normal file
@ -0,0 +1,28 @@
|
||||
# Build rules for the OpenAFS test suite.
|
||||
|
||||
srcdir=@srcdir@
|
||||
abs_top_srcdir=@abs_top_srcdir@
|
||||
abs_top_builddir=@abs_top_builddir@
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
|
||||
RUNTESTS_CPPFLAGS = -DSOURCE='"$(abs_top_srcdir)/tests"' \
|
||||
-DBUILD='"$(abs_top_builddir)/tests"'
|
||||
|
||||
all: runtests
|
||||
cd tap && $(MAKE) $@
|
||||
|
||||
runtests.o: $(srcdir)/runtests.c
|
||||
$(CCOBJ) $(CFLAGS) $(RUNTESTS_CPPFLAGS) -c $(srcdir)/runtests.c
|
||||
|
||||
runtests: runtests.o
|
||||
$(CC) $(LDFLAGS) -o runtests runtests.o
|
||||
|
||||
check test tests: runtests
|
||||
cd tap && $(MAKE) $@
|
||||
./runtests $(abs_top_srcdir)/tests/TESTS
|
||||
|
||||
install:
|
||||
|
||||
clean distclean:
|
||||
cd tap && $(MAKE) $@
|
||||
$(RM) -f *.o core runtests
|
0
tests/TESTS
Normal file
0
tests/TESTS
Normal file
1116
tests/runtests.c
Normal file
1116
tests/runtests.c
Normal file
File diff suppressed because it is too large
Load Diff
21
tests/tap/Makefile.in
Normal file
21
tests/tap/Makefile.in
Normal file
@ -0,0 +1,21 @@
|
||||
# Build rules for the OpenAFS test suite.
|
||||
|
||||
srcdir=@srcdir@
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
|
||||
objects = basic.o
|
||||
|
||||
all check test tests: libtap.a
|
||||
|
||||
basic.o: $(srcdir)/basic.c $(srcdir)/basic.h
|
||||
$(CCOBJ) $(CFLAGS) -I$(srcdir)/.. -c $(srcdir)/basic.c
|
||||
|
||||
libtap.a: $(objects)
|
||||
$(RM) -f libtap.a
|
||||
$(AR) crv libtap.a $(objects)
|
||||
$(RANLIB) libtap.a
|
||||
|
||||
install:
|
||||
|
||||
clean distclean:
|
||||
$(RM) -f *.o *.a core
|
418
tests/tap/basic.c
Normal file
418
tests/tap/basic.c
Normal file
@ -0,0 +1,418 @@
|
||||
/*
|
||||
* Some utility routines for writing tests.
|
||||
*
|
||||
* Herein are a variety of utility routines for writing tests. All routines
|
||||
* of the form ok*() 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.
|
||||
*
|
||||
* Copyright 2009, 2010 Russ Allbery <rra@stanford.edu>
|
||||
* Copyright 2006, 2007, 2008
|
||||
* Board of Trustees, Leland Stanford Jr. University
|
||||
* Copyright (c) 2004, 2005, 2006
|
||||
* by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
|
||||
* 2002, 2003 by The Internet Software Consortium and Rich Salz
|
||||
*
|
||||
* See LICENSE for licensing terms.
|
||||
*/
|
||||
|
||||
#include <errno.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;
|
||||
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));
|
||||
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, ...)
|
||||
{
|
||||
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, ...)
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Skip a test.
|
||||
*/
|
||||
void
|
||||
skip(const char *reason, ...)
|
||||
{
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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, ...)
|
||||
{
|
||||
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)";
|
||||
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 match.
|
||||
*/
|
||||
void
|
||||
is_double(double wanted, double seen, const char *format, ...)
|
||||
{
|
||||
if (wanted == seen)
|
||||
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, ...)
|
||||
{
|
||||
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(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(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(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(stdout);
|
||||
printf("# ");
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
printf(": %s\n", strerror(oerrno));
|
||||
}
|
111
tests/tap/basic.h
Normal file
111
tests/tap/basic.h
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Basic utility routines for the TAP protocol.
|
||||
*
|
||||
* Copyright 2009, 2010 Russ Allbery <rra@stanford.edu>
|
||||
* Copyright 2006, 2007, 2008
|
||||
* Board of Trustees, Leland Stanford Jr. University
|
||||
* Copyright (c) 2004, 2005, 2006
|
||||
* by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
|
||||
* 2002, 2003 by The Internet Software Consortium and Rich Salz
|
||||
*
|
||||
* See LICENSE for licensing terms.
|
||||
*/
|
||||
|
||||
#ifndef TAP_BASIC_H
|
||||
#define TAP_BASIC_H 1
|
||||
|
||||
#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. */
|
||||
void ok(int success, const char *format, ...)
|
||||
__attribute__((__format__(printf, 2, 3)));
|
||||
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, const char *format, ...)
|
||||
__attribute__((__format__(printf, 3, 4)));
|
||||
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)));
|
||||
|
||||
END_DECLS
|
||||
|
||||
#endif /* LIBTEST_H */
|
165
tests/tap/libtap.sh
Normal file
165
tests/tap/libtap.sh
Normal file
@ -0,0 +1,165 @@
|
||||
# Shell function library for test cases.
|
||||
#
|
||||
# Written by Russ Allbery <rra@stanford.edu>
|
||||
# Copyright 2009, 2010 Russ Allbery <rra@stanford.edu>
|
||||
# Copyright 2006, 2007, 2008 Board of Trustees, Leland Stanford Jr. University
|
||||
#
|
||||
# See LICENSE for licensing terms.
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
# 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. Strip
|
||||
# a colon and everything after it off the output if the expected status is
|
||||
# non-zero, since this is probably a system-specific error message.
|
||||
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 [ "$w_status" -ne 0 ] ; then
|
||||
output=`echo "$output" | sed 's/^\([^:]*\):.*/\1/'`
|
||||
fi
|
||||
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
|
||||
}
|
||||
|
||||
# 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 '#' "$@"
|
||||
}
|
Loading…
Reference in New Issue
Block a user