1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;
use Cwd 'abs_path';
use File::Basename;
use File::Spec;
my $whoami = basename($0);
my $top = undef;
my $code = undef;
my @bin = ();
my $color = undef;
my $show_on_failure = 0;
my $disable_tc = 0;
my @tc = ();
if ($^O =~ m/^MSWin32|msys$/)
{
for (@ARGV)
{
s,^([A-Z]):/,/\L$1\E/,;
}
}
while (@ARGV)
{
my $arg = shift(@ARGV);
if ($arg eq '--top')
{
usage() unless @ARGV;
$top = shift(@ARGV);
}
elsif ($arg eq '--code')
{
usage() unless @ARGV;
$code = shift(@ARGV);
}
elsif ($arg eq '--bin')
{
usage() unless @ARGV;
push(@bin, abs_path(shift(@ARGV)));
}
elsif ($arg eq '--color')
{
usage() unless @ARGV;
$color = cmake_bool(shift(@ARGV));
}
elsif ($arg eq '--show-on-failure')
{
usage() unless @ARGV;
$show_on_failure = cmake_bool(shift(@ARGV));
}
elsif ($arg eq '--disable-tc')
{
$disable_tc = 1;
}
elsif ($arg eq '--tc')
{
usage() unless @ARGV;
while (@ARGV && ($ARGV[0] !~ m/^--/))
{
# On Windows, a literal glob in quotes is expanded by the
# shell, so we have to handle globs when expanded by the
# shell by consuming arguments until the next --.
my $t = shift(@ARGV);
if (exists $ENV{'TESTS'})
{
# No point enabling coverage if we're intentionally
# running only a subset of tests.
next;
}
push(@tc, $t);
}
}
elsif ($arg eq '--env')
{
usage() unless @ARGV;
my $var = shift(@ARGV);
usage() unless $var =~ m/^([^=]+)=(.*)$/;
$ENV{$1} = $2;
}
else
{
usage();
}
}
usage() unless (defined $top && defined $code && scalar(@bin));
my @cmd = ("$top/qtest/bin/qtest-driver");
if (defined $color)
{
push(@cmd, "-stdout-tty=$color");
}
push(@cmd,
"-bindirs", join(':', @bin),
"-datadir", "$code/qtest",
"-junit-suffix", basename($code));
if (scalar(@tc) && (! $disable_tc))
{
my @tc_srcs = map {
File::Spec->abs2rel(abs_path($_))
} map {
# On non-Windows, a literal glob in quotes is not expanded by
# the shell, so we have to handle globs explicitly.
glob($_)
} @tc;
$ENV{'TC_SRCS'} = join(' ', @tc_srcs);
push(@cmd, "-covdir", $code);
}
my $r = system(@cmd);
if (($r != 0) && $show_on_failure && open(R, "<qtest.log"))
{
binmode R;
while (<R>)
{
print;
}
close(R);
}
exit($r == 0 ? 0 : 2);
sub cmake_bool
{
my $arg = shift;
($arg =~ m/^(1|on|true|y(es)?)$/i) ? 1 : 0;
}
sub usage
{
die "
Usage: $whoami options
--top source-tree
--code code-subdir
--bin bindir ...
[--color [01]]
[--show-on-failure [01]]
[--tc \"../a/*.cc\" ...]
";
}
|