Any time we see the pattern `assertEqual(value, bool)`, we can replace
that with `assert<bool>(value)`. Likewise for `assertNotEqual`.
Technically this relaxes the test a bit, as we may want to make sure
`value` is either `True` or `False`, and not something that implicitly
converts to a bool. For example, `assertEqual("foo", True)` will fail,
but `assertTrue("foo")` will not. In most cases, this distinction is not
important.
There are two such places that this patch does **not** transform, since
it seems intentional that we want the result to be a bool:
*
5daf2001a1/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py (L90)
*
5daf2001a1/lldb/test/API/commands/settings/TestSettings.py (L940)
Followup to 9c2468821e. I patched `teyit`
with a `visit_assertEqual` node handler to generate this.
107 lines
3.7 KiB
Python
107 lines
3.7 KiB
Python
"""Test the RunCommandInterpreter API."""
|
|
|
|
import os
|
|
import lldb
|
|
from lldbsuite.test.decorators import *
|
|
from lldbsuite.test.lldbtest import *
|
|
|
|
|
|
class CommandRunInterpreterLegacyAPICase(TestBase):
|
|
NO_DEBUG_INFO_TESTCASE = True
|
|
|
|
def setUp(self):
|
|
TestBase.setUp(self)
|
|
|
|
self.stdin_path = self.getBuildArtifact("stdin.txt")
|
|
|
|
with open(self.stdin_path, "w") as input_handle:
|
|
input_handle.write("nonexistingcommand\nquit")
|
|
|
|
# Python will close the file descriptor if all references
|
|
# to the filehandle object lapse, so we need to keep one
|
|
# around.
|
|
self.filehandle = open(self.stdin_path, "r")
|
|
self.dbg.SetInputFileHandle(self.filehandle, False)
|
|
|
|
# No need to track the output
|
|
self.devnull = open(os.devnull, "w")
|
|
self.dbg.SetOutputFileHandle(self.devnull, False)
|
|
self.dbg.SetErrorFileHandle(self.devnull, False)
|
|
|
|
def test_run_session_with_error_and_quit_legacy(self):
|
|
"""Run non-existing and quit command returns appropriate values"""
|
|
|
|
n_errors, quit_requested, has_crashed = self.dbg.RunCommandInterpreter(
|
|
True, False, lldb.SBCommandInterpreterRunOptions(), 0, False, False
|
|
)
|
|
|
|
self.assertGreater(n_errors, 0)
|
|
self.assertTrue(quit_requested)
|
|
self.assertFalse(has_crashed)
|
|
|
|
|
|
class CommandRunInterpreterAPICase(TestBase):
|
|
NO_DEBUG_INFO_TESTCASE = True
|
|
|
|
def setUp(self):
|
|
TestBase.setUp(self)
|
|
|
|
self.stdin_path = self.getBuildArtifact("stdin.txt")
|
|
|
|
with open(self.stdin_path, "w") as input_handle:
|
|
input_handle.write("nonexistingcommand\nquit")
|
|
|
|
self.dbg.SetInputFile(open(self.stdin_path, "r"))
|
|
|
|
# No need to track the output
|
|
devnull = open(os.devnull, "w")
|
|
self.dbg.SetOutputFile(devnull)
|
|
self.dbg.SetErrorFile(devnull)
|
|
|
|
def test_run_session_with_error_and_quit(self):
|
|
"""Run non-existing and quit command returns appropriate values"""
|
|
|
|
n_errors, quit_requested, has_crashed = self.dbg.RunCommandInterpreter(
|
|
True, False, lldb.SBCommandInterpreterRunOptions(), 0, False, False
|
|
)
|
|
|
|
self.assertGreater(n_errors, 0)
|
|
self.assertTrue(quit_requested)
|
|
self.assertFalse(has_crashed)
|
|
|
|
|
|
class SBCommandInterpreterRunOptionsCase(TestBase):
|
|
NO_DEBUG_INFO_TESTCASE = True
|
|
|
|
def test_command_interpreter_run_options(self):
|
|
"""Test SBCommandInterpreterRunOptions default values, getters & setters"""
|
|
|
|
opts = lldb.SBCommandInterpreterRunOptions()
|
|
|
|
# Check getters with default values
|
|
self.assertFalse(opts.GetStopOnContinue())
|
|
self.assertFalse(opts.GetStopOnError())
|
|
self.assertFalse(opts.GetStopOnCrash())
|
|
self.assertTrue(opts.GetEchoCommands())
|
|
self.assertTrue(opts.GetPrintResults())
|
|
self.assertTrue(opts.GetPrintErrors())
|
|
self.assertTrue(opts.GetAddToHistory())
|
|
|
|
# Invert values
|
|
opts.SetStopOnContinue(not opts.GetStopOnContinue())
|
|
opts.SetStopOnError(not opts.GetStopOnError())
|
|
opts.SetStopOnCrash(not opts.GetStopOnCrash())
|
|
opts.SetEchoCommands(not opts.GetEchoCommands())
|
|
opts.SetPrintResults(not opts.GetPrintResults())
|
|
opts.SetPrintErrors(not opts.GetPrintErrors())
|
|
opts.SetAddToHistory(not opts.GetAddToHistory())
|
|
|
|
# Check the value changed
|
|
self.assertTrue(opts.GetStopOnContinue())
|
|
self.assertTrue(opts.GetStopOnError())
|
|
self.assertTrue(opts.GetStopOnCrash())
|
|
self.assertFalse(opts.GetEchoCommands())
|
|
self.assertFalse(opts.GetPrintResults())
|
|
self.assertFalse(opts.GetPrintErrors())
|
|
self.assertFalse(opts.GetAddToHistory())
|