line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
10
|
|
|
10
|
|
3756
|
use strict; use warnings; |
|
10
|
|
|
10
|
|
79
|
|
|
10
|
|
|
|
|
289
|
|
|
10
|
|
|
|
|
51
|
|
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
352
|
|
2
|
|
|
|
|
|
|
package YAMLScript::Test; |
3
|
|
|
|
|
|
|
|
4
|
10
|
|
|
10
|
|
3676
|
use YAMLScript::Main; |
|
10
|
|
|
|
|
34
|
|
|
10
|
|
|
|
|
353
|
|
5
|
10
|
|
|
10
|
|
4330
|
use Lingy::Test; |
|
10
|
|
|
|
|
51
|
|
|
10
|
|
|
|
|
93
|
|
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
3020
|
use base 'Exporter'; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
1476
|
|
8
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
78
|
use Test::More; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
125
|
|
10
|
10
|
|
|
10
|
|
3542
|
use YAML::PP; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
437
|
|
11
|
|
|
|
|
|
|
|
12
|
10
|
|
|
10
|
|
64
|
use Lingy::Printer; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
295
|
|
13
|
|
|
|
|
|
|
|
14
|
10
|
|
|
10
|
|
75
|
use YAMLScript::Common; |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
2358
|
|
15
|
10
|
|
|
10
|
|
84
|
use YAMLScript::RT; |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
233
|
|
16
|
10
|
|
|
10
|
|
56
|
use YAMLScript::Reader; |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
5182
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $reader = YAMLScript::Reader->new; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$ENV{YAMLSCRIPT_TEST} = 1; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $yamlscript = |
23
|
|
|
|
|
|
|
-f './blib/script/yamlscript' ? './blib/script/yamlscript' : |
24
|
|
|
|
|
|
|
-f './bin/yamlscript' ? './bin/yamlscript' : |
25
|
|
|
|
|
|
|
die "Can't find 'yamlscript' bin script to test"; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $eg = |
28
|
|
|
|
|
|
|
-d 'eg' ? 'eg' : |
29
|
|
|
|
|
|
|
-d 'example' ? 'example' : |
30
|
|
|
|
|
|
|
die "Can't find eg/example directory"; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our @EXPORT = ( |
33
|
|
|
|
|
|
|
@Lingy::Test::EXPORT, |
34
|
|
|
|
|
|
|
qw< |
35
|
|
|
|
|
|
|
$yamlscript |
36
|
|
|
|
|
|
|
test_eval |
37
|
|
|
|
|
|
|
test_ys_to_ly |
38
|
|
|
|
|
|
|
>, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub fmt { |
42
|
104
|
|
|
104
|
0
|
193
|
local $_ = shift; |
43
|
104
|
|
|
|
|
289
|
s/\n/\\n/g; |
44
|
104
|
|
|
|
|
214
|
s/^\s+//; |
45
|
104
|
|
|
|
|
282
|
s/\s+$//; |
46
|
104
|
|
|
|
|
448
|
$_; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub label { |
50
|
58
|
|
|
58
|
0
|
109
|
local $_ = shift; |
51
|
58
|
|
|
|
|
119
|
my ($got, $want) = @_; |
52
|
58
|
|
|
|
|
140
|
s/\$GOT/$got/g; |
53
|
58
|
|
|
|
|
113
|
s/\$WANT/$want/g; |
54
|
58
|
|
|
|
|
124
|
$_; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub map_yaml_tests { |
58
|
8
|
|
|
8
|
0
|
38
|
my ($func, $yaml) = @_; |
59
|
8
|
|
|
|
|
75
|
my $data = YAML::PP->new->load_string($yaml); |
60
|
8
|
50
|
|
|
|
143870
|
if (my $last = $ENV{LAST}) { |
|
|
50
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
$data = [$data->[0 - $last]]; |
62
|
|
|
|
|
|
|
} elsif (length(my $only = $ENV{ONLY})) { |
63
|
0
|
0
|
|
|
|
0
|
die "Invalid setting ONLY='$only'" unless |
64
|
|
|
|
|
|
|
$only =~ /^[1-9]\d*$/; |
65
|
0
|
|
|
|
|
0
|
my $max = @$data; |
66
|
0
|
0
|
|
|
|
0
|
die "You said ONLY='$only', but only $max tests" |
67
|
|
|
|
|
|
|
if $only > $max; |
68
|
0
|
|
|
|
|
0
|
$data = [$data->[$only - 1]]; |
69
|
|
|
|
|
|
|
} |
70
|
8
|
|
|
|
|
59
|
for my $test (@$data) { |
71
|
58
|
|
|
|
|
21786
|
$func->(@$test); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
10
|
|
|
10
|
|
96
|
no warnings 'redefine'; |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
6440
|
|
76
|
|
|
|
|
|
|
sub test_eval { |
77
|
|
|
|
|
|
|
map_yaml_tests sub { |
78
|
7
|
0
|
|
7
|
|
32
|
my ($input, $want, $label) = |
|
|
50
|
|
|
|
|
|
79
|
|
|
|
|
|
|
(@_ == 2) ? @_ : |
80
|
|
|
|
|
|
|
(@_ == 3) ? ($_[1], $_[2], $_[0]) : |
81
|
|
|
|
|
|
|
die; |
82
|
7
|
|
33
|
|
|
29
|
$label //= "'${\fmt($input)}' -> '${\fmt($want)}'"; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
14
|
|
83
|
|
|
|
|
|
|
|
84
|
7
|
|
|
|
|
19
|
my $got = eval { |
85
|
7
|
|
|
|
|
18
|
local $YAMLScript::Reader::read_ys = 1; |
86
|
7
|
|
|
|
|
28
|
join("\n", RT->rep($input)); |
87
|
|
|
|
|
|
|
}; |
88
|
7
|
50
|
|
|
|
726
|
$got = $@ if $@; |
89
|
7
|
|
|
|
|
19
|
chomp $got; |
90
|
|
|
|
|
|
|
|
91
|
7
|
|
|
|
|
13
|
$got =~ s/^Error: //; |
92
|
|
|
|
|
|
|
|
93
|
7
|
|
|
|
|
27
|
$label = label($label. $got, $want); |
94
|
7
|
50
|
|
|
|
20
|
if (ref($want) eq 'Regexp') { |
95
|
0
|
|
|
|
|
0
|
like $got, $want, $label; |
96
|
|
|
|
|
|
|
} else { |
97
|
7
|
|
|
|
|
25
|
is $got, $want, $label; |
98
|
|
|
|
|
|
|
} |
99
|
2
|
|
|
2
|
0
|
293
|
}, @_; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub test_ys_to_ly { |
103
|
|
|
|
|
|
|
map_yaml_tests sub { |
104
|
51
|
50
|
|
51
|
|
220
|
my ($ys, $ly, $label) = |
|
|
100
|
|
|
|
|
|
105
|
|
|
|
|
|
|
(@_ == 2) ? @_ : |
106
|
|
|
|
|
|
|
(@_ == 3) ? ($_[1], $_[2], $_[0]) : |
107
|
|
|
|
|
|
|
die; |
108
|
|
|
|
|
|
|
|
109
|
51
|
|
|
|
|
190
|
$ys =~ s/\A\s+//; |
110
|
51
|
|
|
|
|
101
|
$ly =~ s/\A\s+//; |
111
|
|
|
|
|
|
|
|
112
|
51
|
|
66
|
|
|
172
|
$label //= "'${\fmt($ys)}' -> '${\fmt($ly)}'"; |
|
45
|
|
|
|
|
109
|
|
|
45
|
|
|
|
|
98
|
|
113
|
|
|
|
|
|
|
|
114
|
51
|
|
|
|
|
101
|
my $got; |
115
|
51
|
|
|
|
|
87
|
eval { |
116
|
51
|
|
|
|
|
244
|
my $ast = $reader->read_ys("$ys\n"); |
117
|
50
|
|
|
|
|
231
|
$got = Lingy::Printer->pr_str($ast); |
118
|
|
|
|
|
|
|
}; |
119
|
51
|
100
|
|
|
|
5829
|
$got = $@ if $@; |
120
|
|
|
|
|
|
|
|
121
|
51
|
|
|
|
|
87
|
my $want = $ly; |
122
|
51
|
|
|
|
|
124
|
$label = label($label, $got, $ly); |
123
|
|
|
|
|
|
|
|
124
|
51
|
100
|
|
|
|
140
|
if ($want =~ s{^/(.*)/$}{$1}) { |
125
|
1
|
|
|
|
|
17
|
like $got, qr/$want/, $label; |
126
|
|
|
|
|
|
|
} else { |
127
|
50
|
|
|
|
|
175
|
is $got, $ly, $label; |
128
|
|
|
|
|
|
|
} |
129
|
6
|
|
|
6
|
0
|
759
|
}, @_; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |