From 8d77279934f4257a0ea5c7f3ac29f99f00f0d5f1 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 7 Jan 2017 18:53:28 +0200 Subject: [PATCH] Make tests pass on systems without %s strftime specifier --- lib/App/Lastmsg.pm | 4 +++- t/App-Lastmsg.t | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/App/Lastmsg.pm b/lib/App/Lastmsg.pm index a5a27b5..8d2cce5 100644 --- a/lib/App/Lastmsg.pm +++ b/lib/App/Lastmsg.pm @@ -18,6 +18,8 @@ our @DEFAULT_INBOX; push @DEFAULT_INBOX, "/var/mail/$ENV{USER}" if exists $ENV{USER}; push @DEFAULT_INBOX, "$ENV{HOME}/Maildir" if exists $ENV{HOME}; +sub format_time { strftime '%c', localtime shift } + sub run { my $config = Config::Auto->new(format => 'yaml')->parse; die "No configuration file found\n" unless $config; @@ -94,7 +96,7 @@ sub run { my $addrlen = max map { length } values %lastaddr; for (sort { $lastmsg{$b} <=> $lastmsg{$a} } keys %lastmsg) { - my $time = strftime '%c', localtime $lastmsg{$_}; + my $time = format_time $lastmsg{$_}; printf $OUTPUT_FILEHANDLE "%-${idlen}s %-${addrlen}s %s\n", $_, $lastaddr{$_}, $time; } diff --git a/t/App-Lastmsg.t b/t/App-Lastmsg.t index 2439d3f..a984509 100644 --- a/t/App-Lastmsg.t +++ b/t/App-Lastmsg.t @@ -5,14 +5,9 @@ use warnings; use Test::More tests => 2; BEGIN { use_ok('App::Lastmsg') }; -my $real_strftime = \&POSIX::strftime; - { no warnings 'redefine'; - *App::Lastmsg::strftime = sub { - my ($format, @rest) = @_; - $real_strftime->('%s', @rest) - }; + *App::Lastmsg::format_time = sub { shift }; } chdir 't'; -- 2.30.2