summaryrefslogtreecommitdiff
path: root/travis
diff options
context:
space:
mode:
authoreplanet <emeric.planet@gmail.com>2016-11-14 09:13:44 +0100
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2016-11-14 00:13:44 -0800
commitb0af4e4c8543d8cdfd8bc7cd68b760d9d66e927c (patch)
treee9586c0909c71a33208b8d22661577a0e705d83a /travis
parent220b9e156527463512862f59b2413702d3ef6a3f (diff)
Unit testing in Travis (#170)
Diffstat (limited to 'travis')
-rwxr-xr-xtravis/run-tests.pl42
1 files changed, 42 insertions, 0 deletions
diff --git a/travis/run-tests.pl b/travis/run-tests.pl
new file mode 100755
index 0000000..453a633
--- /dev/null
+++ b/travis/run-tests.pl
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+
+use v5.10;
+use strict;
+use warnings;
+use Term::ANSIColor qw(:constants);
+use File::Basename;
+
+sub TestCase {
+ my ($dir) = @_;
+ my $conf = "$dir/i3status.conf";
+ my $testres = `./i3status --run-once -c $conf`;
+ my $refres = "";
+
+ if ( -f "@_/expected_output.txt") {
+ $refres = `cat "@_/expected_output.txt"`;
+ } elsif ( -f "@_/expected_output.sh") {
+ $refres = `bash @_/expected_output.sh`;
+ }
+
+ if ( "$testres" eq "$refres" ) {
+ say "Testing test case '", basename($dir), "'… ", BOLD, GREEN, "OK", RESET;
+ return 1;
+ } else {
+ say "Testing test case '", basename($dir), "'… ", BOLD, RED, "Failed!", RESET;
+ return 0;
+ }
+}
+
+
+my $testcases = 'testcases';
+my $testresults = 1;
+
+opendir(my $dir, $testcases) or die "Could not open directory $testcases: $!";
+
+while (my $entry = readdir($dir)) {
+ next unless (-d "$testcases/$entry");
+ next if ($entry =~ m/^\./);
+ $testresults = $testresults && TestCase("$testcases/$entry");
+}
+closedir($dir);
+exit 0;