File: run.pl

package info (click to toggle)
gcli 2.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,596 kB
  • sloc: ansic: 26,273; sh: 601; makefile: 538; perl: 374; yacc: 261; lex: 59
file content (116 lines) | stat: -rwxr-xr-x 2,814 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env perl
#
# This is the main test harness for the gcli test suite.
# Its job is to look for tests and run them.
# Afterwards it should summarise the results.
#
# This file is part of gcli.
#
# Copyright Nico Sonack <nsonack@herrhotzenplotz.de>

use warnings;
use strict;

# Minimum required perl version
use 5.006002;

use Cwd qw(getcwd realpath);
use File::Basename;
use Getopt::Long;
use TAP::Harness;

BEGIN { push(@INC, dirname(realpath($0))); }
use testparser;

#####################
# Environment setup
my $testsrcdir = dirname(realpath($0));
my $builddir = getcwd();
my $verbosity = 0;
my $jobs = 1;

# Clean environment variables that could mess with the
# test suite results.
$ENV{'TZ'} = "UTC";
$ENV{'LC_ALL'} = "C.UTF-8";
delete $ENV{'GCLI_ACCOUNT'};

#########################
# Command line Options
sub usage {
	print STDERR "usage: $0 [-j <njobs>] [-s <srcdir>] [-b <builddir>] [-v] [filter]\n";
	print STDERR "OPTIONS:\n";
	print STDERR "   -j --jobs      Run tests in parallel with the given number of jobs\n";
	print STDERR "   -s --srcdir    Assume the test source tree is at the given directory\n";
	print STDERR "   -b --builddir  Assume the build output directory is at the given directory\n";
	print STDERR "   -v --verbose   Be verbose\n";
	print STDERR "\n";
	print STDERR "When a filter is given, only integration tests are run.\n";
	print STDERR "A filter is either a keyword or a test ID.\n";
}

GetOptions(
	"srcdir=s" => \$testsrcdir,
	"builddir=s" => \$builddir,
	"verbose" => \$verbosity,
	"jobs=i" => \$jobs,
	"help" => sub { usage; exit 0; },
) or die "failed to parse command line arguments";

chdir $builddir;

##########################
# Look for unit tests
my @alltests = ();

while (glob("${testsrcdir}/unit/*.c")) {
	my $name = fileparse($_, ".c");

	push(@alltests, [ "tests/unit/$name", "U: $name" ]) if ($#ARGV != 0);
}

for (glob "${testsrcdir}/integration/*.t") {
	# Push the integration tests, the second argument here is the title
	my %data = testparser::parsetest $_;
	my @kws = split / /, $data{Keywords};

	my @tdescr = ["$_", "I: #${data{ID}}: ${data{Title}}"];

	if (scalar(@ARGV) != 0) {
		foreach my $arg (@ARGV) {
			# test id
			if ($data{ID} eq $arg) {
				push(@alltests, @tdescr);
				last;
			}

			# test keywords
			if (scalar(grep($arg eq $_, @kws)) != 0) {
				push(@alltests, @tdescr);
				last;
			}
		}
	} else {
		push(@alltests, @tdescr);
	}
}

my $harness = TAP::Harness->new({
	verbosity => $verbosity,
	failures => 1,
	timer => 1,
	show_count => 1,
	errors => 1,
	jobs => $jobs,
	exec => sub {
		my ($harness, $test_file) = @_;

		return [ "${testsrcdir}/integrationwrap.pl", $test_file ] if $test_file =~ /\.t$/;
		return undef;
	},
});

my $agg = $harness->runtests(@alltests);
exit 1 if $agg->has_errors;

# kak: filetype=perl