]> rtime.felk.cvut.cz Git - wvtest.git/commitdiff
Put the definition of prefix to a variable
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 15 Aug 2012 14:49:37 +0000 (16:49 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 15 Aug 2012 15:25:21 +0000 (17:25 +0200)
Now, it should be easy to change it at one place.

tools/wvformat
tools/wvnulrun
tools/wvperf2html.py
tools/wvtest2html.py
tools/wvwrap

index 3db76c9eff0309c03c35378431731e10ba107a08..ac0d45f9da5a5641a8dbbeab73db60ced11a0fa3 100755 (executable)
@@ -78,8 +78,8 @@ sub print_and_clear_log()
     my @log2print = ();
     my $skipped = 0;
     foreach (@log) {
-       if (/^(\([0-9]+\) (#   )?)?!\s*(.*?)\s+(\S+)\s*$/) {
-           my ($prefix, $name, $result) = ($1, $3, $4);
+       if (/^($prefix_re)?!\s*(.*?)\s+(\S+)\s*$/) {
+           my ($prefix, $name, $result) = ($1, $2, $3);
            push @log2print, resultline($prefix, $name, $result);
            if ($result ne "ok") {
                print "wvformat: skipped $skipped lines\n" if $skipped;
@@ -120,7 +120,7 @@ while (<>)
     chomp;
     s/\r//g;
 
-    if (/^(\([0-9]+\) )?\s*Testing "(.*)" in (.*):\s*$/)
+    if (/^($prefix_re)?\s*Testing "(.*)" in (.*):\s*$/)
     {
        print_test_summary() unless $startup;
        $startup = 0;
@@ -130,9 +130,9 @@ while (<>)
            print highlight($_), "\n";
        }
     }
-    elsif (/^(\([0-9]+\) (#   )?)?!\s*(.*?)\s+(\S+)\s*$/)
+    elsif (/^($prefix_re)?!\s*(.*?)\s+(\S+)\s*$/)
     {
-       my ($prefix, $name, $result) = ($1, $3, $4);
+       my ($prefix, $name, $result) = ($1, $2, $3);
 
        if ($startup) {
            $file = "";
index 91a282367a027f47988e72f8a71c69a6e54b6962..9034c508e23de61bedba8113ffc72a9644376746 100755 (executable)
@@ -28,6 +28,9 @@
 use strict;
 use IO::Pty;
 
+# Optional prefix of wvtest protocol lines
+my $prefix_re = '\([0-9]+\) (?:#   )?';
+
 # always flush
 $| = 1;
 
@@ -95,13 +98,13 @@ local $SIG{ALRM} = sub {
 
 my $allstart = time();
 my ($start, $stop);
-my $tests_executed = 0;
-my $tests_failed = 0;
+my $assertions_executed = 0;
+my $assertions_failed = 0;
 my $waits_for_child = 0;
 my $kill_ok = 0;
 my $ignore_exit_patterns = 0;
-my $expected_test_count = 0;
-my $expected_test_base = 0;
+my $expected_assertion_count = 0;
+my $expected_assertion_base = 0;
 
 sub matches_exit_pattern($)
 {
@@ -118,19 +121,19 @@ sub matches_exit_pattern($)
     }
 }
 
-sub check_number_of_tests()
+sub check_number_of_assertions()
 {
-    if ($expected_test_count) {
-       my $executed = $tests_executed - $expected_test_base;
+    if ($expected_assertion_count) {
+       my $executed = $assertions_executed - $expected_assertion_base;
        my $result;
-       if ($executed == $expected_test_count) {
+       if ($executed == $expected_assertion_count) {
            $result = "ok";
        } else {
            $result = "FAILED";
-           $tests_failed++;
-           print "Expected $expected_test_count tests, executed $executed tests.\n"
+           $assertions_failed++;
+           print "Expected $expected_assertion_count tests, executed $executed tests.\n"
        }
-       print "! $0: tests_expected == tests_executed  $result\n";
+       print "! $0: tests_expected == assertions_executed  $result\n";
     }
 }
 
@@ -148,9 +151,9 @@ while (<$pty>)
     chomp;
     s/\r//g;
 
-    if (/^(\([0-9]+\) (#   )?)?!\s*(.*?)\s+(\S+)\s*$/) {
-       $tests_executed++;
-       $tests_failed++ if ($4 ne "ok");
+    if (/^($prefix_re?)?!\s*(.*?)\s+(\S+)\s*$/) {
+       $assertions_executed++;
+       $assertions_failed++ if ($3 ne "ok");
     }
     elsif (/wvtest: timeout (\d+)\s*$/) {
        $timeout=$1;
@@ -158,10 +161,10 @@ while (<$pty>)
     }
     elsif (/sc: wait for child/) { $waits_for_child = 1; }
     elsif (/wvtest: ignore exit patterns/) { $ignore_exit_patterns = 1; }
-    elsif (/wvtest: expect ([0-9]+) tests/) {
-       check_number_of_tests();
-       $expected_test_count = $1;
-       $expected_test_base = $tests_executed;
+    elsif (/wvtest: expect ([0-9]+) (tests|assertions)/) {
+       check_number_of_assertions();
+       $expected_assertion_count = $1;
+       $expected_assertion_base = $assertions_executed;
     }
     elsif (matches_exit_pattern($_))
     {
@@ -209,11 +212,11 @@ if ($ret != 0) {
 }
 
 if (!$ENV{WVTEST_EXIT_PATTERN}) {
-    printf "! $0: \$tests_executed > 0  %s\n", ($tests_executed > 0) ? "ok" : "FAILED";
+    printf "! $0: \$assertions_executed > 0  %s\n", ($assertions_executed > 0) ? "ok" : "FAILED";
 }
-check_number_of_tests();
+check_number_of_assertions();
 
-if ($tests_failed > 0) { $ret = 1; }
-if ($ret == 0 && $tests_executed == 0) { $ret = 1; }
+if ($assertions_failed > 0) { $ret = 1; }
+if ($ret == 0 && $assertions_executed == 0) { $ret = 1; }
 
 exit $ret;
index 26fb4330c4da46f1d289dc0ac0c3583af55d93e9..c3f37d0a19c41cd85ac12144fc624f60fd46f5a3 100755 (executable)
@@ -8,6 +8,15 @@ import string
 import time
 import numpy as np
 
+re_prefix = "\([0-9]+\) (?:#   )?"
+re_date = re.compile('^Date: (.*)')
+re_testing = re.compile('^('+re_prefix+')?\s*Testing "(.*)" in (.*):\s*$')
+re_commit = re.compile('.*(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*, commit: (.*)')
+re_commithash = re.compile('([0-9a-f]{7})(-dirty)? \(')
+re_assertion = re.compile('^('+re_prefix+')?!\s*(.*?)\s+(\S+)\s*$')
+re_perf =  re.compile('^('+re_prefix+')?!\s*(.*?)\s+PERF:\s*(.*?)\s+(\S+)\s*$')
+re_perfaxis = re.compile('axis="([^"]+)"')
+
 class Axis:
     def __init__(self, name=None, units=None):
         self.name = name
@@ -214,14 +223,6 @@ class Graphs(dict):
 graphs = Graphs()
 commits = {}
 
-re_date = re.compile('^Date: (.*)')
-re_testing = re.compile('^(\([0-9]+\) (#   )?)?\s*Testing "(.*)" in (.*):\s*$')
-re_commit = re.compile('.*(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*, commit: (.*)')
-re_commithash = re.compile('([0-9a-f]{7})(-dirty)? \(')
-re_check = re.compile('^(\([0-9]+\) (#   )?)?!\s*(.*?)\s+(\S+)\s*$')
-re_perf =  re.compile('^(\([0-9]+\) (#   )?)?!\s*(.*?)\s+PERF:\s*(.*?)\s+(\S+)\s*$')
-re_perfaxis = re.compile('axis="([^"]+)"')
-
 date = time.localtime(time.time())
 
 for line in sys.stdin.readlines():
@@ -234,8 +235,8 @@ for line in sys.stdin.readlines():
 
     match = re_testing.match(line)
     if match:
-        what = match.group(3)
-        where = match.group(4)
+        what = match.group(2)
+        where = match.group(3)
 
         match = re_commit.match(what)
         if match:
@@ -261,7 +262,7 @@ for line in sys.stdin.readlines():
 
     match = re_perf.match(line)
     if match:
-        perfstr = match.group(4)
+        perfstr = match.group(3)
         perf = perfstr.split()
         col = perf[0]
         try:
@@ -273,7 +274,7 @@ for line in sys.stdin.readlines():
             if '=' in units: units = None
         except:
             units = None
-        if match.group(5) != "ok":
+        if match.group(4) != "ok":
             val=None
 
         graph.addValue(date, col, val, units)
index ff0deba5bb3ca18d9e5a7e46325f081bda3f97ee..89cb8d91c06177d972cdf1054163de6c270a52bb 100755 (executable)
@@ -9,12 +9,13 @@ import time
 import numpy as np
 import cgi
 
+re_prefix = "\([0-9]+\) (?:#   )?"
 re_date = re.compile('^Date: (.*)')
-re_testing = re.compile('^(\([0-9]+\) (#   )?)?\s*Testing "(.*)" in (.*):\s*$')
+re_testing = re.compile('^('+re_prefix+')?\s*Testing "(.*)" in (.*):\s*$')
 re_commit = re.compile('.*(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*, commit: (.*)')
 re_commithash = re.compile('([0-9a-f]{7})(-dirty)? \(')
-re_check = re.compile('^(\([0-9]+\) (#   )?)?!\s*(.*?)\s+(\S+)\s*$')
-re_perf =  re.compile('^(\([0-9]+\) (#   )?)?!\s*(.*?)\s+PERF:\s*(.*?)\s+(\S+)\s*$')
+re_assertion = re.compile('^('+re_prefix+')?!\s*(.*?)\s+(\S+)\s*$')
+re_perf =  re.compile('^('+re_prefix+')?!\s*(.*?)\s+PERF:\s*(.*?)\s+(\S+)\s*$')
 re_perfaxis = re.compile('axis="([^"]+)"')
 
 date = time.localtime(time.time())
@@ -31,10 +32,10 @@ class Test:
 
     def add_line(self, line):
         self.output.append(line)
-        match = re_check.match(line)
+        match = re_assertion.match(line)
         if match:
             self.check_count += 1
-            result = match.group(4)
+            result = match.group(3)
             if result != "ok":
                 self.status = result
                 self.failures += 1
@@ -69,9 +70,9 @@ class Test:
 <table class='output'>
 """ % (date_and_commit, self.num, cgi.escape(self.title())))
         for line in self.output:
-            match = re_check.match(line)
+            match = re_assertion.match(line)
             if match:
-                result = match.group(4)
+                result = match.group(3)
                 if result == "ok":
                     status_class = "ok"
                 else:
@@ -100,8 +101,8 @@ for line in sys.stdin.readlines():
 
     match = re_testing.match(line)
     if match:
-        what = match.group(3)
-        where = match.group(4)
+        what = match.group(2)
+        where = match.group(3)
 
         test = Test(what, where)
         tests.append(test)
index 184b50393a356f24e8ea89375f35a2afb49401fc..8b304c7ad60b3aac6715e35762f77443479e9c14 100755 (executable)
@@ -38,7 +38,7 @@ while (<>)
     chomp;
     s/\r//g;
 
-    if (/^(\([0-9]+\) (#   )?)?!\s*(.*?)\s+(\S+)\s*$/) {
+    if (/^($prefix_re)?!\s*(.*?)\s+(\S+)\s*$/) {
        my $line = $_;
        do {
            print substr($line, 0, $columns) . "\n";