#!perl use strict; use warnings; use Test::More tests => 39; use Test::Differences; use IO::CaptureOutput qw(capture_exec); use File::Temp qw(tempfile); use File::Basename qw(fileparse); my $CURYEAR = (localtime)[5] + 1900; my @perl = ( $^X, '-Ilib' ); push @perl, '-MDevel::Cover=-silent,1,-db,cover_db,-ignore,.,+select,advent,+select,Advent' if exists $INC{'Devel/Cover.pm'}; my @files = ( [ 'ex/sample.pod', 'ex/sample.html', 'Possible SPELLING ERRORS: href lt pre mispelling ', ], [ 'ex/getting_started.pod', 'ex/getting_started.html', '', ], [ 'ex/footnotes.pod', 'ex/footnotes.html', 'Possible SPELLING ERRORS: sourcedcode ', ], [ '+', undef, '', 'B', '

test

' ], [ '-', undef, '', 'B', qq{ $CURYEAR Perl Advent Calendar:

Perl Advent Calendar $CURYEAR-12-00

} ], [ '-', undef, '', "=for advent_title blah\n\nfoo mispelling bar", q{ blah

blah

foo mispelling bar

View Source (POD)

}, [qw/--noadvent --css=foo.css --nospellcheck/] ], [ '+', undef, 'Possible SPELLING ERRORS: z1 ', 'B', '

z1

' ], ); foreach my $info ( @files ){ my ( $podfile, $htmlfile, $errors, $stdin, $snippet, $args ) = @$info; $args ||= []; my $html = $stdin ? $snippet . "\n" : do{ local $/ = undef; open FILE, '<', $htmlfile; } ; my $tmpsrc = ''; if ( $stdin && $stdin =~ /\n/ ) { my ($fh, $filename) = File::Temp::tempfile(); print $fh $stdin; ($podfile, $stdin) = ($filename, undef); # HACK for win32, where multi-line echo won't work. $tmpsrc = File::Basename::fileparse($filename); } my ($stdout, $stderr, $success, $exit_code) = $stdin ? capture_exec( join ' ', "echo '$stdin' |" , @perl, 'bin/pod2advent', $podfile, @$args ) : capture_exec( @perl, 'bin/pod2advent', $podfile, @$args ) ; is($success, 1, "[$podfile] success"); is($exit_code, 0, "[$podfile] exit code"); s/^$//m for $html, $stdout; $stdout =~ s/$tmpsrc/==TMPFILE==/g if $tmpsrc; SKIP: { skip 'spellcheck disabled', 3 if $stderr =~ /Couldn't load Text::Aspell -- spellchecking disabled./; eq_or_diff($stderr, $errors, "[$podfile] errors match"); ok( $stdout, "[$podfile] got output" ) or skip 'no output!', 1; eq_or_diff($stdout, $html, "[$podfile] output matches"); } } my ($stdout, $stderr, $success, $exit_code) = capture_exec( @perl, 'bin/pod2advent'); is($success, 0, "[no args] failed"); ok($exit_code>>8, "[no args] exit code"); eq_or_diff($stdout, '', "[no args] file matches"); SKIP: { skip 'spellcheck disabled', 1 if $stderr =~ /Couldn't load Text::Aspell -- spellchecking disabled./; eq_or_diff($stderr, "need pod filename, or - for file on stdin, or + for snippet on stdin at bin/pod2advent line 8.\n", "[no args] errors match"); }