|
| 1 | +#!perl |
| 2 | + |
| 3 | +use 5.018; |
| 4 | +use strict; |
| 5 | +use warnings; |
| 6 | +use Test::More; # tests=>27; |
| 7 | +use Capture::Tiny 'capture_stdout'; |
| 8 | +use File::Spec; |
| 9 | + |
| 10 | +BEGIN { |
| 11 | + use_ok( 'XML::Axk::Core' ) || print "Bail out!\n"; |
| 12 | +} |
| 13 | + |
| 14 | +diag( "Testing XML::Axk::Core $XML::Axk::Core::VERSION, Perl $], $^X" ); |
| 15 | + |
| 16 | +sub localpath { |
| 17 | + state $voldir = [File::Spec->splitpath(__FILE__)]; |
| 18 | + return File::Spec->catpath($voldir->[0], $voldir->[1], shift) |
| 19 | +} |
| 20 | + |
| 21 | +# Inline script, operation at runtime ============================= {{{1 |
| 22 | +{ |
| 23 | + my $core = XML::Axk::Core->new(); |
| 24 | + $core->load_script_text('pre_all { print 42 }','filename',1); |
| 25 | + |
| 26 | + my $out = capture_stdout { $core->run(); }; |
| 27 | + is($out, '42', 'inline script runs'); |
| 28 | +} |
| 29 | + |
| 30 | +# }}}1 |
| 31 | +# Inline script, operation at load time =========================== {{{1 |
| 32 | +{ |
| 33 | + my $core = XML::Axk::Core->new(); |
| 34 | + my $out = capture_stdout { |
| 35 | + $core->load_script_text('print 42','filename',1); |
| 36 | + }; |
| 37 | + is($out, '42', 'inline script runs load-time statements'); |
| 38 | + |
| 39 | + my $out2 = capture_stdout { $core->run(); }; |
| 40 | + is($out2, '', 'no run-time statements in inline script'); |
| 41 | +} |
| 42 | + |
| 43 | +# }}}1 |
| 44 | +# Script on disk ================================================== {{{1 |
| 45 | +{ |
| 46 | + my $core = XML::Axk::Core->new(); |
| 47 | + $core->load_script_file(localpath '02.axk'); |
| 48 | + |
| 49 | + my $out = capture_stdout { $core->run(); }; |
| 50 | + is($out, '1337', 'on-disk script runs'); |
| 51 | +} |
| 52 | + |
| 53 | +# }}}1 |
| 54 | +# Script with no language indicator =============================== {{{1 |
| 55 | +{ |
| 56 | + my $core = XML::Axk::Core->new(); |
| 57 | + eval { $core->load_script_file(localpath '02-noL.axk'); }; |
| 58 | + my $err = $@; |
| 59 | + like($err, qr/No language \(Ln\) specified/, 'detects missing Ln'); |
| 60 | +} |
| 61 | + |
| 62 | +# }}}1 |
| 63 | + |
| 64 | +done_testing(); |
| 65 | + |
| 66 | +# vi: set ts=4 sts=4 sw=4 et ai fdm=marker fdl=1: # |
0 commit comments