]> err.no Git - util-linux/commitdiff
cal: add test code
authorKarel Zak <kzak@redhat.com>
Tue, 10 Jul 2007 21:20:42 +0000 (23:20 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 10 Jul 2007 21:20:42 +0000 (23:20 +0200)
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 <kzak@redhat.com>
misc-utils/Makefile.am
misc-utils/cal.c

index a9ea5ef4b1160d421e976914b1b59d5221e31855..794be494da382289155159938907d54216425530 100644 (file)
@@ -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)
+
index dc5848aae082a9ac76ab672a632cf41752d38245..f5ede93d61ed83563e173e4040aa198692c0c618 100644 (file)
@@ -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;