Commit 248b31fdb97cc7f238306e04b807a5d97b695b10

Authored by Jay Berkenbilt
Committed by Jay Berkenbilt
1 parent 3eaeeaf8

Add wrapper around qtest-driver for cmake

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