blob: e7dbdce2fae20e32e644b054d7ef7fe55581e522 [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
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000014 @classmethod
15 def classCleanup(cls):
16 system(["/bin/sh", "-c", "rm output.txt"])
17
Johnny Chen77377772010-09-07 17:06:13 +000018 def test_set_prompt(self):
19 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000020
21 # Use '-o' option to override the existing instance setting.
Johnny Chen77377772010-09-07 17:06:13 +000022 self.runCmd("settings set -o prompt 'lldb2'")
Johnny Chen881c3712010-09-07 17:12:10 +000023
24 # Immediately test the setting.
Johnny Chen77377772010-09-07 17:06:13 +000025 self.expect("settings show prompt",
26 startstr = "prompt (string) = 'lldb2'")
Johnny Chen881c3712010-09-07 17:12:10 +000027
28 # The overall display should also reflect the new setting.
Johnny Chen77377772010-09-07 17:06:13 +000029 self.expect("settings show",
30 substrs = ["prompt (string) = 'lldb2'"])
31
Johnny Chena37764b2010-09-07 17:31:05 +000032 def test_set_term_width(self):
33 """Test that 'set term-width' actually changes the term-width."""
34
35 # No '-o' option is needed for static setting.
36 self.runCmd("settings set term-width 70")
37
38 # Immediately test the setting.
39 self.expect("settings show term-width",
40 startstr = "term-width (int) = '70'")
41
42 # The overall display should also reflect the new setting.
43 self.expect("settings show",
Johnny Chenea772bb2010-09-07 18:55:50 +000044 startstr = "term-width (int) = '70'")
Johnny Chena37764b2010-09-07 17:31:05 +000045
Johnny Chend5e111c2010-09-15 22:27:29 +000046 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
47 def test_with_dsym(self):
48 """Test that run-args and env-vars are passed to the launched process."""
49 self.buildDsym()
50 self.pass_run_args_and_env_vars()
51
52 def test_with_dwarf(self):
53 """Test that run-args and env-vars are passed to the launched process."""
54 self.buildDwarf()
55 self.pass_run_args_and_env_vars()
56
57 def pass_run_args_and_env_vars(self):
58 """Test that run-args and env-vars are passed to the launched process."""
59 exe = os.path.join(os.getcwd(), "a.out")
60 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
61
62 # Set the run-args and the env-vars.
63 self.runCmd('settings set process.run-args A B C')
64 self.runCmd('settings set process.env-vars ["MY_ENV_VAR"]=YES')
65
66 self.runCmd("run", RUN_SUCCEEDED)
67
68 # Read the output file produced by running the program.
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000069 output = open('output.txt', 'r').read()
Johnny Chend5e111c2010-09-15 22:27:29 +000070
71 self.assertTrue(output.startswith("argv[1] matches") and
72 output.find("argv[2] matches") > 0 and
73 output.find("argv[3] matches") > 0 and
74 output.find("Environment variable 'MY_ENV_VAR' successfully passed.") > 0)
75
Johnny Chen77377772010-09-07 17:06:13 +000076
77if __name__ == '__main__':
78 import atexit
79 lldb.SBDebugger.Initialize()
80 atexit.register(lambda: lldb.SBDebugger.Terminate())
81 unittest2.main()