File: devise-date.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (68 lines) | stat: -rw-r--r-- 2,443 bytes parent folder | download
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
62
63
64
65
66
67
68
#!/usr/bin/perl
#
# Tests the handling of the date added to the man page header in the output of
# Pod::Man.
#
# Copyright 2009, 2014-2015, 2018-2019, 2022, 2024 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.
#
# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl

use 5.012;
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} = undef;
local $ENV{POD_MAN_DATE} = undef;

# 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;
my $expected_old = strftime('%Y-%m-%d', gmtime());
my $seen = $parser->devise_date();
my $expected_new = strftime('%Y-%m-%d', gmtime());
my $expected = ($seen eq $expected_old) ? $expected_old : $expected_new;
is($seen, $expected, '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} = undef;
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 and the code falls
# back on using the current time.  Be careful to avoid false failures if the
# test is run exactly at the transition from one day to the next.
local $ENV{POD_MAN_DATE} = undef;
local $ENV{SOURCE_DATE_EPOCH} = '1482676620B';
$expected_old = strftime('%Y-%m-%d', gmtime());
$seen = $parser->devise_date();
$expected_new = strftime('%Y-%m-%d', gmtime());
$expected = ($seen eq $expected_old) ? $expected_old : $expected_new;
is(
    $parser->devise_date,
    $expected,
    'devise_date ignores invalid SOURCE_DATE_EPOCH',
);