21
21
#
22
22
# runs a test and check its output
23
23
24
+ my $color_output_enabled ;
25
+ sub with_color {
26
+ my ($text , $color ) = @_ ;
27
+ if ($color_output_enabled ) {
28
+ colored($text , $color );
29
+ } else {
30
+ $text ;
31
+ }
32
+ }
33
+
24
34
sub run ($$$$$) {
25
35
my ($name , $input , $cmd , $options , $output ) = @_ ;
26
36
my $cmdline = " $cmd $options '$input ' >'$output ' 2>&1" ;
@@ -290,6 +300,10 @@ ($$$$)
290
300
independent logs.
291
301
-f forward the test name to CMD
292
302
303
+ --[no]color enable/disable color output; enabled by default unless
304
+ TESTPL_COLOR_OUTPUT is set to 0, in which case it is
305
+ disabled by default.
306
+
293
307
test.pl expects a test.desc file in each subdirectory. The file test.desc
294
308
follows the format specified below. Any line starting with // will be ignored.
295
309
@@ -324,9 +338,17 @@ ($$$$)
324
338
use Getopt::Long qw( :config pass_through bundling) ;
325
339
$main::VERSION = 0.1;
326
340
$Getopt::Std::STANDARD_HELP_VERSION = 1;
327
- our ($opt_c , $opt_e , $opt_f , $opt_i , $opt_j , $opt_n , $opt_p , $opt_h , $opt_C , $opt_T , $opt_F , $opt_K , $opt_s , %defines , @include_tags , @exclude_tags ); # the variables for getopt
328
- GetOptions(" D=s" => \%defines , " X=s" => \@exclude_tags , " I=s" => \@include_tags );
329
- getopts(' c:efi:j:nphCTFKs:' ) or &main::HELP_MESSAGE(\*STDOUT , " " , $main::VERSION , " " );
341
+ our ($opt_c , $opt_e , $opt_f , $opt_i , $opt_j , $opt_n , $opt_p , $opt_h , $opt_C , $opt_T , $opt_F , $opt_K , $opt_s , $opt_S , %defines , @include_tags , @exclude_tags ); # the variables for getopt
342
+
343
+ # this needs to come before GetOptions to ensure the
344
+ # default -> environment -> flag override priority
345
+ $color_output_enabled = 1;
346
+ if (exists $ENV {' TESTPL_COLOR_OUTPUT' }) {
347
+ $color_output_enabled = $ENV {' TESTPL_COLOR_OUTPUT' };
348
+ }
349
+
350
+ GetOptions(" D=s" => \%defines , " X=s" => \@exclude_tags , " I=s" => \@include_tags , ' color!' => \$color_output_enabled );
351
+ getopts(' c:efi:j:nphCTFKs:S:' ) or &main::HELP_MESSAGE(\*STDOUT , " " , $main::VERSION , " " );
330
352
$opt_c or &main::HELP_MESSAGE(\*STDOUT , " " , $main::VERSION , " " );
331
353
$opt_j = $opt_j || $ENV {' TESTPL_JOBS' } || 0;
332
354
if ($opt_j && $opt_j != 1 && !$has_thread_pool ) {
@@ -340,6 +362,7 @@ ($$$$)
340
362
$t_level += 4 if ($opt_F );
341
363
$t_level += 8 if ($opt_K );
342
364
$t_level += 1 if ($opt_C || 0 == $t_level );
365
+
343
366
my $dry_run = $opt_n ;
344
367
my $log_suffix = $opt_s ;
345
368
my $exit_signal_checks = defined ($opt_e );
@@ -386,10 +409,10 @@ ($)
386
409
$skips ++;
387
410
print " [SKIPPED]\n " ;
388
411
} elsif (0 == $failed_skipped ) {
389
- print " [" . colored (" OK" , " green" ) . " ] in $runtime seconds\n " ;
412
+ print " [" . with_color (" OK" , " green" ) . " ] in $runtime seconds\n " ;
390
413
} else {
391
414
$failures ++;
392
- print " [" . colored (" FAILED" , " red" ) . " ]\n " ;
415
+ print " [" . with_color (" FAILED" , " red" ) . " ]\n " ;
393
416
}
394
417
}
395
418
}
427
450
print " \n " ;
428
451
429
452
if ($failures == 0) {
430
- print colored (" All tests were successful" , " green" );
453
+ print with_color (" All tests were successful" , " green" );
431
454
} else {
432
- print colored (" Tests failed" , " red" ) . " \n " ;
455
+ print with_color (" Tests failed" , " red" ) . " \n " ;
433
456
print " $failures of $count " . (1==$count ?" test" :" tests" ) . " failed" ;
434
457
}
435
458
print " , $skips " . (1==$skips ?" test" :" tests" ) . " skipped" if ($skips > 0);
0 commit comments