]> git.sur5r.net Git - i3/i3/blob - testcases/complete-run.pl
tests: add test for the for_window config directive, use separate config for tests
[i3/i3] / testcases / complete-run.pl
1 #!/usr/bin/env perl
2 # vim:ts=4:sw=4:expandtab
3
4 use strict;
5 use warnings;
6 use v5.10;
7 use DateTime;
8 use Data::Dumper;
9 use Cwd qw(abs_path);
10 use Proc::Background;
11 use TAP::Harness;
12 use TAP::Parser::Aggregator;
13 use File::Basename qw(basename);
14 use AnyEvent::I3 qw(:all);
15 use Try::Tiny;
16 use Getopt::Long;
17
18 # reads in a whole file
19 sub slurp {
20     open my $fh, '<', shift;
21     local $/;
22     <$fh>;
23 }
24
25 my $coverage_testing = 0;
26
27 my $result = GetOptions(
28     "coverage-testing" => \$coverage_testing
29 );
30
31 my $i3cmd = "export DISPLAY=:0; exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c i3-test.config";
32
33 # 1: get a list of all testcases
34 my @testfiles = @ARGV;
35
36 # if no files were passed on command line, run all tests from t/
37 @testfiles = <t/*.t> if @testfiles == 0;
38
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`;
43 chomp($outdir);
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";
47
48 # 3: run all tests
49 my $harness = TAP::Harness->new({
50     verbosity => 1,
51     lib => [ 't/lib' ]
52 });
53 my $aggregator = TAP::Parser::Aggregator->new();
54 $aggregator->start();
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!/);
59
60     my $process = Proc::Background->new($cmd) unless $dont_start;
61     say "testing $t with logfile $logpath";
62     $harness->aggregate_tests($aggregator, [ $t ]);
63
64     # Don’t bother killing i3 when we haven’t started it
65     next if $dont_start;
66
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) {
70         my $exited = 0;
71         try {
72             say "Exiting i3 cleanly...";
73             i3("/tmp/nestedcons")->command('exit')->recv;
74             $exited = 1;
75         };
76         next if $exited;
77     }
78
79     say "Killing i3";
80     kill(9, $process->pid) or die "could not kill i3";
81 }
82 $aggregator->stop();
83
84 # 4: print summary
85 $harness->summary($aggregator);