1#!/usr/bin/perl 2# 3# In order for MakeMaker to build in the core, nothing can use Fcntl which 4# includes POSIX. devise_date()'s use of strftime() was replaced. This tests 5# that it's identical. It also tests special handling of the POD_MAN_DATE 6# environment variable. 7# 8# Copyright 2009, 2014-2015, 2018 Russ Allbery <rra@cpan.org> 9# 10# This program is free software; you may redistribute it and/or modify it 11# under the same terms as Perl itself. 12# 13# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl 14 15use 5.006; 16use strict; 17use warnings; 18 19use Pod::Man; 20use POSIX qw(strftime); 21 22use Test::More tests => 6; 23 24# Start with environment variables affecting the date stripped. 25local $ENV{SOURCE_DATE_EPOCH}; 26local $ENV{POD_MAN_DATE}; 27 28# Check that the results of device_date matches strftime. There is no input 29# file name, so this will use the current time. 30my $parser = Pod::Man->new; 31is( 32 $parser->devise_date, 33 strftime('%Y-%m-%d', gmtime()), 34 'devise_date matches strftime' 35); 36 37# Set the override environment variable and ensure that it's honored. 38local $ENV{POD_MAN_DATE} = '2014-01-01'; 39is($parser->devise_date, '2014-01-01', 'devise_date honors POD_MAN_DATE'); 40 41# Check that an empty environment variable is honored. 42local $ENV{POD_MAN_DATE} = q{}; 43is($parser->devise_date, q{}, 'devise_date honors empty POD_MAN_DATE'); 44 45# Set another environment variable and ensure that it's honored. 46local $ENV{POD_MAN_DATE}; 47local $ENV{SOURCE_DATE_EPOCH} = 1439390140; 48is($parser->devise_date, '2015-08-12', 'devise_date honors SOURCE_DATE_EPOCH'); 49 50# Check that POD_MAN_DATE overrides SOURCE_DATE_EPOCH 51local $ENV{POD_MAN_DATE} = '2013-01-01'; 52local $ENV{SOURCE_DATE_EPOCH} = 1482676620; 53is($parser->devise_date, '2013-01-01', 54 'devise_date honors POD_MAN_DATE over SOURCE_DATE_EPOCH'); 55 56# Check that an invalid SOURCE_DATE_EPOCH is not accepted 57local $ENV{POD_MAN_DATE}; 58local $ENV{SOURCE_DATE_EPOCH} = '1482676620B'; 59is( 60 $parser->devise_date, 61 strftime('%Y-%m-%d', gmtime()), 62 'devise_date ignores invalid SOURCE_DATE_EPOCH' 63); 64