line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
10
|
|
|
10
|
|
3674
|
use strict; use warnings; |
|
10
|
|
|
10
|
|
69
|
|
|
10
|
|
|
|
|
282
|
|
|
10
|
|
|
|
|
46
|
|
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
353
|
|
2
|
|
|
|
|
|
|
package YAMLScript::Test; |
3
|
|
|
|
|
|
|
|
4
|
10
|
|
|
10
|
|
3760
|
use YAMLScript::Main; |
|
10
|
|
|
|
|
39
|
|
|
10
|
|
|
|
|
366
|
|
5
|
10
|
|
|
10
|
|
4508
|
use Lingy::Test; |
|
10
|
|
|
|
|
54
|
|
|
10
|
|
|
|
|
95
|
|
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
3147
|
use base 'Exporter'; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
1560
|
|
8
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
76
|
use Test::More; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
138
|
|
10
|
10
|
|
|
10
|
|
4298
|
use YAML::PP; |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
481
|
|
11
|
|
|
|
|
|
|
|
12
|
10
|
|
|
10
|
|
74
|
use Lingy::Printer; |
|
10
|
|
|
|
|
31
|
|
|
10
|
|
|
|
|
296
|
|
13
|
|
|
|
|
|
|
|
14
|
10
|
|
|
10
|
|
59
|
use YAMLScript::Common; |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
2422
|
|
15
|
10
|
|
|
10
|
|
83
|
use YAMLScript::RT; |
|
10
|
|
|
|
|
32
|
|
|
10
|
|
|
|
|
237
|
|
16
|
10
|
|
|
10
|
|
56
|
use YAMLScript::Reader; |
|
10
|
|
|
|
|
34
|
|
|
10
|
|
|
|
|
5492
|
|
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
|
|
|
|
|
292
|
s/\n/\\n/g; |
44
|
104
|
|
|
|
|
222
|
s/^\s+//; |
45
|
104
|
|
|
|
|
298
|
s/\s+$//; |
46
|
104
|
|
|
|
|
438
|
$_; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub label { |
50
|
58
|
|
|
58
|
0
|
114
|
local $_ = shift; |
51
|
58
|
|
|
|
|
126
|
my ($got, $want) = @_; |
52
|
58
|
|
|
|
|
136
|
s/\$GOT/$got/g; |
53
|
58
|
|
|
|
|
103
|
s/\$WANT/$want/g; |
54
|
58
|
|
|
|
|
125
|
$_; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub map_yaml_tests { |
58
|
8
|
|
|
8
|
0
|
37
|
my ($func, $yaml) = @_; |
59
|
8
|
|
|
|
|
79
|
my $data = YAML::PP->new->load_string($yaml); |
60
|
8
|
50
|
|
|
|
145439
|
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
|
|
|
|
|
50
|
for my $test (@$data) { |
71
|
58
|
|
|
|
|
22029
|
$func->(@$test); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
10
|
|
|
10
|
|
107
|
no warnings 'redefine'; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
6744
|
|
76
|
|
|
|
|
|
|
sub test_eval { |
77
|
|
|
|
|
|
|
map_yaml_tests sub { |
78
|
7
|
0
|
|
7
|
|
31
|
my ($input, $want, $label) = |
|
|
50
|
|
|
|
|
|
79
|
|
|
|
|
|
|
(@_ == 2) ? @_ : |
80
|
|
|
|
|
|
|
(@_ == 3) ? ($_[1], $_[2], $_[0]) : |
81
|
|
|
|
|
|
|
die; |
82
|
7
|
|
33
|
|
|
28
|
$label //= "'${\fmt($input)}' -> '${\fmt($want)}'"; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
18
|
|
83
|
|
|
|
|
|
|
|
84
|
7
|
|
|
|
|
16
|
my $got = eval { |
85
|
7
|
|
|
|
|
12
|
local $YAMLScript::Reader::read_ys = 1; |
86
|
7
|
|
|
|
|
27
|
join("\n", RT->rep($input)); |
87
|
|
|
|
|
|
|
}; |
88
|
7
|
50
|
|
|
|
715
|
$got = $@ if $@; |
89
|
7
|
|
|
|
|
17
|
chomp $got; |
90
|
|
|
|
|
|
|
|
91
|
7
|
|
|
|
|
13
|
$got =~ s/^Error: //; |
92
|
|
|
|
|
|
|
|
93
|
7
|
|
|
|
|
30
|
$label = label($label. $got, $want); |
94
|
7
|
50
|
|
|
|
21
|
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
|
277
|
}, @_; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub test_ys_to_ly { |
103
|
|
|
|
|
|
|
map_yaml_tests sub { |
104
|
51
|
50
|
|
51
|
|
247
|
my ($ys, $ly, $label) = |
|
|
100
|
|
|
|
|
|
105
|
|
|
|
|
|
|
(@_ == 2) ? @_ : |
106
|
|
|
|
|
|
|
(@_ == 3) ? ($_[1], $_[2], $_[0]) : |
107
|
|
|
|
|
|
|
die; |
108
|
|
|
|
|
|
|
|
109
|
51
|
|
|
|
|
195
|
$ys =~ s/\A\s+//; |
110
|
51
|
|
|
|
|
99
|
$ly =~ s/\A\s+//; |
111
|
|
|
|
|
|
|
|
112
|
51
|
|
66
|
|
|
167
|
$label //= "'${\fmt($ys)}' -> '${\fmt($ly)}'"; |
|
45
|
|
|
|
|
126
|
|
|
45
|
|
|
|
|
99
|
|
113
|
|
|
|
|
|
|
|
114
|
51
|
|
|
|
|
94
|
my $got; |
115
|
51
|
|
|
|
|
90
|
eval { |
116
|
51
|
|
|
|
|
231
|
my $ast = $reader->read_ys("$ys\n"); |
117
|
50
|
|
|
|
|
218
|
$got = Lingy::Printer->pr_str($ast); |
118
|
|
|
|
|
|
|
}; |
119
|
51
|
100
|
|
|
|
5785
|
$got = $@ if $@; |
120
|
|
|
|
|
|
|
|
121
|
51
|
|
|
|
|
93
|
my $want = $ly; |
122
|
51
|
|
|
|
|
133
|
$label = label($label, $got, $ly); |
123
|
|
|
|
|
|
|
|
124
|
51
|
100
|
|
|
|
146
|
if ($want =~ s{^/(.*)/$}{$1}) { |
125
|
1
|
|
|
|
|
18
|
like $got, qr/$want/, $label; |
126
|
|
|
|
|
|
|
} else { |
127
|
50
|
|
|
|
|
151
|
is $got, $ly, $label; |
128
|
|
|
|
|
|
|
} |
129
|
6
|
|
|
6
|
0
|
836
|
}, @_; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |