aboutsummaryrefslogtreecommitdiffstats
path: root/run-qtest
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-03-05 14:23:05 +0100
committerJay Berkenbilt <jberkenbilt@users.noreply.github.com>2022-03-19 00:53:18 +0100
commit248b31fdb97cc7f238306e04b807a5d97b695b10 (patch)
treef3e98dfcd14fa571e573bb145de0e05817328d7a /run-qtest
parent3eaeeaf8f38d9d69660511f492f532f169b74385 (diff)
downloadqpdf-248b31fdb97cc7f238306e04b807a5d97b695b10.tar.zst
Add wrapper around qtest-driver for cmake
Handle various options that were handled in Makefile code.
Diffstat (limited to 'run-qtest')
-rwxr-xr-xrun-qtest132
1 files changed, 132 insertions, 0 deletions
diff --git a/run-qtest b/run-qtest
new file mode 100755
index 00000000..73b0f485
--- /dev/null
+++ b/run-qtest
@@ -0,0 +1,132 @@
+#!/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 @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, 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 '--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.
+ push(@tc, shift(@ARGV));
+ }
+ }
+ 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))
+{
+ 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\" ...]
+";
+}