X-Git-Url: https://git.cworth.org/git?p=apitrace-tests;a=blobdiff_plain;f=cli_driver.py;h=5139b1de27c6c7bdbc22e5449375fb7f711c4031;hp=6906b738e11c271629951b715a546d169ef23179;hb=6497cf7ca42b69e3172c07a5151e1cbf475e8c17;hpb=283dea13d9305a10cc309eb7b524b514012f4be7 diff --git a/cli_driver.py b/cli_driver.py index 6906b73..5139b1d 100644 --- a/cli_driver.py +++ b/cli_driver.py @@ -31,19 +31,32 @@ from base_driver import * class CliDriver(Driver): def do_apitrace(self, args): - cmd = [self.options.apitrace] + args[1:] + cmd = [self.options.apitrace] + args.split() - 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:])) + 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): + 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): @@ -54,7 +67,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." @@ -68,17 +81,36 @@ 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() + line = line.rstrip() + + if " " in line: + (cmd, args) = line.split(None,1) + else: + cmd = line + args = '' - if (len(cmd) == 0): + # Ignore blank lines and comments + if (len(cmd) == 0 or cmd == '\n' or cmd[0] == '#'): continue - commands.get(cmd[0], self.unknown_command)(cmd) + if (cmd == 'EXPECT_FAILURE:'): + self.expect_failure = True + if " " in args: + (cmd, args) = args.split(None, 1) + else: + cmd = args + args = '' + + commands.get(cmd, self.unknown_command)(args) def run(self): self.parseOptions()