1#!/usr/bin/perl 2# 3# Development helper program to regenerate test data. 4# 5# The snippet tests are designed to keep the output fairly stable, but there 6# are a few tests that use complete output with some customization. This 7# helper program regenerates those files using the local installation of 8# podlators. The output can then be reviewed with normal Git tools. 9# 10# Copyright 2022 Russ Allbery <rra@cpan.org> 11# 12# This program is free software; you may redistribute it and/or modify it 13# under the same terms as Perl itself. 14# 15# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl 16 17use 5.008; 18use strict; 19use warnings; 20 21use lib 'blib/lib'; 22 23use File::Spec; 24use Pod::Man; 25use Pod::Text; 26use Pod::Text::Color; 27use Pod::Text::Overstrike; 28use Pod::Text::Termcap; 29 30# Hard-code configuration for Term::Cap to get predictable results. 31#<<< 32local $ENV{COLUMNS} = 80; 33local $ENV{TERM} = 'xterm'; 34local $ENV{TERMPATH} = File::Spec->catfile('t', 'data', 'termcap'); 35local $ENV{TERMCAP} = 'xterm:co=#80:do=^J:md=\\E[1m:us=\\E[4m:me=\\E[m'; 36#>>> 37 38# Map of translators to the file containing the formatted output for the 39# general/basic.t test. 40#<<< 41my %output = ( 42 'Pod::Man' => File::Spec->catfile('t', 'data', 'basic.man'), 43 'Pod::Text' => File::Spec->catfile('t', 'data', 'basic.txt'), 44 'Pod::Text::Color' => File::Spec->catfile('t', 'data', 'basic.clr'), 45 'Pod::Text::Overstrike' => File::Spec->catfile('t', 'data', 'basic.ovr'), 46 'Pod::Text::Termcap' => File::Spec->catfile('t', 'data', 'basic.cap'), 47); 48#>>> 49 50# Regenerate those output files. 51my $input = File::Spec->catfile('t', 'data', 'basic.pod'); 52for my $module (keys(%output)) { 53 my $parser = $module->new(); 54 55 # Run the formatting module. 56 my $output; 57 $parser->output_string(\$output); 58 $parser->parse_file($input); 59 60 # If the test module is Pod::Man, strip off the header. This test does 61 # not attempt to compare it, since it contains version numbers that 62 # change. 63 if ($module eq 'Pod::Man') { 64 $output =~ s{ \A .* \n [.]nh \n }{}xms; 65 } 66 67 # Overwrite the output. 68 open(my $fh, '>', $output{$module}) 69 or die "cannot create $output{$module}: $!\n"; 70 print {$fh} $output 71 or die "cannot write to $output{$module}: $!\n"; 72 close($fh) 73 or die "cannot write to $output{$module}: $!\n"; 74} 75 76# Now switch to the files for the man/encoding.t test. 77$input = File::Spec->catfile('t', 'data', 'man', 'encoding.pod'); 78#<<< 79%output = ( 80 groff => File::Spec->catfile('t', 'data', 'man', 'encoding.groff'), 81 roff => File::Spec->catfile('t', 'data', 'man', 'encoding.roff'), 82 utf8 => File::Spec->catfile('t', 'data', 'man', 'encoding.utf8'), 83); 84#>>> 85 86# For each encoding, load the input, generate the output, and check that the 87# output matches. 88for my $encoding (keys(%output)) { 89 my $parser = Pod::Man->new( 90 encoding => $encoding, 91 center => 'podlators', 92 release => 'testing', 93 ); 94 my $output; 95 $parser->output_string(\$output); 96 $parser->parse_file($input); 97 98 # Strip off the version line. 99 $output =~ s{ ^ [^\n]+ Automatically [ ] generated [ ] by [^\n]+ \n }{}xms; 100 101 # Overwrite the output. 102 open(my $fh, '>', $output{$encoding}) 103 or die "cannot create $output{$encoding}: $!\n"; 104 print {$fh} $output 105 or die "cannot write to $output{$encoding}: $!\n"; 106 close($fh) 107 or die "cannot write to $output{$encoding}: $!\n"; 108} 109