Commit 67c8cb9c authored by Russ Allbery's avatar Russ Allbery

Update to rra-c-util 4.6 and C TAP Harness 1.12

parent 659a1551
......@@ -72,12 +72,15 @@ MAINTAINERCLEANFILES = Makefile.in aclocal.m4 build-aux/compile \
#
# -Wconversion http://bugs.debian.org/488884 (htons warnings)
#
# Last checked against gcc 4.6.1 (2011-05-04).
WARNINGS = -g -O -Wall -Wextra -Wendif-labels -Wformat=2 -Winit-self \
-Wswitch-enum -Wdeclaration-after-statement -Wshadow \
-Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings \
-Wjump-misses-init -Wlogical-op -Wstrict-prototypes \
-Wmissing-prototypes -Wredundant-decls -Wnested-externs -Werror
# Last checked against gcc 4.6.1 (2011-05-04). -D_FORTIFY_SOURCE=2 enables
# warn_unused_result attribute markings on glibc functions on Linux, which
# catches a few more issues.
WARNINGS = -g -O -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wendif-labels \
-Wformat=2 -Winit-self -Wswitch-enum -Wdeclaration-after-statement \
-Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align \
-Wwrite-strings -Wjump-misses-init -Wlogical-op \
-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls \
-Wnested-externs -Werror
warnings:
$(MAKE) V=0 CFLAGS='$(WARNINGS)'
......@@ -94,8 +97,9 @@ tests_runtests_CPPFLAGS = -DSOURCE='"$(abs_top_srcdir)/tests"' \
-DBUILD='"$(abs_top_builddir)/tests"'
tests_tap_libtap_a_CPPFLAGS = -I$(abs_top_srcdir)/tests
tests_tap_libtap_a_SOURCES = tests/tap/basic.c tests/tap/basic.h \
tests/tap/messages.c tests/tap/messages.h tests/tap/process.c \
tests/tap/process.h tests/tap/string.c tests/tap/string.h
tests/tap/macros.h tests/tap/messages.c tests/tap/messages.h \
tests/tap/process.c tests/tap/process.h tests/tap/string.c \
tests/tap/string.h
# All of the test programs.
tests_portable_asprintf_t_SOURCES = tests/portable/asprintf-t.c \
......
......@@ -12,6 +12,21 @@ krb5-sync 2.3 (unreleased)
this error from Active Directory when attempting to change the
password of an account that does not exist.
Update to rra-c-util 4.6:
* Pass --deps to krb5-config except with --enable-reduced-depends.
* Do not assume string is nul-terminated in replacement strdup.
* Avoid using local in the shell TAP library for Solaris portability.
* Silence __attribute__ warnings on more compilers.
Update to C TAP Harness 1.12:
* Suppress plan and summary if bail is called before any tests run.
* Only use feature-test macros when requested or built with gcc -ansi.
* Drop is_double from the C TAP library to avoid requiring -lm.
* Avoid using local in the shell libtap.sh library.
* Silence __attribute__ warnings on more compilers.
krb5-sync 2.2 (2012-01-10)
The name of the plugin is now krb5_sync.so instead of passwd_update.so
......
......@@ -11,7 +11,7 @@ AC_INIT([krb5-sync], [2.2], [rra@stanford.edu])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_LIBOBJ_DIR([portable])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([1.11 check-news foreign silent-rules subdir-objects
AM_INIT_AUTOMAKE([1.11 check-news dist-xz foreign silent-rules subdir-objects
-Wall -Werror])
AM_MAINTAINER_MODE
......@@ -20,7 +20,7 @@ AC_USE_SYSTEM_EXTENSIONS
AM_PROG_CC_C_O
AC_PROG_INSTALL
AM_DISABLE_STATIC
AC_PROG_LIBTOOL
LT_INIT
RRA_LIB_KRB5
RRA_LIB_KRB5_SWITCH
......@@ -43,7 +43,7 @@ RRA_LIB_KRB5_RESTORE
RRA_LIB_LDAP
AC_HEADER_STDBOOL
AC_CHECK_HEADERS([strings.h sys/bittypes.h syslog.h])
AC_CHECK_HEADERS([sys/bittypes.h syslog.h])
AC_CHECK_DECLS([snprintf, vsnprintf])
RRA_C_C99_VAMACROS
RRA_C_GNU_VAMACROS
......
dnl Use krb5-config to get link paths for Kerberos libraries.
dnl
dnl Provides one macro, RRA_KRB5_CONFIG, which attempts to get compiler and
dnl linker flags for a library via krb5-config and sets the appropriate shell
dnl variables. Defines the Autoconf variable PATH_KRB5_CONFIG, which can be
dnl used to find the default path to krb5-config.
dnl
dnl Depends on RRA_ENABLE_REDUCED_DEPENDS.
dnl
dnl The canonical version of this file is maintained in the rra-c-util
dnl package, available at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
dnl
dnl Written by Russ Allbery <rra@stanford.edu>
dnl Copyright 2011, 2012
dnl The Board of Trustees of the Leland Stanford Junior University
dnl
dnl This file is free software; the authors give unlimited permission to copy
dnl and/or distribute it, with or without modifications, as long as this
dnl notice is preserved.
dnl Check for krb5-config in the user's path and set PATH_KRB5_CONFIG. This
dnl is moved into a separate macro so that it can be loaded via AC_REQUIRE,
dnl meaning it will only be run once even if we link with multiple krb5-config
dnl libraries.
AC_DEFUN([_RRA_KRB5_CONFIG_PATH],
[AC_ARG_VAR([PATH_KRB5_CONFIG], [Path to krb5-config])
AC_PATH_PROG([PATH_KRB5_CONFIG], [krb5-config], [],
[${PATH}:/usr/kerberos/bin])])
dnl Check whether the --deps flag is supported by krb5-config. Takes the path
dnl to krb5-config to use. Note that this path is not embedded in the cache
dnl variable, so this macro implicitly assumes that we will always use the
dnl same krb5-config program.
AC_DEFUN([_RRA_KRB5_CONFIG_DEPS],
[AC_REQUIRE([_RRA_KRB5_CONFIG_PATH])
AC_CACHE_CHECK([for --deps support in krb5-config],
[rra_cv_krb5_config_deps],
[AS_IF(["$1" 2>&1 | grep deps >/dev/null 2>&1],
[rra_cv_krb5_config_deps=yes],
[rra_cv_krb5_config_deps=no])])])
dnl Obtain the library flags for a particular library using krb5-config.
dnl Takes the path to the krb5-config program to use, the argument to
dnl krb5-config to use, and the variable prefix under which to store the
dnl library flags.
AC_DEFUN([_RRA_KRB5_CONFIG_LIBS],
[AC_REQUIRE([_RRA_KRB5_CONFIG_PATH])
AC_REQUIRE([RRA_ENABLE_REDUCED_DEPENDS])
_RRA_KRB5_CONFIG_DEPS([$1])
AS_IF([test x"$rra_reduced_depends" = xfalse \
&& test x"$rra_cv_krb5_config_deps" = xyes],
[$3[]_LIBS=`"$1" --deps --libs $2 2>/dev/null`],
[$3[]_LIBS=`"$1" --libs $2 2>/dev/null`])])
dnl Attempt to find the flags for a library using krb5-config. Takes the
dnl following arguments (in order):
dnl
dnl 1. The root directory for the library in question, generally from an
dnl Autoconf --with flag. Used by preference as the path to krb5-config.
dnl
dnl 2. The argument to krb5-config to retrieve flags for this particular
dnl library.
dnl
dnl 3. The variable prefix to use when setting CPPFLAGS and LIBS variables
dnl based on the result of krb5-config.
dnl
dnl 4. Further actions to take if krb5-config was found and supported that
dnl library type.
dnl
dnl 5. Further actions to take if krb5-config could not be used to get flags
dnl for that library type.
dnl
dnl Special-case a krb5-config argument of krb5 and run krb5-config without an
dnl argument if that option was requested and not supported. Old versions of
dnl krb5-config didn't take an argument to specify the library type, but
dnl always returned the flags for libkrb5.
AC_DEFUN([RRA_KRB5_CONFIG],
[AC_REQUIRE([_RRA_KRB5_CONFIG_PATH])
rra_krb5_config_$3=
rra_krb5_config_$3[]_ok=
AS_IF([test x"$1" != x && test -x "$1/bin/krb5-config"],
[rra_krb5_config_$3="$1/bin/krb5-config"],
[rra_krb5_config_$3="$PATH_KRB5_CONFIG"])
AS_IF([test x"$rra_krb5_config_$3" != x && test -x "$rra_krb5_config_$3"],
[AC_CACHE_CHECK([for $2 support in krb5-config], [rra_cv_lib_$3[]_config],
[AS_IF(["$rra_krb5_config_$3" 2>&1 | grep $2 >/dev/null 2>&1],
[rra_cv_lib_$3[]_config=yes],
[rra_cv_lib_$3[]_config=no])])
AS_IF([test "$rra_cv_lib_$3[]_config" = yes],
[$3[]_CPPFLAGS=`"$rra_krb5_config_$3" --cflags $2 2>/dev/null`
_RRA_KRB5_CONFIG_LIBS([$rra_krb5_config_$3], [$2], [$3])
rra_krb5_config_$3[]_ok=yes],
[AS_IF([test x"$2" = xkrb5],
[$3[]_CPPFLAGS=`"$rra_krb5_config_$3" --cflags 2>/dev/null`
$3[]_LIBS=`"$rra_krb5_config_$3" --libs $2 2>/dev/null`
rra_krb5_config_$3[]_ok=yes])])])
AS_IF([test x"$rra_krb5_config_$3[]_ok" = xyes],
[$3[]_CPPFLAGS=`echo "$$3[]_CPPFLAGS" | sed 's%-I/usr/include %%'`
$3[]_CPPFLAGS=`echo "$$3[]_CPPFLAGS" | sed 's%-I/usr/include$%%'`
$4],
[$5])])
......@@ -185,39 +185,21 @@ dnl Determine Kerberos compiler and linker flags from krb5-config. Does the
dnl additional probing we need to do to uncover error handling features, and
dnl falls back on the manual checks.
AC_DEFUN([_RRA_LIB_KRB5_CONFIG],
[AC_ARG_VAR([PATH_KRB5_CONFIG], [Path to krb5-config])
AS_IF([test x"$rra_krb5_root" != x && test -z "$PATH_KRB5_CONFIG"],
[AS_IF([test -x "${rra_krb5_root}/bin/krb5-config"],
[PATH_KRB5_CONFIG="${rra_krb5_root}/bin/krb5-config"])],
[AC_PATH_PROG([PATH_KRB5_CONFIG], [krb5-config], [],
[${PATH}:/usr/kerberos/bin])])
AS_IF([test x"$PATH_KRB5_CONFIG" != x && test -x "$PATH_KRB5_CONFIG"],
[AC_CACHE_CHECK([for krb5 support in krb5-config],
[rra_cv_lib_krb5_config],
[AS_IF(["$PATH_KRB5_CONFIG" 2>&1 | grep krb5 >/dev/null 2>&1],
[rra_cv_lib_krb5_config=yes],
[rra_cv_lib_krb5_config=no])])
AS_IF([test x"$rra_cv_lib_krb5_config" = xyes],
[KRB5_CPPFLAGS=`"$PATH_KRB5_CONFIG" --cflags krb5 2>/dev/null`
KRB5_LIBS=`"$PATH_KRB5_CONFIG" --libs krb5 2>/dev/null`],
[KRB5_CPPFLAGS=`"$PATH_KRB5_CONFIG" --cflags 2>/dev/null`
KRB5_LIBS=`"$PATH_KRB5_CONFIG" --libs 2>/dev/null`])
KRB5_CPPFLAGS=`echo "$KRB5_CPPFLAGS" | sed 's%-I/usr/include %%'`
KRB5_CPPFLAGS=`echo "$KRB5_CPPFLAGS" | sed 's%-I/usr/include$%%'`
_RRA_LIB_KRB5_CHECK([$1])
RRA_LIB_KRB5_SWITCH
AC_CHECK_HEADERS([krb5.h krb5/krb5.h])
AC_CHECK_FUNCS([krb5_get_error_message],
[AC_CHECK_FUNCS([krb5_free_error_message])],
[AC_CHECK_FUNCS([krb5_get_error_string], [],
[AC_CHECK_FUNCS([krb5_get_err_txt], [],
[AC_CHECK_FUNCS([krb5_svc_get_msg],
[AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [],
[RRA_INCLUDES_KRB5])],
[AC_CHECK_HEADERS([et/com_err.h])])])])])
RRA_LIB_KRB5_RESTORE],
[_RRA_LIB_KRB5_PATHS
_RRA_LIB_KRB5_MANUAL([$1])])])
[RRA_KRB5_CONFIG([${rra_krb5_root}], [krb5], [KRB5],
[_RRA_LIB_KRB5_CHECK([$1])
RRA_LIB_KRB5_SWITCH
AC_CHECK_HEADERS([krb5.h krb5/krb5.h])
AC_CHECK_FUNCS([krb5_get_error_message],
[AC_CHECK_FUNCS([krb5_free_error_message])],
[AC_CHECK_FUNCS([krb5_get_error_string], [],
[AC_CHECK_FUNCS([krb5_get_err_txt], [],
[AC_CHECK_FUNCS([krb5_svc_get_msg],
[AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [],
[RRA_INCLUDES_KRB5])],
[AC_CHECK_HEADERS([et/com_err.h])])])])])
RRA_LIB_KRB5_RESTORE],
[_RRA_LIB_KRB5_PATHS
_RRA_LIB_KRB5_MANUAL([$1])])])
dnl The core of the library checking, shared between RRA_LIB_KRB5 and
dnl RRA_LIB_KRB5_OPTIONAL. The single argument, if "true", says to fail if
......
......@@ -29,6 +29,29 @@
# endif
#endif
/*
* We use __alloc_size__, but it was only available in fairly recent versions
* of GCC. Suppress warnings about the unknown attribute if GCC is too old.
* We know that we're GCC at this point, so we can use the GCC variadic macro
* extension, which will still work with versions of GCC too old to have C99
* variadic macro support.
*/
#if !defined(__attribute__) && !defined(__alloc_size__)
# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
# define __alloc_size__(spec, args...) /* empty */
# endif
#endif
/*
* LLVM and Clang pretend to be GCC but don't support all of the __attribute__
* settings that GCC does. For them, suppress warnings about unknown
* attributes on declarations. This unfortunately will affect the entire
* compilation context, but there's no push and pop available.
*/
#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__))
# pragma GCC diagnostic ignored "-Wattributes"
#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.
......
......@@ -33,6 +33,7 @@ char *test_strndup(const char *, size_t);
char *
strndup(const char *s, size_t n)
{
const char *p;
size_t length;
char *copy;
......@@ -40,9 +41,11 @@ strndup(const char *s, size_t n)
errno = EINVAL;
return NULL;
}
length = strlen(s);
if (length > n)
length = n;
/* Don't assume that the source string is nul-terminated. */
for (p = s; (size_t) (p - s) < n && *p != '\0'; p++)
;
length = p - s;
copy = malloc(length + 1);
if (copy == NULL)
return NULL;
......
......@@ -28,9 +28,10 @@ char *test_strndup(const char *, size_t);
int
main(void)
{
char buffer[3];
char *result = NULL;
plan(6);
plan(7);
result = test_strndup("foo", 8);
is_string("foo", result, "strndup longer than string");
......@@ -44,6 +45,10 @@ main(void)
result = test_strndup("foo", 0);
is_string("", result, "strndup of size 0");
free(result);
memcpy(buffer, "foo", 3);
result = test_strndup(buffer, 3);
is_string("foo", result, "strndup of non-nul-terminated string");
free(result);
errno = 0;
result = test_strndup(NULL, 0);
is_string(NULL, result, "strndup of NULL");
......
......@@ -77,8 +77,10 @@
*/
/* Required for fdopen(), getopt(), and putenv(). */
#ifndef _XOPEN_SOURCE
# define _XOPEN_SOURCE 500
#if defined(__STRICT_ANSI__) || defined(PEDANTIC)
# ifndef _XOPEN_SOURCE
# define _XOPEN_SOURCE 500
# endif
#endif
#include <ctype.h>
......
......@@ -6,14 +6,14 @@
* 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.
* constructing more complex tests, skipping tests, reporting errors, setting
* up the TAP output format, or finding things in the test environment.
*
* 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, 2011 Russ Allbery <rra@stanford.edu>
* Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011
* Copyright 2009, 2010, 2011, 2012 Russ Allbery <rra@stanford.edu>
* Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011, 2012
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
......@@ -35,13 +35,7 @@
* 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>
......@@ -54,7 +48,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <tap/basic.h>
#include <tests/tap/basic.h>
/* Windows provides mkdir and rmdir under different names. */
#ifdef _WIN32
......@@ -88,7 +82,9 @@ 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.
* results provided we're still in the original process. This also handles
* printing out the plan if we used plan_lazy(), although that's suppressed if
* we never ran a test (due to an early bail, for example).
*/
static void
finish(void)
......@@ -99,7 +95,7 @@ finish(void)
return;
fflush(stderr);
if (_process != 0 && getpid() == _process) {
if (_lazy) {
if (_lazy && highest > 0) {
printf("1..%lu\n", highest);
_planned = highest;
}
......@@ -352,34 +348,6 @@ is_string(const char *wanted, const char *seen, const char *format, ...)
}
/*
* 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.
......@@ -544,6 +512,31 @@ bstrdup(const char *s)
}
/*
* Copy up to n characters of a string, reporting a fatal error with bail on
* failure. Don't use the system strndup function, since it may not exist and
* the TAP library doesn't assume any portability support.
*/
char *
bstrndup(const char *s, size_t n)
{
const char *p;
char *copy;
size_t length;
/* Don't assume that the source string is nul-terminated. */
for (p = s; (size_t) (p - s) < n && *p != '\0'; p++)
;
length = p - s;
copy = malloc(length + 1);
if (p == NULL)
sysbail("failed to strndup %lu bytes", (unsigned long) length);
memcpy(copy, s, length);
copy[length] = '\0';
return copy;
}
/*
* 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
......
......@@ -4,8 +4,8 @@
* 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, 2011 Russ Allbery <rra@stanford.edu>
* Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011
* Copyright 2009, 2010, 2011, 2012 Russ Allbery <rra@stanford.edu>
* Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011, 2012
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
......@@ -30,34 +30,10 @@
#ifndef TAP_BASIC_H
#define TAP_BASIC_H 1
#include <tests/tap/macros.h>
#include <stdarg.h> /* va_list */
#include <sys/types.h> /* size_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
......@@ -108,9 +84,6 @@ void skip_block(unsigned long count, const char *reason, ...)
/* 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, ...)
......@@ -137,6 +110,8 @@ void *brealloc(void *, size_t)
__attribute__((__alloc_size__(2), __malloc__));
char *bstrdup(const char *)
__attribute__((__malloc__, __nonnull__));
char *bstrndup(const char *, size_t)
__attribute__((__malloc__, __nonnull__));
/*
* Find a test file under BUILD or SOURCE, returning the full path. The
......
# Shell function library for test cases.
#
# Note that while many of the functions in this library could benefit from
# using "local" to avoid possibly hammering global variables, Solaris /bin/sh
# doesn't support local and this library aspires to be portable to Solaris
# Bourne shell. Instead, all private variables are prefixed with "tap_".
#
# 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, 2011 Russ Allbery <rra@stanford.edu>
# Copyright 2009, 2010, 2011, 2012 Russ Allbery <rra@stanford.edu>
# Copyright 2006, 2007, 2008
# The Board of Trustees of the Leland Stanford Junior University
#
......@@ -46,33 +51,35 @@ plan_lazy () {
# Report the test status on exit.
finish () {
local highest looks
highest=`expr "$count" - 1`
tap_highest=`expr "$count" - 1`
if [ "$planned" = 0 ] ; then
echo "1..$highest"
planned="$highest"
echo "1..$tap_highest"
planned="$tap_highest"
fi
looks='# Looks like you'
tap_looks='# Looks like you'
if [ "$planned" -gt 0 ] ; then
if [ "$planned" -gt "$highest" ] ; then
if [ "$planned" -gt "$tap_highest" ] ; then
if [ "$planned" -gt 1 ] ; then
echo "$looks planned $planned tests but only ran $highest"
echo "$tap_looks planned $planned tests but only ran" \
"$tap_highest"
else
echo "$looks planned $planned test but only ran $highest"
echo "$tap_looks planned $planned test but only ran" \
"$tap_highest"
fi
elif [ "$planned" -lt "$highest" ] ; then
local extra
extra=`expr "$highest" - "$planned"`
elif [ "$planned" -lt "$tap_highest" ] ; then
tap_extra=`expr "$tap_highest" - "$planned"`
if [ "$planned" -gt 1 ] ; then
echo "$looks planned $planned tests but ran $extra extra"
echo "$tap_looks planned $planned tests but ran" \
"$tap_extra extra"
else
echo "$looks planned $planned test but ran $extra extra"
echo "$tap_looks planned $planned test but ran" \
"$tap_extra extra"
fi
elif [ "$failed" -gt 0 ] ; then
if [ "$failed" -gt 1 ] ; then
echo "$looks failed $failed tests of $planned"
echo "$tap_looks failed $failed tests of $planned"
else
echo "$looks failed $failed test of $planned"
echo "$tap_looks failed $failed test of $planned"
fi
elif [ "$planned" -gt 1 ] ; then
echo "# All $planned tests successful or skipped"
......@@ -84,10 +91,9 @@ finish () {
# 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"
tap_desc="$1"
if [ -n "$tap_desc" ] ; then
echo "1..0 # skip $tap_desc"
else
echo "1..0 # skip"
fi
......@@ -98,16 +104,15 @@ skip_all () {
# 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"
tap_desc="$1"
if [ -n "$tap_desc" ] ; then
tap_desc=" - $tap_desc"
fi
shift
if "$@" ; then
echo ok $count$desc
echo ok "$count$tap_desc"
else
echo not ok $count$desc
echo not ok "$count$tap_desc"
failed=`expr $failed + 1`
fi
count=`expr $count + 1`
......@@ -122,34 +127,34 @@ skip () {
# 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"
tap_i=$count
tap_end=`expr $count + $1`
shift
while [ "$i" -lt "$end" ] ; do
ok "$desc" "$@"
i=`expr $i + 1`
while [ "$tap_i" -lt "$tap_end" ] ; do
ok "$@"
tap_i=`expr $tap_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`
tap_i=$count
tap_end=`expr $count + $1`
shift
while [ "$i" -lt "$end" ] ; do
while [ "$tap_i" -lt "$tap_end" ] ; do
skip "$@"
i=`expr $i + 1`
tap_i=`expr $tap_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.
#
# This macro must not be called via backticks inside double quotes, since this
# will result in bizarre escaping behavior and lots of extra backslashes on
# Solaris.
puts () {
cat << EOH
$@
......@@ -165,21 +170,21 @@ EOH
# 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"
tap_desc="$1"
shift
w_status="$1"
tap_w_status="$1"
shift
w_output="$1"
tap_w_output="$1"
shift
output=`"$@" 2>&1`
status=$?
if [ $status = $w_status ] && [ x"$output" = x"$w_output" ] ; then
ok "$desc" true
tap_output=`"$@" 2>&1`
tap_status=$?
if [ $tap_status = $tap_w_status ] \
&& [ x"$tap_output" = x"$tap_w_output" ] ; then
ok "$tap_desc" true
else
echo "# saw: ($status) $output"
echo "# not: ($w_status) $w_output"
ok "$desc" false
echo "# saw: ($tap_status) $tap_output"
echo "# not: ($tap_w_status) $tap_w_output"
ok "$tap_desc" false
fi
}
......@@ -189,12 +194,11 @@ ok_program () {
# 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
tap_output=`"$@" 2>&1`
tap_status=$?
tap_output=`puts "$tap_output" | sed 's/^\([^ ]* [^:]*\):.*/\1/'`
puts "$tap_output"
return $tap_status
}
# Bail out with an error message.
......@@ -211,6 +215,9 @@ diag () {
# 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.
#
# 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"
......@@ -223,15 +230,17 @@ test_file_path () {
# Create $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 () {
local tmpdir
if [ -z "$BUILD" ] ; then
tmpdir="./tmp"
tap_tmpdir="./tmp"
else
tmpdir="$BUILD"/tmp
tap_tmpdir="$BUILD"/tmp
fi
if [ ! -d "$tmpdir" ] ; then
mkdir "$tmpdir" || bail "Error creating $tmpdir"
if [ ! -d "$tap_tmpdir" ] ; then
mkdir "$tap_tmpdir" || bail "Error creating $tap_tmpdir"
fi
puts "$tmpdir"
puts "$tap_tmpdir"
}
/*
* Helpful macros for TAP header files.
*
* This is not, strictly speaking, related to TAP, but any TAP add-on is
* probably going to need these macros, so define them in one place so that