]> git.cworth.org Git - apitrace-tests/blobdiff - cli_driver.py
Print commands to be executed by cli_driver.py
[apitrace-tests] / cli_driver.py
index 6906b738e11c271629951b715a546d169ef23179..d4d277d33e822f7e8f4ff9dc75f25c92eec335e4 100644 (file)
@@ -33,7 +33,18 @@ class CliDriver(Driver):
     def do_apitrace(self, args):
         cmd = [self.options.apitrace] + args[1:]
  
-        self.output = subprocess.check_output(cmd)
+        print " ".join(cmd)
+        proc = subprocess.Popen(cmd, stdout = subprocess.PIPE)
+        self.output = proc.communicate()[0]
+
+        proc.wait()
+
+        if (self.expect_failure):
+            if (proc.returncode == 0):
+                fail("Command unexpectedly passed when expecting failure:\n    " + " ".join(cmd))
+        else:
+            if (proc.returncode != 0):
+                fail("Command failed (returned non-zero):\n    " + " ".join(cmd))
 
     def do_expect(self, args):
         expected = json.loads(" ".join(args[1:]))
@@ -68,16 +79,25 @@ class CliDriver(Driver):
         script = open(cli_script, 'rt')
 
         while True:
+
+            self.expect_failure = False
+
             line = script.readline()
 
+            # Exit loop on EOF
             if (line == ''):
                 break
 
             cmd = line.split()
 
-            if (len(cmd) == 0):
+            # Ignore blank lines and comments
+            if (len(cmd) == 0 or line[0] == '#'):
                 continue
 
+            if (cmd[0] == 'EXPECT_FAILURE:'):
+                self.expect_failure = True
+                cmd.pop(0)
+
             commands.get(cmd[0], self.unknown_command)(cmd)
 
     def run(self):