Sat Oct 11 16:52:56 2014 UTC ()
Pull up following revision(s) (requested by apb in ticket #135.10):
	tests/lib/libutil/t_parsedate.c: revision 1.12
When tests fail, print all args, notjust the date string.


(snj)
diff -r1.7.8.4 -r1.7.8.5 src/tests/lib/libutil/t_parsedate.c

cvs diff -r1.7.8.4 -r1.7.8.5 src/tests/lib/libutil/t_parsedate.c (expand / switch to unified diff)

--- src/tests/lib/libutil/t_parsedate.c 2014/10/11 16:47:00 1.7.8.4
+++ src/tests/lib/libutil/t_parsedate.c 2014/10/11 16:52:56 1.7.8.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: t_parsedate.c,v 1.7.8.4 2014/10/11 16:47:00 snj Exp $ */ 1/* $NetBSD: t_parsedate.c,v 1.7.8.5 2014/10/11 16:52:56 snj Exp $ */
2/*- 2/*-
3 * Copyright (c) 2010 The NetBSD Foundation, Inc. 3 * Copyright (c) 2010 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the 14 * the documentation and/or other materials provided with the
@@ -19,84 +19,106 @@ @@ -19,84 +19,106 @@
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 22 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
29 */ 29 */
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.4 2014/10/11 16:47:00 snj Exp $"); 32__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.5 2014/10/11 16:52:56 snj Exp $");
33 33
34#include <atf-c.h> 34#include <atf-c.h>
35#include <errno.h> 35#include <errno.h>
 36#include <stdio.h>
