From 0c8a4b80f9d29ef759e3c9f59dfeeb04471ccb6e Mon Sep 17 00:00:00 2001 From: kre Date: Tue, 21 Mar 2017 20:06:27 +0000 Subject: [PATCH] PR lib/52101 Add 6 extra tests for the 12am/12pm bug - all currently expected to fail. (That is, 6 subtests of the "times" test will fail, all new ones)> While here, when parsedate() fails (returns -1) avoid converting that failure value (-1) to a struct tm (1969-12-31T23:59:59 UTC) and then comparing the values with those expected by the test, and complaining about all of those (where ANY was not permitted) that don't match... --- tests/lib/libutil/t_parsedate.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/lib/libutil/t_parsedate.c b/tests/lib/libutil/t_parsedate.c index c78df58b6b1c..ef30862ec256 100644 --- a/tests/lib/libutil/t_parsedate.c +++ b/tests/lib/libutil/t_parsedate.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_parsedate.c,v 1.25 2016/06/22 15:01:38 kre Exp $ */ +/* $NetBSD: t_parsedate.c,v 1.26 2017/03/21 20:06:27 kre Exp $ */ /*- * Copyright (c) 2010, 2015 The NetBSD Foundation, Inc. * All rights reserved. @@ -29,7 +29,7 @@ */ #include -__RCSID("$NetBSD: t_parsedate.c,v 1.25 2016/06/22 15:01:38 kre Exp $"); +__RCSID("$NetBSD: t_parsedate.c,v 1.26 2017/03/21 20:06:27 kre Exp $"); #include #include @@ -84,6 +84,9 @@ parsecheck(const char *datestr, const time_t *reftime, const int *zoff, ATF_CHECK_MSG((t = parsedate(datestr, reftime, zoff)) != -1, "parsedate(%s) returned -1\n", argstr); + if (t == -1) + return; + ATF_CHECK(time_to_tm(&t, &tm) != NULL); if (year != ANY) ATF_CHECK_MSG(tm.tm_year + 1900 == year, @@ -180,6 +183,26 @@ ATF_TC_BODY(times, tc) ANY, ANY, ANY, 0, 0, 0); parsecheck("noon", NULL, NULL, localtime_r, ANY, ANY, ANY, 12, 0, 0); + + atf_tc_expect_fail("PR lib/52101"); + + parsecheck("12:30 am", NULL, NULL, localtime_r, + ANY, ANY, ANY, 0, 30, 0); + parsecheck("12:30 pm", NULL, NULL, localtime_r, + ANY, ANY, ANY, 12, 20, 0); + + /* + * Technically, these are invalid, noon and midnight + * are neither am, nor pm, but this is what people expect... + */ + parsecheck("12:00:00 am", NULL, NULL, localtime_r, + ANY, ANY, ANY, 0, 0, 0); + parsecheck("12:00:00 pm", NULL, NULL, localtime_r, + ANY, ANY, ANY, 12, 0, 0); + parsecheck("12am", NULL, NULL, localtime_r, + ANY, ANY, ANY, 0, 0, 0); + parsecheck("12pm", NULL, NULL, localtime_r, + ANY, ANY, ANY, 12, 0, 0); } ATF_TC(dsttimes);