line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
9
|
|
|
9
|
|
3342
|
use strict; use warnings; |
|
9
|
|
|
9
|
|
68
|
|
|
9
|
|
|
|
|
275
|
|
|
9
|
|
|
|
|
53
|
|
|
9
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
340
|
|
2
|
|
|
|
|
|
|
package YAMLScript::Test; |
3
|
|
|
|
|
|
|
|
4
|
9
|
|
|
9
|
|
3349
|
use YAMLScript::Main; |
|
9
|
|
|
|
|
38
|
|
|
9
|
|
|
|
|
319
|
|
5
|
9
|
|
|
9
|
|
3976
|
use Lingy::Test; |
|
9
|
|
|
|
|
47
|
|
|
9
|
|
|
|
|
88
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
2656
|
use base 'Exporter'; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
1340
|
|
8
|
|
|
|
|
|
|
|
9
|
9
|
|
|
9
|
|
70
|
use Test::More; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
107
|
|
10
|
9
|
|
|
9
|
|
2975
|
use YAML::PP; |
|
9
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
412
|
|
11
|
|
|
|
|
|
|
|
12
|
9
|
|
|
9
|
|
61
|
use Lingy::Printer; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
247
|
|
13
|
|
|
|
|
|
|
|
14
|
9
|
|
|
9
|
|
53
|
use YAMLScript::Common; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
2113
|
|
15
|
9
|
|
|
9
|
|
74
|
use YAMLScript::RT; |
|
9
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
190
|
|
16
|
9
|
|
|
9
|
|
51
|
use YAMLScript::Reader; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
4353
|
|
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
|
188
|
local $_ = shift; |
43
|
104
|
|
|
|
|
278
|
s/\n/\\n/g; |
44
|
104
|
|
|
|
|
214
|
s/^\s+//; |
45
|
104
|
|
|
|
|
292
|
s/\s+$//; |
46
|
104
|
|
|
|
|
420
|
$_; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub label { |
50
|
58
|
|
|
58
|
0
|
101
|
local $_ = shift; |
51
|
58
|
|
|
|
|
127
|
my ($got, $want) = @_; |
52
|
58
|
|
|
|
|
133
|
s/\$GOT/$got/g; |
53
|
58
|
|
|
|
|
101
|
s/\$WANT/$want/g; |
54
|
58
|
|
|
|
|
124
|
$_; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub map_yaml_tests { |
58
|
8
|
|
|
8
|
0
|
73
|
my ($func, $yaml) = @_; |
59
|
8
|
|
|
|
|
64
|
my $data = YAML::PP->new->load_string($yaml); |
60
|
8
|
50
|
|
|
|
145208
|
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
|
|
|
|
|
46
|
for my $test (@$data) { |
71
|
58
|
|
|
|
|
18579
|
$func->(@$test); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
9
|
|
|
9
|
|
82
|
no warnings 'redefine'; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
5664
|
|
76
|
|
|
|
|
|
|
sub test_eval { |
77
|
|
|
|
|
|
|
map_yaml_tests sub { |
78
|
7
|
0
|
|
7
|
|
33
|
my ($input, $want, $label) = |
|
|
50
|
|
|
|
|
|
79
|
|
|
|
|
|
|
(@_ == 2) ? @_ : |
80
|
|
|
|
|
|
|
(@_ == 3) ? ($_[1], $_[2], $_[0]) : |
81
|
|
|
|
|
|
|
die; |
82
|
7
|
|
33
|
|
|
26
|
$label //= "'${\fmt($input)}' -> '${\fmt($want)}'"; |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
15
|
|
83
|
|
|
|
|
|
|
|
84
|
7
|
|
|
|
|
15
|
my $got = eval { |
85
|
7
|
|
|
|
|
14
|
local $YAMLScript::Reader::read_ys = 1; |
86
|
7
|
|
|
|
|
24
|
join("\n", RT->rep($input)); |
87
|
|
|
|
|
|
|
}; |
88
|
7
|
50
|
|
|
|
679
|
$got = $@ if $@; |
89
|
7
|
|
|
|
|
15
|
chomp $got; |
90
|
|
|
|
|
|
|
|
91
|
7
|
|
|
|
|
12
|
$got =~ s/^Error: //; |
92
|
|
|
|
|
|
|
|
93
|
7
|
|
|
|
|
25
|
$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
|
|
|
|
|
23
|
is $got, $want, $label; |
98
|
|
|
|
|
|
|
} |
99
|
2
|
|
|
2
|
0
|
306
|
}, @_; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub test_ys_to_ly { |
103
|
|
|
|
|
|
|
map_yaml_tests sub { |
104
|
51
|
50
|
|
51
|
|
209
|
my ($ys, $ly, $label) = |
|
|
100
|
|
|
|
|
|
105
|
|
|
|
|
|
|
(@_ == 2) ? @_ : |
106
|
|
|
|
|
|
|
(@_ == 3) ? ($_[1], $_[2], $_[0]) : |
107
|
|
|
|
|
|
|
die; |
108
|
|
|
|
|
|
|
|
109
|
51
|
|
|
|
|
194
|
$ys =~ s/\A\s+//; |
110
|
51
|
|
|
|
|
102
|
$ly =~ s/\A\s+//; |
111
|
|
|
|
|
|
|
|
112
|
51
|
|
66
|
|
|
169
|
$label //= "'${\fmt($ys)}' -> '${\fmt($ly)}'"; |
|
45
|
|
|
|
|
135
|
|
|
45
|
|
|
|
|
92
|
|
113
|
|
|
|
|
|
|
|
114
|
51
|
|
|
|
|
94
|
my $got; |
115
|
51
|
|
|
|
|
91
|
eval { |
116
|
51
|
|
|
|
|
229
|
my $ast = $reader->read_ys("$ys\n"); |
117
|
50
|
|
|
|
|
222
|
$got = Lingy::Printer->pr_str($ast); |
118
|
|
|
|
|
|
|
}; |
119
|
51
|
100
|
|
|
|
5802
|
$got = $@ if $@; |
120
|
|
|
|
|
|
|
|
121
|
51
|
|
|
|
|
95
|
my $want = $ly; |
122
|
51
|
|
|
|
|
124
|
$label = label($label, $got, $ly); |
123
|
|
|
|
|
|
|
|
124
|
51
|
100
|
|
|
|
132
|
if ($want =~ s{^/(.*)/$}{$1}) { |
125
|
1
|
|
|
|
|
19
|
like $got, qr/$want/, $label; |
126
|
|
|
|
|
|
|
} else { |
127
|
50
|
|
|
|
|
174
|
is $got, $ly, $label; |
128
|
|
|
|
|
|
|
} |
129
|
6
|
|
|
6
|
0
|
853
|
}, @_; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |