From 0cd24554b0cbcc64e9866addde75028c3f9e87d3 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Wed, 7 Aug 2013 16:47:43 -0400 Subject: [PATCH] filters to trim/highlight test output 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 | 57 +++++++++++++++++++++++++++++++++++++++++++ qa/test_output_filter_html.pl | 1 + 2 files changed, 58 insertions(+) create mode 100755 qa/test_output_filter.pl create mode 120000 qa/test_output_filter_html.pl diff --git a/qa/test_output_filter.pl b/qa/test_output_filter.pl new file mode 100755 index 000000000..5c4a1c003 --- /dev/null +++ b/qa/test_output_filter.pl @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +my $state = 'skipping'; + +if ($0 =~ /html/) { + print "test output"; + print ""; + print "
\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 "$line\n";
+        } else {
+            print $line;
+        }
+    }
+    if ($line =~ /=~-\._/) {
+        $state = 'skipping';
+    }
+}
+
+if ($0 =~ /html/) {
+    print "
\n"; +} diff --git a/qa/test_output_filter_html.pl b/qa/test_output_filter_html.pl new file mode 120000 index 000000000..a7c1b3fb5 --- /dev/null +++ b/qa/test_output_filter_html.pl @@ -0,0 +1 @@ +test_output_filter.pl \ No newline at end of file -- 2.11.0