]> git.cworth.org Git - apitrace-tests/commitdiff
cli_driver: Rework driver script to preserve json-embedded whitespace
authorCarl Worth <cworth@cworth.org>
Tue, 14 Aug 2012 23:50:00 +0000 (16:50 -0700)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 1 Dec 2012 10:15:49 +0000 (10:15 +0000)
Previously, the line read from the script was being passed through
python's string.split() and string.join() functions. This was causing
sequences of successive whitespace characters to be collapsed down to
a single space, (in turn causing spurious failures when comparing
against expected output with successive whitespace).

Rework the driver to avoid munging the line past the separation of the
first command word.

cli/.gitignore
cli/glxsimple.trace [new file with mode: 0644]
cli_driver.py

index 64d0e40eec460417b053620f39ff418d713f759d..214d7f2c2cf6159fe718bdf13fd4152b11c5b6d4 100644 (file)
@@ -2,4 +2,6 @@
 tri-trim.trace
 tri-out
 glxsimple-ref
 tri-trim.trace
 tri-out
 glxsimple-ref
+glxsimple-out
+glxsimple-trim.trace
 
 
diff --git a/cli/glxsimple.trace b/cli/glxsimple.trace
new file mode 100644 (file)
index 0000000..9c22592
Binary files /dev/null and b/cli/glxsimple.trace differ
index d4d277d33e822f7e8f4ff9dc75f25c92eec335e4..5139b1de27c6c7bdbc22e5449375fb7f711c4031 100644 (file)
@@ -31,7 +31,7 @@ from base_driver import *
 class CliDriver(Driver):
 
     def do_apitrace(self, args):
 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)
  
         print " ".join(cmd)
         proc = subprocess.Popen(cmd, stdout = subprocess.PIPE)
@@ -47,14 +47,16 @@ class CliDriver(Driver):
                 fail("Command failed (returned non-zero):\n    " + " ".join(cmd))
 
     def do_expect(self, args):
                 fail("Command failed (returned non-zero):\n    " + " ".join(cmd))
 
     def do_expect(self, args):
-        expected = json.loads(" ".join(args[1:]))
+        expected = json.loads(args)
         if (self.output != expected):
             fail("Unexpected output:\n    Expected: %s\n    Received: %s\n" % (expected, self.output))
 
     def do_rm_and_mkdir(self, args):
 
         if (self.output != expected):
             fail("Unexpected output:\n    Expected: %s\n    Received: %s\n" % (expected, self.output))
 
     def do_rm_and_mkdir(self, args):
 
+        args = args.split()
+
         # Operate only on local directories
         # 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):
 
         # Failing to delete a directory that doesn't exist is no failure
         def rmtree_onerror(function, path, excinfo):
@@ -65,7 +67,7 @@ class CliDriver(Driver):
         os.makedirs(dir)
 
     def unknown_command(self, args):
         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."
 
     def run_script(self, cli_script):
         "Execute the commands in the given cli script."
@@ -88,17 +90,27 @@ class CliDriver(Driver):
             if (line == ''):
                 break
 
             if (line == ''):
                 break
 
-            cmd = line.split()
+            line = line.rstrip()
+
+            if " " in line:
+                (cmd, args) = line.split(None,1)
+            else:
+                cmd = line
+                args = ''
 
             # Ignore blank lines and comments
 
             # Ignore blank lines and comments
-            if (len(cmd) == 0 or line[0] == '#'):
+            if (len(cmd) == 0 or cmd == '\n' or cmd[0] == '#'):
                 continue
 
                 continue
 
-            if (cmd[0] == 'EXPECT_FAILURE:'):
+            if (cmd == 'EXPECT_FAILURE:'):
                 self.expect_failure = True
                 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()
 
     def run(self):
         self.parseOptions()