1 """Test the RunCommandInterpreter API."""
5 from lldbsuite
.test
.decorators
import *
6 from lldbsuite
.test
.lldbtest
import *
9 class CommandRunInterpreterLegacyAPICase(TestBase
):
10 NO_DEBUG_INFO_TESTCASE
= True
15 self
.stdin_path
= self
.getBuildArtifact("stdin.txt")
17 with
open(self
.stdin_path
, "w") as input_handle
:
18 input_handle
.write("nonexistingcommand\nquit")
20 # Python will close the file descriptor if all references
21 # to the filehandle object lapse, so we need to keep one
23 self
.filehandle
= open(self
.stdin_path
, "r")
24 self
.dbg
.SetInputFileHandle(self
.filehandle
, False)
26 # No need to track the output
27 self
.devnull
= open(os
.devnull
, "w")
28 self
.dbg
.SetOutputFileHandle(self
.devnull
, False)
29 self
.dbg
.SetErrorFileHandle(self
.devnull
, False)
31 def test_run_session_with_error_and_quit_legacy(self
):
32 """Run non-existing and quit command returns appropriate values"""
34 n_errors
, quit_requested
, has_crashed
= self
.dbg
.RunCommandInterpreter(
35 True, False, lldb
.SBCommandInterpreterRunOptions(), 0, False, False
38 self
.assertGreater(n_errors
, 0)
39 self
.assertTrue(quit_requested
)
40 self
.assertFalse(has_crashed
)
43 class CommandRunInterpreterAPICase(TestBase
):
44 NO_DEBUG_INFO_TESTCASE
= True
49 self
.stdin_path
= self
.getBuildArtifact("stdin.txt")
51 with
open(self
.stdin_path
, "w") as input_handle
:
52 input_handle
.write("nonexistingcommand\nquit")
54 self
.dbg
.SetInputFile(open(self
.stdin_path
, "r"))
56 # No need to track the output
57 devnull
= open(os
.devnull
, "w")
58 self
.dbg
.SetOutputFile(devnull
)
59 self
.dbg
.SetErrorFile(devnull
)
61 def test_run_session_with_error_and_quit(self
):
62 """Run non-existing and quit command returns appropriate values"""
64 n_errors
, quit_requested
, has_crashed
= self
.dbg
.RunCommandInterpreter(
65 True, False, lldb
.SBCommandInterpreterRunOptions(), 0, False, False
68 self
.assertGreater(n_errors
, 0)
69 self
.assertTrue(quit_requested
)
70 self
.assertFalse(has_crashed
)
73 class SBCommandInterpreterRunOptionsCase(TestBase
):
74 NO_DEBUG_INFO_TESTCASE
= True
76 def test_command_interpreter_run_options(self
):
77 """Test SBCommandInterpreterRunOptions default values, getters & setters"""
79 opts
= lldb
.SBCommandInterpreterRunOptions()
81 # Check getters with default values
82 self
.assertEqual(opts
.GetStopOnContinue(), False)
83 self
.assertEqual(opts
.GetStopOnError(), False)
84 self
.assertEqual(opts
.GetStopOnCrash(), False)
85 self
.assertEqual(opts
.GetEchoCommands(), True)
86 self
.assertEqual(opts
.GetPrintResults(), True)
87 self
.assertEqual(opts
.GetPrintErrors(), True)
88 self
.assertEqual(opts
.GetAddToHistory(), True)
91 opts
.SetStopOnContinue(not opts
.GetStopOnContinue())
92 opts
.SetStopOnError(not opts
.GetStopOnError())
93 opts
.SetStopOnCrash(not opts
.GetStopOnCrash())
94 opts
.SetEchoCommands(not opts
.GetEchoCommands())
95 opts
.SetPrintResults(not opts
.GetPrintResults())
96 opts
.SetPrintErrors(not opts
.GetPrintErrors())
97 opts
.SetAddToHistory(not opts
.GetAddToHistory())
99 # Check the value changed
100 self
.assertEqual(opts
.GetStopOnContinue(), True)
101 self
.assertEqual(opts
.GetStopOnError(), True)
102 self
.assertEqual(opts
.GetStopOnCrash(), True)
103 self
.assertEqual(opts
.GetEchoCommands(), False)
104 self
.assertEqual(opts
.GetPrintResults(), False)
105 self
.assertEqual(opts
.GetPrintErrors(), False)
106 self
.assertEqual(opts
.GetAddToHistory(), False)