1
+ # !/usr/bin/perl
1
2
# -*- perl -*-
2
3
3
4
use strict;
@@ -19,6 +20,7 @@ sub new
19
20
return bless {
20
21
root => $root ,
21
22
parent => $parent ,
23
+ wtodo => $opt -> {wtodo },
22
24
todo => $opt -> {todo },
23
25
clean => $opt -> {clean },
24
26
style => $opt -> {style },
@@ -47,14 +49,28 @@ package SPEC;
47
49
# ###############################################################################
48
50
49
51
use CSS::Sass;
52
+ use Cwd qw( getcwd) ;
50
53
use Carp qw( croak) ;
51
54
use File::Spec::Functions;
52
55
56
+ my $cwd = getcwd;
57
+ my $cwd_win = $cwd ;
58
+ my $cwd_nix = $cwd ;
59
+ $cwd_win =~ s / [\/\\ ]/ \\ / g ;
60
+ $cwd_nix =~ s / [\/\\ ]/ \/ / g ;
61
+
53
62
# everything is normalized
54
63
my $norm_output = sub ($) {
55
64
$_ [0] =~ s / (?:\r ?\n )+/ \n / g ;
56
65
$_ [0] =~ s / ;(?:\s *;)+/ ;/ g ;
57
66
$_ [0] =~ s / ;\s *}/ }/ g ;
67
+ # normalize debug entries
68
+ $_ [0] =~ s / [^\n ]+(\d +) DEBUG: / $1 : DEBUG: / g ;
69
+ # normalize directory entries
70
+ $_ [0] =~ s /\/ libsass-todo-issues\/ / \/ libsass-issues\/ / g ;
71
+ $_ [0] =~ s /\/ libsass-closed-issues\/ / \/ libsass-issues\/ / g ;
72
+ $_ [0] =~ s /\Q $cwd_win\E [\/\\ ]t[\/\\ ]sass-spec[\/\\ ]/ \/ sass\/ / g ;
73
+ $_ [0] =~ s /\Q $cwd_nix\E [\/\\ ]t[\/\\ ]sass-spec[\/\\ ]/ \/ sass\/ / g ;
58
74
};
59
75
60
76
# only flagged stuff is cleaned
@@ -69,27 +85,62 @@ sub new
69
85
my $pkg = $_ [0];
70
86
my $root = $_ [1];
71
87
my $file = $_ [2];
88
+ my $test = $_ [3];
72
89
return bless {
73
90
root => $root ,
74
91
file => $file ,
92
+ test => $test ,
75
93
}, $pkg ;
76
94
}
77
95
96
+ sub errors
97
+ {
98
+ my ($spec ) = @_ ;
99
+
100
+ local $/ = undef ;
101
+ return -f catfile($spec -> {root }-> {root }, " status" );
102
+ }
103
+
78
104
sub stderr
79
105
{
80
106
my ($spec ) = @_ ;
81
107
82
108
local $/ = undef ;
83
- my $path = catfile($_ [0] -> {root }-> {root }, " error" );
84
- return undef unless -f $path ;
109
+ my $path = catfile($spec -> {root }-> {root }, " error" );
110
+ return " " unless -f $path ;
85
111
open my $fh , " <:raw:utf8" , $path or
86
112
croak " Error opening <" , $path , " >: $! " ;
87
113
binmode $fh ; my $stderr = join " \n " , <$fh >;
114
+ # fully remove debug messaged from error
115
+ $stderr =~ s / [^\n ]+(\d +) DEBUG: [^\n ]*// g ;
88
116
$norm_output -> ($stderr );
117
+ # clean todo warnings (remove all warning blocks)
118
+ $stderr =~ s / ^(?:DEPRECATION )?WARNING(?:[^\n ]+\n )*\n *// gm ;
89
119
$stderr =~ s /\n .*\Z // s ;
90
120
return $stderr ;
121
+ }
122
+
123
+ sub stdmsg
124
+ {
125
+ my ($spec ) = @_ ;
91
126
127
+ local $/ = undef ;
128
+ my $path = catfile($spec -> {root }-> {root }, " error" );
129
+ return ' ' unless -f $path ;
130
+ open my $fh , " <:raw:utf8" , $path or
131
+ croak " Error opening <" , $path , " >: $! " ;
132
+ binmode $fh ; my $stderr = join " \n " , <$fh >;
133
+ $norm_output -> ($stderr );
134
+ if ($spec -> {test }-> {wtodo }) {
135
+ # clean todo warnings (remove all warning blocks)
136
+ $stderr =~ s / ^(?:DEPRECATION )?WARNING(?:[^\n ]+\n )*\n *// gm ;
137
+ }
138
+ # clean error messages
139
+ $stderr =~ s / ^Error(?:[^\n ]+\n )*\n *// gm ;
140
+ $stderr =~ s /\n .*\Z // s ;
141
+ return $stderr ;
92
142
}
143
+
93
144
sub expected
94
145
{
95
146
my ($spec ) = @_ ;
@@ -135,12 +186,22 @@ sub err
135
186
{
136
187
$_ [0]-> execute;
137
188
my $err = $_ [0]-> {err };
138
- return $err unless defined $err ;
189
+ return " " unless defined $err ;
139
190
$norm_output -> ($err );
140
191
$err =~ s /\n .*\Z // s ;
141
192
return $err ;
142
193
}
143
194
195
+ sub msg
196
+ {
197
+ $_ [0]-> execute;
198
+ my $msg = $_ [0]-> {msg };
199
+ return " " unless defined $msg ;
200
+ $norm_output -> ($msg );
201
+ $msg =~ s /\n .*\Z // s ;
202
+ return $msg ;
203
+ }
204
+
144
205
sub execute
145
206
{
146
207
@@ -167,16 +228,18 @@ sub execute
167
228
open OLDFH, ' >&STDERR' ;
168
229
169
230
# redirect stderr to file
170
- open (STDERR , " +>" , " specs.stderr.log" ); select (STDERR ); $| = 1;
231
+ open (STDERR , " +>:raw:utf8 " , " specs.stderr.log" ); select (STDERR ); $| = 1;
171
232
my $css = eval { $comp -> compile_file($spec -> {file }) }; my $err = $@ ;
172
- print STDERR " \n " ; sysseek (STDERR , 0, 0 ); close (STDERR );
233
+ sysseek( STDERR , 0, 0); sysread (STDERR , my $msg , 65536 ); close (STDERR );
173
234
174
235
# reset stderr
175
236
open STDERR , ' >&OLDFH' ;
176
237
177
238
# store the results
178
239
$spec -> {css } = $css ;
179
240
$spec -> {err } = $err ;
241
+ $spec -> {msg } = $msg ;
242
+
180
243
# return the results
181
244
return $css , $err ;
182
245
@@ -216,7 +279,8 @@ sub load_tests()
216
279
{
217
280
218
281
# result
219
- my @specs ; my $filter = qr / huge|unicode\/ report/ ;
282
+ my @specs ; my $ignore = qr / huge|unicode\/ report/ ;
283
+ my $filter = qr /\Q $ARGV [0]\E / if defined $ARGV [0];
220
284
# initial spec test directory entry
221
285
my $root = new DIR;
222
286
$root -> {start } = 0;
@@ -238,9 +302,11 @@ sub load_tests()
238
302
$test -> {start } = $yaml -> {' :start_version' };
239
303
$test -> {end } = $yaml -> {' :end_version' };
240
304
$test -> {ignore } = grep /^libsass$/i,
241
- @{$yaml -> {' :ignore_for' } || []};
305
+ @{$yaml -> {' :ignore_for' } || []};
306
+ $test -> {wtodo } = grep /^libsass$/i,
307
+ @{$yaml -> {' :warning_todo' } || []};
242
308
$test -> {todo } = grep /^libsass$/i,
243
- @{$yaml -> {' :todo' } || []};
309
+ @{$yaml -> {' :todo' } || []};
244
310
}
245
311
246
312
$test -> {clean } = $parent -> {clean } unless $test -> {clean };
@@ -249,19 +315,24 @@ sub load_tests()
249
315
$test -> {start } = $parent -> {start } unless $test -> {start };
250
316
$test -> {end } = $parent -> {end } unless $test -> {end };
251
317
$test -> {ignore } = $parent -> {ignore } unless $test -> {ignore };
318
+ $test -> {wtodo } = $parent -> {wtodo } unless $test -> {wtodo };
252
319
$test -> {todo } = $parent -> {todo } unless $test -> {todo };
253
320
254
321
my $sass = catfile($dir , " input.sass" );
255
322
my $scss = catfile($dir , " input.scss" );
256
323
# have spec test
257
324
if (-e $scss ) {
258
- if (!$filter || !($scss =~ m /$filter / )) {
259
- push @specs , new SPEC($test , $scss );
325
+ if (!$ignore || !($scss =~ m /$ignore / )) {
326
+ if (!$filter || ($scss =~ m /$filter / )) {
327
+ push @specs , new SPEC($test , $scss , $test );
328
+ }
260
329
}
261
330
}
262
331
elsif (-e $sass ) {
263
- if (!$filter || !($sass =~ m /$filter / )) {
264
- push @specs , new SPEC($test , $sass );
332
+ if (!$ignore || !($sass =~ m /$ignore / )) {
333
+ if (!$filter || ($sass =~ m /$filter / )) {
334
+ push @specs , new SPEC($test , $sass , $test );
335
+ }
265
336
}
266
337
}
267
338
@@ -285,27 +356,35 @@ sub load_tests()
285
356
return @specs ;
286
357
}
287
358
288
- use vars qw( @specs) ;
359
+ use vars qw( @tests @ specs) ;
289
360
# specs must be loaded first
290
361
# before registering tests
291
- BEGIN { @specs = grep {
292
- ! $_ -> query(' todo' ) &&
293
- ! $_ -> query(' ignore' ) &&
294
- $_ -> query(' start' ) <= 3.4
295
- } load_tests }
362
+ BEGIN {
363
+ @tests = load_tests;
364
+ @specs = grep {
365
+ ! $_ -> query(' todo' ) &&
366
+ ! $_ -> query(' ignore' ) &&
367
+ $_ -> query(' start' ) <= 3.4
368
+ } @tests ;
369
+ }
370
+
371
+ # report todo tests
372
+ # die join("\n", map {
373
+ # $_->{root}->{root}
374
+ # } grep {
375
+ # $_->query('todo') &&
376
+ # ! $_->query('ignore') &&
377
+ # $_->query('start') <= 3.4
378
+ # } @tests);
296
379
297
- use Test::More tests => scalar @specs ;
380
+ use Test::More tests => 3 * scalar @specs ;
298
381
use Test::Differences;
299
382
300
383
# run tests after filtering
301
384
foreach my $spec (@specs )
302
385
{
303
386
# compare the result with expected data
304
- if ($spec -> err) {
305
- eq_or_diff ($spec -> err, $spec -> stderr, $spec -> file)
306
- } elsif ($spec -> expect) {
307
- eq_or_diff ($spec -> result, $spec -> expect, $spec -> file)
308
- } else {
309
- eq_or_diff ($spec -> result, $spec -> result, $spec -> file)
310
- }
387
+ eq_or_diff ($spec -> css, $spec -> expect, " CSS: " . $spec -> file);
388
+ eq_or_diff ($spec -> err, $spec -> stderr, " Errors: " . $spec -> file);
389
+ eq_or_diff ($spec -> msg, $spec -> stdmsg, " Warnings: " . $spec -> file);
311
390
}
0 commit comments