summaryrefslogtreecommitdiff
path: root/cpan/podlators/t/man/devise-date.t
blob: 642d08cc4f4ba5d49b7efb676beedf1d8c0c5703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
#
# In order for MakeMaker to build in the core, nothing can use Fcntl which
# includes POSIX.  devise_date()'s use of strftime() was replaced.  This tests
# that it's identical.  It also tests special handling of the POD_MAN_DATE
# environment variable.
#
# Copyright 2009, 2014, 2015 Russ Allbery <rra@cpan.org>
#
# This program is free software; you may redistribute it and/or modify it
# under the same terms as Perl itself.

use 5.006;
use strict;
use warnings;

use Pod::Man;
use POSIX qw(strftime);

use Test::More tests => 6;

# Start with environment variables affecting the date stripped.
local $ENV{SOURCE_DATE_EPOCH};
local $ENV{POD_MAN_DATE};

# Check that the results of device_date matches strftime.  There is no input
# file name, so this will use the current time.
my $parser = Pod::Man->new;
is(
    $parser->devise_date,
    strftime('%Y-%m-%d', gmtime()),
    'devise_date matches strftime'
);

# Set the override environment variable and ensure that it's honored.
local $ENV{POD_MAN_DATE} = '2014-01-01';
is($parser->devise_date, '2014-01-01', 'devise_date honors POD_MAN_DATE');

# Check that an empty environment variable is honored.
local $ENV{POD_MAN_DATE} = q{};
is($parser->devise_date, q{}, 'devise_date honors empty POD_MAN_DATE');

# Set another environment variable and ensure that it's honored.
local $ENV{POD_MAN_DATE};
local $ENV{SOURCE_DATE_EPOCH} = 1439390140;
is($parser->devise_date, '2015-08-12', 'devise_date honors SOURCE_DATE_EPOCH');

# Check that POD_MAN_DATE overrides SOURCE_DATE_EPOCH
local $ENV{POD_MAN_DATE}      = '2013-01-01';
local $ENV{SOURCE_DATE_EPOCH} = 1482676620;
is($parser->devise_date, '2013-01-01',
   'devise_date honors POD_MAN_DATE over SOURCE_DATE_EPOCH');

# Check that an invalid SOURCE_DATE_EPOCH is not accepted
local $ENV{POD_MAN_DATE};
local $ENV{SOURCE_DATE_EPOCH} = '1482676620B';
is(
    $parser->devise_date,
    strftime('%Y-%m-%d', gmtime()),
    'devise_date ignores invalid SOURCE_DATE_EPOCH'
);