devise-date.t revision 1.4
1219820Sjeff#!/usr/bin/perl
2219820Sjeff#
3219820Sjeff# In order for MakeMaker to build in the core, nothing can use Fcntl which
4219820Sjeff# includes POSIX.  devise_date()'s use of strftime() was replaced.  This tests
5219820Sjeff# that it's identical.  It also tests special handling of the POD_MAN_DATE
6219820Sjeff# and SOURCE_DATE_EPOCH environment variables.
7219820Sjeff#
8219820Sjeff# Copyright 2009, 2014-2015, 2018-2019, 2022 Russ Allbery <rra@cpan.org>
9219820Sjeff#
10219820Sjeff# This program is free software; you may redistribute it and/or modify it
11219820Sjeff# under the same terms as Perl itself.
12219820Sjeff#
13219820Sjeff# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
14219820Sjeff
15219820Sjeffuse 5.008;
16219820Sjeffuse strict;
17219820Sjeffuse warnings;
18219820Sjeff
19219820Sjeffuse Pod::Man;
20219820Sjeffuse POSIX qw(strftime);
21219820Sjeff
22219820Sjeffuse Test::More tests => 6;
23219820Sjeff
24219820Sjeff# Start with environment variables affecting the date stripped.
25219820Sjefflocal $ENV{SOURCE_DATE_EPOCH} = undef;
26219820Sjefflocal $ENV{POD_MAN_DATE} = undef;
27219820Sjeff
28219820Sjeff# Check that the results of device_date matches strftime.  There is no input
29219820Sjeff# file name, so this will use the current time.
30219820Sjeffmy $parser = Pod::Man->new;
31219820Sjeffis(
32219820Sjeff    $parser->devise_date,
33219820Sjeff    strftime('%Y-%m-%d', gmtime()),
34219820Sjeff    'devise_date matches strftime',
35219820Sjeff);
36219820Sjeff
37219820Sjeff# Set the override environment variable and ensure that it's honored.
38219820Sjefflocal $ENV{POD_MAN_DATE} = '2014-01-01';
39219820Sjeffis($parser->devise_date, '2014-01-01', 'devise_date honors POD_MAN_DATE');
40219820Sjeff
41219820Sjeff# Check that an empty environment variable is honored.
42219820Sjefflocal $ENV{POD_MAN_DATE} = q{};
43219820Sjeffis($parser->devise_date, q{}, 'devise_date honors empty POD_MAN_DATE');
44219820Sjeff
45219820Sjeff# Set another environment variable and ensure that it's honored.
46219820Sjefflocal $ENV{POD_MAN_DATE} = undef;
47219820Sjefflocal $ENV{SOURCE_DATE_EPOCH} = 1439390140;
48219820Sjeffis($parser->devise_date, '2015-08-12', 'devise_date honors SOURCE_DATE_EPOCH');
49219820Sjeff
50219820Sjeff# Check that POD_MAN_DATE overrides SOURCE_DATE_EPOCH
51219820Sjefflocal $ENV{POD_MAN_DATE} = '2013-01-01';
52219820Sjefflocal $ENV{SOURCE_DATE_EPOCH} = 1482676620;
53219820Sjeffis(
54219820Sjeff    $parser->devise_date, '2013-01-01',
55219820Sjeff    'devise_date honors POD_MAN_DATE over SOURCE_DATE_EPOCH',
56219820Sjeff);
57219820Sjeff
58219820Sjeff# Check that an invalid SOURCE_DATE_EPOCH is not accepted
59219820Sjefflocal $ENV{POD_MAN_DATE} = undef;
60219820Sjefflocal $ENV{SOURCE_DATE_EPOCH} = '1482676620B';
61219820Sjeffis(
62219820Sjeff    $parser->devise_date,
63219820Sjeff    strftime('%Y-%m-%d', gmtime()),
64219820Sjeff    'devise_date ignores invalid SOURCE_DATE_EPOCH',
65219820Sjeff);
66219820Sjeff