Skip to content

Commit d263a08

Browse files
author
Chris White
committed
Added tests
1 parent f2c43d0 commit d263a08

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

t/02-basic-core.t

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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: #

t/02-noL.axk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 02-noL.axk: used by 02-basic*.t
2+
#L1
3+
print '1337'
4+
# vi: set ts=4 sts=4 sw=4 et ai ft=perl fdm=marker fdl=1: #

t/02.axk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# 02.axk: used by 02-basic*.t
22
L1
3-
print '1337'
3+
#use Devel::StackTrace;
4+
#say "02.axk:\n", Devel::StackTrace->new->as_string;
5+
pre_all { # otherwise it happens during load
6+
print '1337'
7+
};
48
# vi: set ts=4 sts=4 sw=4 et ai ft=perl fdm=marker fdl=1: #

t/03-TODO.t

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!perl
2+
3+
use 5.018;
4+
use strict;
5+
use warnings;
6+
use Test::More;
7+
8+
ok(1,"Not here yet!");
9+
10+
done_testing();
11+
__END__
12+
13+
./run -e 'perform { say $E; } xpath("//item"); perform { say $E; } xpath(q<//@attrname>);' ex/ex1.xml
14+
# Because Perl tries to interpolate an array into "//@attrname"
15+
16+
# vi: set ts=4 sts=4 sw=4 et ai fdm=marker fdl=1: #

0 commit comments

Comments
 (0)