blob: f18c0bc9d6ebe9056df93461fb40c6cb5c7b16c8 [file] [log] [blame]
Johnny Chen77377772010-09-07 17:06:13 +00001"""
2Test lldb settings command.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class SettingsCommandTestCase(TestBase):
11
12 mydir = "settings"
13
14 def test_set_prompt(self):
15 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000016
17 # Use '-o' option to override the existing instance setting.
Johnny Chen77377772010-09-07 17:06:13 +000018 self.runCmd("settings set -o prompt 'lldb2'")
Johnny Chen881c3712010-09-07 17:12:10 +000019
20 # Immediately test the setting.
Johnny Chen77377772010-09-07 17:06:13 +000021 self.expect("settings show prompt",
22 startstr = "prompt (string) = 'lldb2'")
Johnny Chen881c3712010-09-07 17:12:10 +000023
24 # The overall display should also reflect the new setting.
Johnny Chen77377772010-09-07 17:06:13 +000025 self.expect("settings show",
26 substrs = ["prompt (string) = 'lldb2'"])
27
Johnny Chena37764b2010-09-07 17:31:05 +000028 def test_set_term_width(self):
29 """Test that 'set term-width' actually changes the term-width."""
30
31 # No '-o' option is needed for static setting.
32 self.runCmd("settings set term-width 70")
33
34 # Immediately test the setting.
35 self.expect("settings show term-width",
36 startstr = "term-width (int) = '70'")
37
38 # The overall display should also reflect the new setting.
39 self.expect("settings show",
Johnny Chenea772bb2010-09-07 18:55:50 +000040 startstr = "term-width (int) = '70'")
Johnny Chena37764b2010-09-07 17:31:05 +000041
Johnny Chend5e111c2010-09-15 22:27:29 +000042 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
43 def test_with_dsym(self):
44 """Test that run-args and env-vars are passed to the launched process."""
45 self.buildDsym()
46 self.pass_run_args_and_env_vars()
47
48 def test_with_dwarf(self):
49 """Test that run-args and env-vars are passed to the launched process."""
50 self.buildDwarf()
51 self.pass_run_args_and_env_vars()
52
53 def pass_run_args_and_env_vars(self):
54 """Test that run-args and env-vars are passed to the launched process."""
55 exe = os.path.join(os.getcwd(), "a.out")
56 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
57
58 # Set the run-args and the env-vars.
59 self.runCmd('settings set process.run-args A B C')
60 self.runCmd('settings set process.env-vars ["MY_ENV_VAR"]=YES')
61
62 self.runCmd("run", RUN_SUCCEEDED)
63
64 # Read the output file produced by running the program.
65 output = open('/tmp/output.txt', 'r').read()
66
67 self.assertTrue(output.startswith("argv[1] matches") and
68 output.find("argv[2] matches") > 0 and
69 output.find("argv[3] matches") > 0 and
70 output.find("Environment variable 'MY_ENV_VAR' successfully passed.") > 0)
71
Johnny Chen77377772010-09-07 17:06:13 +000072
73if __name__ == '__main__':
74 import atexit
75 lldb.SBDebugger.Initialize()
76 atexit.register(lambda: lldb.SBDebugger.Terminate())
77 unittest2.main()