Integrate lib/libutil into the build/kyua

Remove the .t wrappers

Rename all of the TAP test applications from test-<test> to
<test>_test to match the convention described in the TestSuite
wiki page

humanize_number_test.c:

- Fix -Wformat warnings with counter variables
- Fix minor style(9) issues:
-- Header sorting
-- Variable declaration alignment/sorting in main(..)
-- Fit the lines in <80 columns
- Fix an off by one index error in the testcase output [*]
- Remove unnecessary `extern char * optarg;` (this is already provided by
  unistd.h)

Phabric: D555
Approved by: jmmv (mentor)
MFC after: 2 weeks
Obtained from: EMC / Isilon Storage Division [*]
Submitted by: Casey Peel <cpeel@isilon.com> [*]
Sponsored by: EMC / Isilon Storage Division
This commit is contained in:
ngie 2014-08-13 04:56:27 +00:00
parent c904689011
commit cba459dcfd
14 changed files with 55 additions and 97 deletions

View File

@ -81,4 +81,8 @@ MLINKS+=pw_util.3 pw_copy.3 \
pw_util.3 pw_tempname.3 \ pw_util.3 pw_tempname.3 \
pw_util.3 pw_tmp.3 pw_util.3 pw_tmp.3
.if ${MK_TESTS} != "no"
SUBDIR+= tests
.endif
.include <bsd.lib.mk> .include <bsd.lib.mk>

View File

@ -0,0 +1,15 @@
# $FreeBSD$
TESTSDIR= ${TESTSBASE}/lib/libutil
TAP_TESTS_C+= flopen_test
TAP_TESTS_C+= grp_test
TAP_TESTS_C+= humanize_number_test
TAP_TESTS_C+= pidfile_test
TAP_TESTS_C+= trimdomain_test
TAP_TESTS_C+= trimdomain-nodomain_test
DPADD+= ${LIBUTIL}
LDADD+= -lutil
.include <bsd.test.mk>

View File

