From 7e7f73cf9d7a55cde858a07c1d16bde57006fb6d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 10 Jul 2007 23:20:42 +0200 Subject: [PATCH] cal: add test code This patch allows to override the time() and define a different time by TEST_TIME env. variable. The code has to be compiled with -DTEST_CAL. Signed-off-by: Karel Zak --- misc-utils/Makefile.am | 6 ++++++ misc-utils/cal.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index a9ea5ef4..794be494 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -74,3 +74,9 @@ install-exec-hook:: endif endif + +noinst_PROGRAMS = cal_test +cal_test_SOURCES = cal.c +cal_test_CPPFLAGS = -DTEST_CAL $(AM_CPPFLAGS) +cal_test_LDADD = $(cal_LDADD) + diff --git a/misc-utils/cal.c b/misc-utils/cal.c index dc5848aa..f5ede93d 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -351,7 +351,16 @@ main(int argc, char **argv) { errx(1, _("illegal year value: use 1-9999")); break; case 0: - time(&now); + { +#ifdef TEST_CAL + char *e = getenv("TEST_TIME"); + + if (e && isdigit((unsigned char) *e)) + now = atol(e); + else +#endif + time(&now); + } local_time = localtime(&now); if (isatty(1)) day = local_time->tm_yday + 1; -- 2.39.5