Skip to content

Commit 7a14e5b

Browse files
authored
Improve test_strptime_days (#21037)
Use `assert` for checking return value. Use better formatting for displaying results.
1 parent 67ce331 commit 7a14e5b

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

test/core/test_strptime_days.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* found in the LICENSE file.
66
*/
77

8+
// glibc requires _XOPEN_SOURCE to be defined in order to get strptime.
9+
#define _XOPEN_SOURCE
10+
11+
#include <assert.h>
812
#include <time.h>
913
#include <stdio.h>
1014
#include <string.h>
@@ -31,9 +35,14 @@ int main() {
3135
for (int i = 0; i < sizeof(day_tests) / sizeof(day_tests[0]); ++i) {
3236
memset(&tm, '\0', sizeof(tm));
3337
char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm);
38+
assert(ptr);
3439

35-
printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n",
36-
(ptr != NULL && *ptr == '\0') ? "OK" : "ERR", tm.tm_mon + 1,
37-
tm.tm_mday, 1900 + tm.tm_year, tm.tm_wday, tm.tm_yday);
40+
printf("%-23s -> %02d/%02d/%4d (%dth DoW, %3dth DoY)\n",
41+
day_tests[i].input,
42+
tm.tm_mon + 1,
43+
tm.tm_mday,
44+
1900 + tm.tm_year,
45+
tm.tm_wday,
46+
tm.tm_yday);
3847
}
3948
}

test/core/test_strptime_days.out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
OK: 1/1/2000 (6th DoW, 0th DoY)
2-
OK: 3/3/2000 (5th DoW, 62th DoY)
3-
OK: 9/9/1999 (4th DoW, 251th DoY)
4-
OK: 5/2/1999 (0th DoW, 121th DoY)
5-
OK: 5/21/2001 (1th DoW, 140th DoY)
6-
OK: 1/27/2006 (5th DoW, 26th DoY)
7-
OK: 5/21/2001 (1th DoW, 140th DoY)
8-
OK: 7/24/2013 (3th DoW, 204th DoY)
9-
OK: 1/1/2000 (6th DoW, 0th DoY)
10-
OK: 1/1/2000 (6th DoW, 0th DoY)
11-
OK: 5/1/2001 (2th DoW, 120th DoY)
12-
OK: 2/22/2001 (4th DoW, 52th DoY)
1+
2000-01-01 -> 01/01/2000 (6th DoW, 0th DoY)
2+
03/03/00 -> 03/03/2000 (5th DoW, 62th DoY)
3+
9/9/99 -> 09/09/1999 (4th DoW, 251th DoY)
4+
19990502123412 -> 05/02/1999 (0th DoW, 121th DoY)
5+
2001 20 Mon -> 05/21/2001 (1th DoW, 140th DoY)
6+
2006 4 Fri -> 01/27/2006 (5th DoW, 26th DoY)
7+
2001 21 Mon -> 05/21/2001 (1th DoW, 140th DoY)
8+
2013 29 Wed -> 07/24/2013 (3th DoW, 204th DoY)
9+
2000-01-01 08:12:21 AM -> 01/01/2000 (6th DoW, 0th DoY)
10+
2000-01-01 08:12:21 PM -> 01/01/2000 (6th DoW, 0th DoY)
11+
2001 17 Tue -> 05/01/2001 (2th DoW, 120th DoY)
12+
2001 8 Thursday -> 02/22/2001 (4th DoW, 52th DoY)

0 commit comments

Comments
 (0)