Skip to content

Commit 92ecd77

Browse files
authored
Merge pull request #4647 from hannes-steffenhagen-diffblue/feature-suppress_color_output_on_aws
Suppress color output on aws
2 parents 9fd7dd4 + ad0bd0c commit 92ecd77

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

buildspec-linux-clang.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
version: 0.2
22

3+
env:
4+
variables:
5+
# CodeBuild console doesn't display color codes correctly
6+
TESTPL_COLOR_OUTPUT: 0
7+
38
phases:
49
install:
510
runtime-versions:

buildspec-linux-cmake-gcc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
version: 0.2
22

3+
env:
4+
variables:
5+
# CodeBuild console doesn't display color codes correctly
6+
TESTPL_COLOR_OUTPUT: 0
7+
38
phases:
49
install:
510
runtime-versions:

buildspec-windows.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
version: 0.2
22

3+
env:
4+
variables:
5+
# CodeBuild console doesn't display color codes correctly
6+
TESTPL_COLOR_OUTPUT: 0
7+
38
phases:
49
install:
510
commands:

buildspec.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
version: 0.2
22

3+
env:
4+
variables:
5+
# CodeBuild console doesn't display color codes correctly
6+
TESTPL_COLOR_OUTPUT: 0
7+
38
phases:
49
install:
510
runtime-versions:

regression/test.pl

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
#
2222
# runs a test and check its output
2323

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+
2434
sub run($$$$$) {
2535
my ($name, $input, $cmd, $options, $output) = @_;
2636
my $cmdline = "$cmd $options '$input' >'$output' 2>&1";
@@ -290,6 +300,10 @@ ($$$$)
290300
independent logs.
291301
-f forward the test name to CMD
292302
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+
293307
test.pl expects a test.desc file in each subdirectory. The file test.desc
294308
follows the format specified below. Any line starting with // will be ignored.
295309
@@ -324,9 +338,17 @@ ($$$$)
324338
use Getopt::Long qw(:config pass_through bundling);
325339
$main::VERSION = 0.1;
326340
$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, "");
330352
$opt_c or &main::HELP_MESSAGE(\*STDOUT, "", $main::VERSION, "");
331353
$opt_j = $opt_j || $ENV{'TESTPL_JOBS'} || 0;
332354
if($opt_j && $opt_j != 1 && !$has_thread_pool) {
@@ -340,6 +362,7 @@ ($$$$)
340362
$t_level += 4 if($opt_F);
341363
$t_level += 8 if($opt_K);
342364
$t_level += 1 if($opt_C || 0 == $t_level);
365+
343366
my $dry_run = $opt_n;
344367
my $log_suffix = $opt_s;
345368
my $exit_signal_checks = defined($opt_e);
@@ -386,10 +409,10 @@ ($)
386409
$skips++;
387410
print " [SKIPPED]\n";
388411
} elsif(0 == $failed_skipped) {
389-
print " [" . colored("OK", "green") . "] in $runtime seconds\n";
412+
print " [" . with_color("OK", "green") . "] in $runtime seconds\n";
390413
} else {
391414
$failures++;
392-
print " [" . colored("FAILED", "red") . "]\n";
415+
print " [" . with_color("FAILED", "red") . "]\n";
393416
}
394417
}
395418
}
@@ -427,9 +450,9 @@ ($)
427450
print "\n";
428451

429452
if($failures == 0) {
430-
print colored("All tests were successful", "green");
453+
print with_color("All tests were successful", "green");
431454
} else {
432-
print colored("Tests failed", "red") . "\n";
455+
print with_color("Tests failed", "red") . "\n";
433456
print " $failures of $count " . (1==$count?"test":"tests") . " failed";
434457
}
435458
print ", $skips " . (1==$skips?"test":"tests") . " skipped" if($skips > 0);

0 commit comments

Comments
 (0)