Support multiple greps and antigreps per test. trunk

Sun, 12 Apr 2009 11:22:42 -0400

author
Brett Smith <brettcsmith@brettcsmith.org>
date
Sun, 12 Apr 2009 11:22:42 -0400
branch
trunk
changeset 107
1b7450ae4c67
parent 106
dcf005ef7070
child 108
b8316c2b36df

Support multiple greps and antigreps per test.

I thought I would need this for a new test I was writing. It turned out I
ended up implementing different tests (and features), but this could come
in handy for later so I'm keeping it.

tests/compare.py file | annotate | diff | comparison | revisions
--- a/tests/compare.py	Sun Apr 12 11:21:51 2009 -0400
+++ b/tests/compare.py	Sun Apr 12 11:22:42 2009 -0400
@@ -54,8 +54,13 @@
         setattr(self, 'options', kwargs.get('options', '-n').split())
         setattr(self, 'filenames', kwargs.get('filenames', '').split())
         for key in ('directory', 'prerun', 'posttest', 'baseline', 'error',
-                    'grep', 'antigrep', 'input', 'output', 'cleanup'):
+                    'input', 'output', 'cleanup'):
             setattr(self, key, kwargs.get(key, None))
+        for key in ('grep', 'antigrep'):
+            value = kwargs.get(key, [])
+            if isinstance(value, str):
+                value = [value]
+            setattr(self, key, value)
         
     def get_results(self, commands, stdin=None):
         print >>output_buffer, "Output from %s:" % (' '.join(commands),)
@@ -165,12 +170,13 @@
         return None
 
     def grep_output(self, output):
-        if self.grep and (not re.search(self.grep.replace(' ', '\\s+'),
-                                        output, re.MULTILINE)):
-            return "output did not match %s" % (self.grep)
-        elif self.antigrep and re.search(self.antigrep.replace(' ', '\\s+'),
-                                         output, re.MULTILINE):
-            return "output matched antigrep %s" % (self.antigrep)
+        for pattern in self.grep:
+            if not re.search(pattern.replace(' ', '\\s+'), output,
+                             re.MULTILINE):
+                return "output did not match %s" % (pattern)
+        for pattern in self.antigrep:
+            if re.search(pattern.replace(' ', '\\s+'), output, re.MULTILINE):
+                return "output matched antigrep %s" % (self.antigrep)
         return None
 
     def check_output(self, output):

mercurial