filters to trim/highlight test output
authorJason Etheridge <jason@esilibrary.com>
Wed, 7 Aug 2013 20:47:43 +0000 (16:47 -0400)
committerJason Etheridge <jason@esilibrary.com>
Wed, 7 Aug 2013 20:47:43 +0000 (16:47 -0400)
So you can take the output from something like this:

    ssh esi@192.168.2.112 /home/esi/installer_installer.sh 2>&1 | tee output.txt

and then produce HTML with something like this:

    ./test_output_filter_html.pl > ~/public_html/test.html

qa/test_output_filter.pl [new file with mode: 0755]
qa/test_output_filter_html.pl [new symlink]

diff --git a/qa/test_output_filter.pl b/qa/test_output_filter.pl
new file mode 100755 (executable)
index 0000000..5c4a1c0
--- /dev/null
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+
+my $state = 'skipping';
+
+if ($0 =~ /html/) {
+    print "<html><head><title>test output</title>";
+    print "<link rel='stylesheet' type='text/css' href='test_output.css'>";
+    print "</head><body><pre>\n";
+}
+
+while (my $line = <>) {
+    if ($line =~ /_\.-~=/) {
+        $state = 'outputting';
+    }
+    if ($state eq 'outputting') {
+        if ($0 =~ /html/) {
+            my $class = '';
+            if ($line =~ /^ok/
+                || $line =~ /\. ok/
+                || $line =~ /^PASS/
+            ) {
+                $class .= 'ok ';
+            }
+            $class .= 'error ' if ($line =~ /^err/i); 
+            if ($line =~ /^not ok/
+                || $line =~ /\. not ok/
+            ) {
+                $class .= 'notok ';
+            }
+            $class .= 'result ' if ($line =~ /^Result:/); 
+            $class .= 'pass ' if ($line =~ /^Result: PASS/); 
+            $class .= 'fail ' if ($line =~ /^Result: FAIL/); 
+            if ($line =~ /^#/
+                || $line =~ /Checks:/
+                || $line =~ /_\.-~=/
+                || $line =~ /=~-\._/
+                || $line =~ / tests /
+                || $line =~ /Failed /
+                || $line =~ /Passed /
+                || $line =~ /Files:/
+            ) {
+                $class .= 'comment ';
+            }
+            chomp $line;
+            print "<span class='$class'>$line</span>\n";
+        } else {
+            print $line;
+        }
+    }
+    if ($line =~ /=~-\._/) {
+        $state = 'skipping';
+    }
+}
+
+if ($0 =~ /html/) {
+    print "</pre></body></html>\n";
+}
diff --git a/qa/test_output_filter_html.pl b/qa/test_output_filter_html.pl
new file mode 120000 (symlink)
index 0000000..a7c1b3f
--- /dev/null
@@ -0,0 +1 @@
+test_output_filter.pl
\ No newline at end of file