2 # vim:ts=4:sw=4:expandtab
12 use TAP::Parser::Aggregator;
13 use File::Basename qw(basename);
14 use AnyEvent::I3 qw(:all);
18 # reads in a whole file
20 open my $fh, '<', shift;
25 my $coverage_testing = 0;
27 my $result = GetOptions(
28 "coverage-testing" => \$coverage_testing
31 my $i3cmd = "export DISPLAY=:0; exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c i3-test.config";
33 # 1: get a list of all testcases
34 my @testfiles = @ARGV;
36 # if no files were passed on command line, run all tests from t/
37 @testfiles = <t/*.t> if @testfiles == 0;
39 # 2: create an output directory for this test-run
40 my $outdir = "testsuite-";
41 $outdir .= DateTime->now->strftime("%Y-%m-%d-%H-%M-%S-");
42 $outdir .= `git describe --tags`;
44 mkdir($outdir) or die "Could not create $outdir";
45 unlink("latest") if -e "latest";
46 symlink("$outdir", "latest") or die "Could not symlink latest to $outdir";
49 my $harness = TAP::Harness->new({
53 my $aggregator = TAP::Parser::Aggregator->new();
55 for my $t (@testfiles) {
56 my $logpath = "$outdir/i3-log-for-" . basename($t);
57 my $cmd = "$i3cmd >$logpath 2>&1";
58 my $dont_start = (slurp($t) =~ /# !NO_I3_INSTANCE!/);
60 my $process = Proc::Background->new($cmd) unless $dont_start;
61 say "testing $t with logfile $logpath";
62 $harness->aggregate_tests($aggregator, [ $t ]);
64 # Don’t bother killing i3 when we haven’t started it
67 # When measuring code coverage, try to exit i3 cleanly (otherwise, .gcda
68 # files are not written) and fallback to killing it
69 if ($coverage_testing) {
72 say "Exiting i3 cleanly...";
73 i3("/tmp/nestedcons")->command('exit')->recv;
80 kill(9, $process->pid) or die "could not kill i3";
85 $harness->summary($aggregator);