]> git.sur5r.net Git - i3/i3status/blob - travis/run-tests.pl.in
Added function to print content from file (#331)
[i3/i3status] / travis / run-tests.pl.in
1 #!/usr/bin/env perl
2
3 use v5.10;
4 use strict;
5 use warnings;
6 use English;
7 use Term::ANSIColor qw(:constants);
8 use File::Basename;
9
10 sub TestCase {
11     my ($dir) = @_;
12
13     if ( -f "@_/setup.pl") {
14         system($EXECUTABLE_NAME, "@_/setup.pl", ($dir));
15     }
16
17     my $conf = "$dir/i3status.conf";
18     my $testres = `cd @abs_top_srcdir@ && LC_ALL=C @abs_top_builddir@/i3status --run-once -c $conf`;
19     my $exitcode = $?;
20     my $refres = "";
21
22     if ( -f "@_/expected_output.txt") {
23         $refres = `cat "@_/expected_output.txt"`;
24     } elsif ( -f "@_/expected_output.pl") {
25         $refres = `$EXECUTABLE_NAME @_/expected_output.pl`;
26     }
27
28     if ( -f "@_/cleanup.pl") {
29         system($EXECUTABLE_NAME, "@_/cleanup.pl", ($dir));
30     }
31
32     if ( $exitcode != 0 ) {
33         say "Testing test case '", basename($dir), "'… ", BOLD, RED, "Crash!", RESET;
34         return 0;
35     }
36
37     if ( "$testres" eq "$refres" ) {
38         say "Testing test case '", basename($dir), "'… ", BOLD, GREEN, "OK", RESET;
39         return 1;
40     } else {
41         say "Testing test case '", basename($dir), "'… ", BOLD, RED, "Failed!", RESET;
42         say "Expected: '$refres'";
43         say "Got: '$testres'";
44         return 0;
45     }
46 }
47
48 my $testcases = '@abs_top_srcdir@/testcases';
49 my $testresults = 0;
50
51 opendir(my $dir, $testcases) or die "Could not open directory $testcases: $!";
52
53 while (my $entry = readdir($dir)) {
54     next unless (-d "$testcases/$entry");
55     next if ($entry =~ m/^\./);
56     if (not TestCase("$testcases/$entry") ) {
57         $testresults = 1;
58     }
59 }
60 closedir($dir);
61 exit $testresults;