bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tests: add tests of e.g., date -d 'next monday'


From: Jim Meyering
Subject: [PATCH] tests: add tests of e.g., date -d 'next monday'
Date: Sun, 03 May 2009 12:57:51 +0200

This tests for the long-standing relative-date bug fixed
by Giuseppe Scrivano via this change to gnulib's getdate.y:

    Subject: getdate: correctly interpret "next monday" when run on a Monday
    http://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=9b518aa03eb0e

>From 59e8a5e2b28561ee6fcf070b058b787a8fe247d5 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 3 May 2009 06:21:48 +0200
Subject: [PATCH] tests: add tests of e.g., date -d 'next monday'

* tests/misc/date-next-dow: New file.
* tests/Makefile.am (TESTS): Add misc/date-next-dow.
* gnulib: Update submodule to latest, for getdate.y that
handles "next Monday" properly when run on a Monday.
---
 gnulib                   |    2 +-
 tests/Makefile.am        |    1 +
 tests/misc/date-next-dow |   77 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 1 deletions(-)
 create mode 100755 tests/misc/date-next-dow

diff --git a/gnulib b/gnulib
index 278d609..8d08fa0 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 278d609ead8d065b4c4a94705b8fd127c3df367a
+Subproject commit 8d08fa04b902a9fdd504c6ceae2efb8ca650c2a6
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 61a64a1..7fe74c0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -133,6 +133,7 @@ TESTS =                                             \
   tail-2/tail-n0f                              \
   misc/ls-misc                                 \
   misc/date                                    \
+  misc/date-next-dow                           \
   misc/ptx-overrun                             \
   misc/xstrtol                                 \
   misc/od                                      \
diff --git a/tests/misc/date-next-dow b/tests/misc/date-next-dow
new file mode 100755
index 0000000..0bc94e1
--- /dev/null
+++ b/tests/misc/date-next-dow
@@ -0,0 +1,77 @@
+#!/usr/bin/perl
+# Test "date".
+
+# Copyright (C) 2005-2009 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use strict;
+use POSIX qw(strftime);
+
+(my $ME = $0) =~ s|.*/||;
+
+# Turn off localization of executable's output.
address@hidden(LANGUAGE LANG LC_ALL)} = ('C') x 3;
+
+# Export TZ=UTC0 so that zone-dependent strings match.
+$ENV{TZ} = 'UTC0';
+
+my $now = time;
+my @d = localtime ($now);
+my @d_week = localtime ($now + 7 * 24 * 3600);
+my $wday = $d[6];
+my $wday_str = qw(sun mon tue wed thu fri sat)[$wday];
+
+my @Tests =
+    (
+     # test-name, [option, option, ...] {OUT=>"expected-output"}
+     #
+
+     # Running "date -d mon +%a" on a Monday must print Mon.
+     ['dow',  "-d $wday_str +%a", {OUT => ucfirst $wday_str}],
+     # It had better be the same date, too.
+     ['dow2', "-d $wday_str +%F", {OUT => strftime("%F", @d)}],
+
+     ['next-dow', "-d 'next $wday_str' +%F", {OUT => strftime("%F", @d_week)}],
+    );
+
+# Append "\n" to each OUT=> RHS if the expected exit value is either
+# zero or not specified (defaults to zero).
+foreach my $t (@Tests)
+  {
+    my $exit_val;
+    foreach my $e (@$t)
+      {
+        ref $e && ref $e eq 'HASH' && defined $e->{EXIT}
+         and $exit_val = $e->{EXIT};
+      }
+    foreach my $e (@$t)
+      {
+        ref $e && ref $e eq 'HASH' && defined $e->{OUT} && ! $exit_val
+         and $e->{OUT} .= "\n";
+      }
+  }
+
+my $save_temps = $ENV{DEBUG};
+my $verbose = $ENV{VERBOSE};
+
+my $prog = 'date';
+my $fail = run_tests ($ME, $prog, address@hidden, $save_temps, $verbose);
+
+# Skip the test if the starting and stopping day numbers differ.
+my @d_post = localtime (time);
+$d_post[7] == $d[7]
+  or (warn "$ME: test straddled a day boundary; skipped"), exit 77;
+
+exit $fail;
--
1.6.3.rc4.190.g4648




reply via email to

[Prev in Thread] Current Thread [Next in Thread]