199451b44SJordan Rupprecht""" 21f933ff9SRaphael IsemannTest quoting of arguments to lldb commands. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprechtimport lldb 699451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 799451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 899451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 999451b44SJordan Rupprecht 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprechtclass SettingsCommandTestCase(TestBase): 121f933ff9SRaphael Isemann output_file_name = "output.txt" 1399451b44SJordan Rupprecht 1499451b44SJordan Rupprecht @classmethod 1599451b44SJordan Rupprecht def classCleanup(cls): 1699451b44SJordan Rupprecht """Cleanup the test byproducts.""" 171f933ff9SRaphael Isemann cls.RemoveTempFile(SettingsCommandTestCase.output_file_name) 1899451b44SJordan Rupprecht 191f933ff9SRaphael Isemann @no_debug_info_test 201f933ff9SRaphael Isemann def test(self): 211f933ff9SRaphael Isemann self.build() 2299451b44SJordan Rupprecht exe = self.getBuildArtifact("a.out") 2399451b44SJordan Rupprecht self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 2499451b44SJordan Rupprecht 251f933ff9SRaphael Isemann # No quotes. 261f933ff9SRaphael Isemann self.expect_args("a b c", "a\0b\0c\0") 271f933ff9SRaphael Isemann # Single quotes. 281f933ff9SRaphael Isemann self.expect_args("'a b c'", "a b c\0") 291f933ff9SRaphael Isemann # Double quotes. 301f933ff9SRaphael Isemann self.expect_args('"a b c"', "a b c\0") 311f933ff9SRaphael Isemann # Single quote escape. 321f933ff9SRaphael Isemann self.expect_args("'a b\\' c", "a b\\\0c\0") 331f933ff9SRaphael Isemann # Double quote escape. 341f933ff9SRaphael Isemann self.expect_args('"a b\\" c"', 'a b" c\0') 352238dcc3SJonas Devlieghere self.expect_args('"a b\\\\" c', "a b\\\0c\0") 361f933ff9SRaphael Isemann # Single quote in double quotes. 371f933ff9SRaphael Isemann self.expect_args('"a\'b"', "a'b\0") 381f933ff9SRaphael Isemann # Double quotes in single quote. 391f933ff9SRaphael Isemann self.expect_args("'a\"b'", 'a"b\0') 401f933ff9SRaphael Isemann # Combined quotes. 412238dcc3SJonas Devlieghere self.expect_args("\"a b\"c'd e'", "a bcd e\0") 421f933ff9SRaphael Isemann # Bare single/double quotes. 431f933ff9SRaphael Isemann self.expect_args("a\\'b", "a'b\0") 441f933ff9SRaphael Isemann self.expect_args('a\\"b', 'a"b\0') 451f933ff9SRaphael Isemann 461f933ff9SRaphael Isemann def expect_args(self, args_in, args_out): 471f933ff9SRaphael Isemann """Test argument parsing. Run the program with args_in. The program dumps its arguments 481f933ff9SRaphael Isemann to stdout. Compare the stdout with args_out.""" 491f933ff9SRaphael Isemann 501f933ff9SRaphael Isemann filename = SettingsCommandTestCase.output_file_name 511f933ff9SRaphael Isemann outfile = self.getBuildArtifact(filename) 5299451b44SJordan Rupprecht 53257f9846SJonas Devlieghere if lldb.remote_platform: 54*7ce3dd49SDmitry Vasilyev outfile_arg = lldbutil.append_to_process_working_directory(self, filename) 55257f9846SJonas Devlieghere else: 56257f9846SJonas Devlieghere outfile_arg = outfile 57257f9846SJonas Devlieghere 58257f9846SJonas Devlieghere self.runCmd("process launch -- %s %s" % (outfile_arg, args_in)) 5999451b44SJordan Rupprecht 6099451b44SJordan Rupprecht if lldb.remote_platform: 61257f9846SJonas Devlieghere src_file_spec = lldb.SBFileSpec(outfile_arg, False) 621f933ff9SRaphael Isemann dst_file_spec = lldb.SBFileSpec(outfile, True) 6399451b44SJordan Rupprecht lldb.remote_platform.Get(src_file_spec, dst_file_spec) 6499451b44SJordan Rupprecht 652238dcc3SJonas Devlieghere with open(outfile, "r") as f: 6699451b44SJordan Rupprecht output = f.read() 6799451b44SJordan Rupprecht 681f933ff9SRaphael Isemann self.RemoveTempFile(outfile) 6999451b44SJordan Rupprecht self.assertEqual(output, args_out) 70