36#include <stdlib.h> 37#include <stdlib.h>
37#include <time.h> 38#include <time.h>
38#include <util.h> 39#include <util.h>
39 40
40/* 41/*
41 * ANY is used as a placeholder for values that do not need to be 42 * ANY is used as a placeholder for values that do not need to be
42 * checked. The actual value is arbitrary. We don't use -1 43 * checked. The actual value is arbitrary. We don't use -1
43 * because some tests might want to use -1 as a literal value. 44 * because some tests might want to use -1 as a literal value.
44 */ 45 */
45#define ANY -30215 46#define ANY -30215
46 47
47/* parsecheck -- 48/* parsecheck --
48 * call parsedate(), then call time_to_tm() on the result, 49 * call parsedate(), then call time_to_tm() on the result,
49 * and check that year/month/day/hour/minute/second are as expected. 50 * and check that year/month/day/hour/minute/second are as expected.
50 * 51 *
51 * time_to_tm should usually be localtime_r or gmtime_r. 52 * time_to_tm should usually be localtime_r or gmtime_r.
52 * 53 *
53 * Don't check values specified as ANY. 54 * Don't check values specified as ANY.
54 */ 55 */
55static void 56static void
56parsecheck(const char *datestr, const time_t *reftime, const int *zoff, 57parsecheck(const char *datestr, const time_t *reftime, const int *zoff,
57 struct tm * time_to_tm(const time_t *, struct tm *), 58 struct tm * time_to_tm(const time_t *, struct tm *),
58 int year, int month, int day, int hour, int minute, int second) 59 int year, int month, int day, int hour, int minute, int second)
59{ 60{
60 time_t t; 61 time_t t;
61 struct tm tm; 62 struct tm tm;
 63 char argstr[128];
 64
 65 /*
 66 * printable version of the args.
 67 *
 68 * Note that printf("%.*d", 0, 0)) prints nothing at all,
 69 * while printf("%.*d", 1, val) prints the value as usual.
 70 */
 71 snprintf(argstr, sizeof(argstr), "%s%s%s, %s%.*jd, %s%.*d",
 72 /* NULL or \"<datestr>\" */
 73 (datestr ? "\"" : ""),
 74 (datestr ? datestr : "NULL"),
 75 (datestr ? "\"" : ""),
 76 /* NULL or *reftime */
 77 (reftime ? "" : "NULL"),
 78 (reftime ? 1 : 0),
 79 (reftime ? (intmax_t)*reftime : (intmax_t)0),
 80 /* NULL or *zoff */
 81 (zoff ? "" : "NULL"),
 82 (zoff ? 1 : 0),
 83 (zoff ? *zoff : 0));
62 84
63 ATF_CHECK_MSG((t = parsedate(datestr, reftime, zoff)) != -1, 85 ATF_CHECK_MSG((t = parsedate(datestr, reftime, zoff)) != -1,
64 "parsedate(\"%s\",,) returned -1\n", datestr); 86 "parsedate(%s) returned -1\n", argstr);
65 ATF_CHECK(time_to_tm(&t, &tm) != NULL); 87 ATF_CHECK(time_to_tm(&t, &tm) != NULL);
66 if (year != ANY) 88 if (year != ANY)
67 ATF_CHECK_MSG(tm.tm_year + 1900 == year, 89 ATF_CHECK_MSG(tm.tm_year + 1900 == year,
68 "parsedate(\"%s\",,) expected year %d got %d (+1900)\n", 90 "parsedate(%s) expected year %d got %d (+1900)\n",
69 datestr, year, (int)tm.tm_year); 91 argstr, year, (int)tm.tm_year);
70 if (month != ANY) 92 if (month != ANY)
71 ATF_CHECK_MSG(tm.tm_mon + 1 == month, 93 ATF_CHECK_MSG(tm.tm_mon + 1 == month,
72 "parsedate(\"%s\",,) expected month %d got %d (+1)\n", 94 "parsedate(%s) expected month %d got %d (+1)\n",
73 datestr, month, (int)tm.tm_mon); 95 argstr, month, (int)tm.tm_mon);
74 if (day != ANY) 96 if (day != ANY)
75 ATF_CHECK_MSG(tm.tm_mday == day, 97 ATF_CHECK_MSG(tm.tm_mday == day,
76 "parsedate(\"%s\",,) expected day %d got %d\n", 98 "parsedate(%s) expected day %d got %d\n",
77 datestr, day, (int)tm.tm_mday); 99 argstr, day, (int)tm.tm_mday);
78 if (hour != ANY) 100 if (hour != ANY)
79 ATF_CHECK_MSG(tm.tm_hour == hour, 101 ATF_CHECK_MSG(tm.tm_hour == hour,
80 "parsedate(\"%s\",,) expected hour %d got %d\n", 102 "parsedate(%s) expected hour %d got %d\n",
81 datestr, hour, (int)tm.tm_hour); 103 argstr, hour, (int)tm.tm_hour);
82 if (minute != ANY) 104 if (minute != ANY)
83 ATF_CHECK_MSG(tm.tm_min == minute, 105 ATF_CHECK_MSG(tm.tm_min == minute,
84 "parsedate(\"%s\",,) expected minute %d got %d\n", 106 "parsedate(%s) expected minute %d got %d\n",
85 datestr, minute, (int)tm.tm_min); 107 argstr, minute, (int)tm.tm_min);
86 if (second != ANY) 108 if (second != ANY)
87 ATF_CHECK_MSG(tm.tm_sec == second, 109 ATF_CHECK_MSG(tm.tm_sec == second,
88 "parsedate(\"%s\",,) expected second %d got %d\n", 110 "parsedate(%s) expected second %d got %d\n",
89 datestr, second, (int)tm.tm_sec); 111 argstr, second, (int)tm.tm_sec);
90} 112}
91 113
92ATF_TC(dates); 114ATF_TC(dates);
93 115
94ATF_TC_HEAD(dates, tc) 116ATF_TC_HEAD(dates, tc)
95{ 117{
96 atf_tc_set_md_var(tc, "descr", "Test unambiguous dates" 118 atf_tc_set_md_var(tc, "descr", "Test unambiguous dates"
97 " (PR lib/44255)"); 119 " (PR lib/44255)");
98} 120}
99 121
100ATF_TC_BODY(dates, tc) 122ATF_TC_BODY(dates, tc)
101{ 123{
102 124