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:
Enji Cooper 2014-08-13 04:56:27 +00:00
parent 9f31240773
commit 5aa45fcb67
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=269904
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_tmp.3
.if ${MK_TESTS} != "no"
SUBDIR+= tests
.endif
.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 <stdlib.h>
#include <libutil.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <inttypes.h>
#include <math.h>
#include <unistd.h>
#include <libutil.h>
#include <limits.h>
extern char * optarg;
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define MAX_STR_FLAGS_RESULT 80
#define MAX_INT_STR_DIGITS 12
@ -490,7 +488,7 @@ static void
testskipped(size_t i)
{
printf("ok %lu # skip - not turned on\n", i);
printf("ok %zu # skip - not turned on\n", i);
}
int
@ -498,10 +496,8 @@ main(int argc, char * const argv[])
{
char *buf;
char *flag_str, *scale_str;
size_t i;
size_t errcnt, tested, skipped;
size_t buflen, errcnt, i, skipped, tested;
int r;
size_t buflen;
int includeNegScale;
int includeExabyteTests;
int verbose;
@ -522,8 +518,8 @@ main(int argc, char * const argv[])
if (buflen != 4)
printf("Warning: buffer size %zu != 4, expect some results to differ.\n", buflen);
printf("1..%lu\n", sizeof test_args / sizeof *test_args);
for (i = 0; i < sizeof test_args / sizeof *test_args; i++) {
printf("1..%zu\n", nitems(test_args));
for (i = 0; i < nitems(test_args); i++) {
/* KLUDGE */
if (test_args[i].num == INT64_MAX && buflen == 4) {
/* 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) {
skipped++;
testskipped(i);
testskipped(i + 1);
continue;
}
if (test_args[i].num >= halfExabyte && ! includeExabyteTests) {
skipped++;
testskipped(i);
testskipped(i + 1);
continue;
}
@ -553,36 +549,46 @@ main(int argc, char * const argv[])
if (r != test_args[i].retval) {
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,
test_args[i].res, test_args[i].num,
test_args[i].res,
(intmax_t)test_args[i].num,
scale_str, flag_str);
else
printf("not ok %lu # return %d != %d\n", i, r,
test_args[i].retval);
printf("not ok %zu # return %d != %d\n",
i + 1, r, test_args[i].retval);
errcnt++;
} else if (strcmp(buf, test_args[i].res) != 0) {
if (verbose)
printf("result mismatch on index %lu, got: \"%s\", expected \"%s\"; num = %" PRId64 ", scale = %s, flags= %s.\n",
i, buf, test_args[i].res, test_args[i].num,
printf("result mismatch on index %zu, got: "
"\"%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);
else
printf("not ok %lu # buf \"%s\" != \"%s\"\n", i,
buf, test_args[i].res);
printf("not ok %zu # buf \"%s\" != \"%s\"\n",
i + 1, buf, test_args[i].res);
errcnt++;
} else {
if (verbose)
printf("successful result on index %lu, returned %d, got: \"%s\"; num = %" PRId64 ", scale = %s, flags= %s.\n",
i, r, buf, test_args[i].num, scale_str,
flag_str);
printf("successful result on index %zu, "
"returned %d, got: \"%s\"; num = %jd, "
"scale = %s, flags= %s.\n",
i, r, buf,
(intmax_t)test_args[i].num,
scale_str, flag_str);
else
printf("ok %lu\n", i);
printf("ok %zu\n", i + 1);
}
tested++;
}
if (verbose)
printf("total errors: %lu/%lu tests, %lu skipped\n", errcnt,
printf("total errors: %zu/%zu tests, %zu skipped\n", errcnt,
tested, skipped);
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