Module Name:    src
Committed By:   snj
Date:           Sat Oct 11 16:52:56 UTC 2014

Modified Files:
        src/tests/lib/libutil [netbsd-7]: t_parsedate.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.7.8.4 -r1.7.8.5 src/tests/lib/libutil/t_parsedate.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libutil/t_parsedate.c
diff -u src/tests/lib/libutil/t_parsedate.c:1.7.8.4 src/tests/lib/libutil/t_parsedate.c:1.7.8.5
--- src/tests/lib/libutil/t_parsedate.c:1.7.8.4	Sat Oct 11 16:47:00 2014
+++ src/tests/lib/libutil/t_parsedate.c	Sat Oct 11 16:52:56 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: t_parsedate.c,v 1.7.8.4 2014/10/11 16:47:00 snj Exp $ */
+/* $NetBSD: t_parsedate.c,v 1.7.8.5 2014/10/11 16:52:56 snj Exp $ */
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,10 +29,11 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.4 2014/10/11 16:47:00 snj Exp $");
+__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.5 2014/10/11 16:52:56 snj Exp $");
 
 #include <atf-c.h>
 #include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <util.h>
@@ -59,34 +60,55 @@ parsecheck(const char *datestr, const ti
 {
 	time_t t;
 	struct tm tm;
+	char argstr[128];
+
+	/*
+	 * printable version of the args.
+	 *
+	 * Note that printf("%.*d", 0, 0)) prints nothing at all,
+	 * while printf("%.*d", 1, val) prints the value as usual.
+	 */
+	snprintf(argstr, sizeof(argstr), "%s%s%s, %s%.*jd, %s%.*d",
+		/* NULL or \"<datestr>\" */
+		(datestr ? "\"" : ""),
+		(datestr ? datestr : "NULL"),
+		(datestr ? "\"" : ""),
+		/* NULL or *reftime */
+		(reftime ? "" : "NULL"),
+		(reftime ? 1 : 0), 
+		(reftime ? (intmax_t)*reftime : (intmax_t)0), 
+		/* NULL or *zoff */
+		(zoff ? "" : "NULL"),
+		(zoff ? 1 : 0), 
+		(zoff ? *zoff : 0));
 
 	ATF_CHECK_MSG((t = parsedate(datestr, reftime, zoff)) != -1,
-	    "parsedate(\"%s\",,) returned -1\n", datestr);
+	    "parsedate(%s) returned -1\n", argstr);
 	ATF_CHECK(time_to_tm(&t, &tm) != NULL);
 	if (year != ANY)
 		ATF_CHECK_MSG(tm.tm_year + 1900 == year,
-		    "parsedate(\"%s\",,) expected year %d got %d (+1900)\n",
-		    datestr, year, (int)tm.tm_year);
+		    "parsedate(%s) expected year %d got %d (+1900)\n",
+		    argstr, year, (int)tm.tm_year);
 	if (month != ANY)
 		ATF_CHECK_MSG(tm.tm_mon + 1 == month,
-		    "parsedate(\"%s\",,) expected month %d got %d (+1)\n",
-		    datestr, month, (int)tm.tm_mon);
+		    "parsedate(%s) expected month %d got %d (+1)\n",
+		    argstr, month, (int)tm.tm_mon);
 	if (day != ANY)
 		ATF_CHECK_MSG(tm.tm_mday == day,
-		    "parsedate(\"%s\",,) expected day %d got %d\n",
-		    datestr, day, (int)tm.tm_mday);
+		    "parsedate(%s) expected day %d got %d\n",
+		    argstr, day, (int)tm.tm_mday);
 	if (hour != ANY)
 		ATF_CHECK_MSG(tm.tm_hour == hour,
-		    "parsedate(\"%s\",,) expected hour %d got %d\n",
-		    datestr, hour, (int)tm.tm_hour);
+		    "parsedate(%s) expected hour %d got %d\n",
+		    argstr, hour, (int)tm.tm_hour);
 	if (minute != ANY)
 		ATF_CHECK_MSG(tm.tm_min == minute,
-		    "parsedate(\"%s\",,) expected minute %d got %d\n",
-		    datestr, minute, (int)tm.tm_min);
+		    "parsedate(%s) expected minute %d got %d\n",
+		    argstr, minute, (int)tm.tm_min);
 	if (second != ANY)
 		ATF_CHECK_MSG(tm.tm_sec == second,
-		    "parsedate(\"%s\",,) expected second %d got %d\n",
-		    datestr, second, (int)tm.tm_sec);
+		    "parsedate(%s) expected second %d got %d\n",
+		    argstr, second, (int)tm.tm_sec);
 }
 
 ATF_TC(dates);

Reply via email to