@ -28,17 +28,15 @@
* *
*/ */
#include <sys/types.h> #include <sys/param.h>
#include <stdlib.h>
#include <libutil.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <math.h> #include <libutil.h>
#include <unistd.h>
#include <limits.h> #include <limits.h>
#include <math.h>
extern char * optarg; #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define MAX_STR_FLAGS_RESULT 80 #define MAX_STR_FLAGS_RESULT 80
#define MAX_INT_STR_DIGITS 12 #define MAX_INT_STR_DIGITS 12
@ -490,7 +488,7 @@ static void
testskipped(size_t i) testskipped(size_t i)
{ {
printf("ok %lu # skip - not turned on\n", i); printf("ok %zu # skip - not turned on\n", i);
} }
int int
@ -498,10 +496,8 @@ main(int argc, char * const argv[])
{ {
char *buf; char *buf;
char *flag_str, *scale_str; char *flag_str, *scale_str;
size_t i; size_t buflen, errcnt, i, skipped, tested;
size_t errcnt, tested, skipped;
int r; int r;
size_t buflen;
int includeNegScale; int includeNegScale;
int includeExabyteTests; int includeExabyteTests;
int verbose; int verbose;
@ -522,8 +518,8 @@ main(int argc, char * const argv[])
if (buflen != 4) if (buflen != 4)
printf("Warning: buffer size %zu != 4, expect some results to differ.\n", buflen); printf("Warning: buffer size %zu != 4, expect some results to differ.\n", buflen);
printf("1..%lu\n", sizeof test_args / sizeof *test_args); printf("1..%zu\n", nitems(test_args));
for (i = 0; i < sizeof test_args / sizeof *test_args; i++) { for (i = 0; i < nitems(test_args); i++) {
/* KLUDGE */ /* KLUDGE */
if (test_args[i].num == INT64_MAX && buflen == 4) { if (test_args[i].num == INT64_MAX && buflen == 4) {
/* Start final tests which require buffer of 6 */ /* Start final tests which require buffer of 6 */
@ -537,12 +533,12 @@ main(int argc, char * const argv[])
if (test_args[i].scale < 0 && ! includeNegScale) { if (test_args[i].scale < 0 && ! includeNegScale) {
skipped++; skipped++;
testskipped(i); testskipped(i + 1);
continue; continue;
} }
if (test_args[i].num >= halfExabyte && ! includeExabyteTests) { if (test_args[i].num >= halfExabyte && ! includeExabyteTests) {
skipped++; skipped++;
testskipped(i); testskipped(i + 1);
continue; continue;
} }
@ -553,36 +549,46 @@ main(int argc, char * const argv[])
if (r != test_args[i].retval) { if (r != test_args[i].retval) {
if (verbose) if (verbose)
printf("wrong return value on index %lu, buflen: %zu, got: %d + \"%s\", expected %d + \"%s\"; num = %" PRId64 ", scale = %s, flags= %s.\n", printf("wrong return value on index %zu, "
"buflen: %zu, got: %d + \"%s\", "
"expected %d + \"%s\"; num = %jd, "
"scale = %s, flags= %s.\n",
i, buflen, r, buf, test_args[i].retval, i, buflen, r, buf, test_args[i].retval,
test_args[i].res, test_args[i].num, test_args[i].res,
(intmax_t)test_args[i].num,
scale_str, flag_str); scale_str, flag_str);
else else
printf("not ok %lu # return %d != %d\n", i, r, printf("not ok %zu # return %d != %d\n",
test_args[i].retval); i + 1, r, test_args[i].retval);
errcnt++; errcnt++;
} else if (strcmp(buf, test_args[i].res) != 0) { } else if (strcmp(buf, test_args[i].res) != 0) {
if (verbose) if (verbose)
printf("result mismatch on index %lu, got: \"%s\", expected \"%s\"; num = %" PRId64 ", scale = %s, flags= %s.\n", printf("result mismatch on index %zu, got: "
i, buf, test_args[i].res, test_args[i].num, "\"%s\", expected \"%s\"; num = %jd, "
"scale = %s, flags= %s.\n",
i, buf, test_args[i].res,
(intmax_t)test_args[i].num,
scale_str, flag_str); scale_str, flag_str);
else else
printf("not ok %lu # buf \"%s\" != \"%s\"\n", i, printf("not ok %zu # buf \"%s\" != \"%s\"\n",
buf, test_args[i].res); i + 1, buf, test_args[i].res);
errcnt++; errcnt++;
} else { } else {
if (verbose) if (verbose)
printf("successful result on index %lu, returned %d, got: \"%s\"; num = %" PRId64 ", scale = %s, flags= %s.\n", printf("successful result on index %zu, "
i, r, buf, test_args[i].num, scale_str, "returned %d, got: \"%s\"; num = %jd, "
flag_str); "scale = %s, flags= %s.\n",
i, r, buf,
(intmax_t)test_args[i].num,
scale_str, flag_str);
else else
printf("ok %lu\n", i); printf("ok %zu\n", i + 1);
} }
tested++; tested++;
} }
if (verbose) if (verbose)
printf("total errors: %lu/%lu tests, %lu skipped\n", errcnt, printf("total errors: %zu/%zu tests, %zu skipped\n", errcnt,
tested, skipped); tested, skipped);
if (errcnt) if (errcnt)

View File

@ -1,13 +0,0 @@
# $FreeBSD$
TESTS= test-trimdomain test-trimdomain-nodomain test-flopen test-grp \
test-pidfile test-humanize_number
CFLAGS+= -g -Wall -Wextra -Werror -lutil
.PHONY: tests
tests: ${TESTS}
for p in ${TESTS}; do ${.OBJDIR}/$$p; done
.PHONY: clean
clean:
-rm -f ${TESTS}

View File

@ -1,12 +0,0 @@
#!/bin/sh
#
# $FreeBSD$
#
base=$(realpath $(dirname $0))
name=$(basename $0 .t)
set -e
cd $base
make -s $name >/dev/null
exec $base/$name

View File

@ -1,12 +0,0 @@
#!/bin/sh
#
# $FreeBSD$
#
base=$(realpath $(dirname $0))
name=$(basename $0 .t)
set -e
cd $base
make -s $name >/dev/null
exec $base/$name

View File

@ -1,10 +0,0 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
executable=`basename $0 .t`
make $executable 2>&1 > /dev/null
exec ./$executable && echo humanize_numbers ok

View File

@ -1,10 +0,0 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
executable=`basename $0 .t`
make $executable 2>&1 > /dev/null
exec ./$executable

View File

@ -1,10 +0,0 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
executable=`basename $0 .t`
make $executable 2>&1 > /dev/null
exec ./$executable