]> git.cworth.org Git - apitrace-tests/blobdiff - cli_driver.py
Merge branch 'trim-auto'
[apitrace-tests] / cli_driver.py
index a7f4b3d5212a67821e636715140c8bc5e5d0c5f9..6c1bfd05ae28424e4a2ed8269e8b395b292ce894 100644 (file)
 
 '''Test driver for scripts in the cli directory.'''
 
-import json, errno, shutil, subprocess
+import json
+import errno
+import shutil
+import subprocess
+import difflib
 
 from base_driver import *
 
 class CliDriver(Driver):
 
     def do_apitrace(self, args):
-        cmd = [self.options.apitrace] + args[1:]
+        cmd = [self.options.apitrace] + args.split()
  
+        print " ".join(cmd)
         proc = subprocess.Popen(cmd, stdout = subprocess.PIPE)
         self.output = proc.communicate()[0]
 
@@ -46,14 +51,19 @@ class CliDriver(Driver):
                 fail("Command failed (returned non-zero):\n    " + " ".join(cmd))
 
     def do_expect(self, args):
-        expected = json.loads(" ".join(args[1:]))
+        expected = eval(args)
         if (self.output != expected):
-            fail("Unexpected output:\n    Expected: %s\n    Received: %s\n" % (expected, self.output))
+            differ = difflib.Differ()
+            diff = differ.compare(expected.splitlines(1), self.output.splitlines(1))
+            diff = ''.join(diff)
+            fail("Unexpected output:\n%s\n" % diff)
 
     def do_rm_and_mkdir(self, args):
 
+        args = args.split()
+
         # Operate only on local directories
-        dir = './' + args[1]
+        dir = './' + args[0]
 
         # Failing to delete a directory that doesn't exist is no failure
         def rmtree_onerror(function, path, excinfo):
@@ -64,7 +74,7 @@ class CliDriver(Driver):
         os.makedirs(dir)
 
     def unknown_command(self, args):
-        fail('Broken test script: Unknown command: %s' % (args[0]))
+        fail('Broken test script: Unknown command: %s' % (args))
 
     def run_script(self, cli_script):
         "Execute the commands in the given cli script."
@@ -83,19 +93,36 @@ class CliDriver(Driver):
 
             line = script.readline()
 
+            # Exit loop on EOF
             if (line == ''):
                 break
 
-            cmd = line.split()
-
-            if (len(cmd) == 0):
+            line = line.rstrip()
+
+            if " " in line:
+                (cmd, args) = line.split(None,1)
+                if args.startswith('r"""'):
+                    while not line.endswith('"""'):
+                        line = script.readline()
+                        line = line.rstrip()
+                        args += '\n' + line
+            else:
+                cmd = line
+                args = ''
+
+            # Ignore blank lines and comments
+            if (len(cmd) == 0 or cmd == '\n' or cmd[0] == '#'):
                 continue
 
-            if (cmd[0] == 'EXPECT_FAILURE:'):
+            if (cmd == 'EXPECT_FAILURE:'):
                 self.expect_failure = True
-                cmd.pop(0)
+                if " " in args:
+                    (cmd, args) = args.split(None, 1)
+                else:
+                    cmd = args
+                    args = ''
 
-            commands.get(cmd[0], self.unknown_command)(cmd)
+            commands.get(cmd, self.unknown_command)(args)
 
     def run(self):
         self.parseOptions()