85 lines · python
1"""2Test lldb-dap command hooks3"""4 5import lldbdap_testcase6from lldbsuite.test.decorators import *7 8 9class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase):10 def test_command_directive_quiet_on_success(self):11 program = self.getBuildArtifact("a.out")12 command_quiet = (13 "settings set target.show-hex-variable-values-with-leading-zeroes false"14 )15 command_not_quiet = (16 "settings set target.show-hex-variable-values-with-leading-zeroes true"17 )18 self.build_and_launch(19 program,20 initCommands=["?" + command_quiet, command_not_quiet],21 terminateCommands=["?" + command_quiet, command_not_quiet],22 stopCommands=["?" + command_quiet, command_not_quiet],23 exitCommands=["?" + command_quiet, command_not_quiet],24 )25 full_output = self.collect_console(26 pattern=command_not_quiet,27 )28 self.assertNotIn(command_quiet, full_output)29 self.assertIn(command_not_quiet, full_output)30 31 def do_test_abort_on_error(32 self,33 use_init_commands=False,34 use_launch_commands=False,35 use_pre_run_commands=False,36 use_post_run_commands=False,37 ):38 program = self.getBuildArtifact("a.out")39 command_quiet = (40 "settings set target.show-hex-variable-values-with-leading-zeroes false"41 )42 command_abort_on_error = "settings set foo bar"43 commands = ["?!" + command_quiet, "!" + command_abort_on_error]44 self.build_and_launch(45 program,46 initCommands=commands if use_init_commands else None,47 launchCommands=commands if use_launch_commands else None,48 preRunCommands=commands if use_pre_run_commands else None,49 postRunCommands=commands if use_post_run_commands else None,50 expectFailure=True,51 )52 full_output = self.collect_console(53 pattern=command_abort_on_error,54 )55 self.assertNotIn(command_quiet, full_output)56 self.assertIn(command_abort_on_error, full_output)57 58 def test_command_directive_abort_on_error_init_commands(self):59 self.do_test_abort_on_error(use_init_commands=True)60 61 def test_command_directive_abort_on_error_launch_commands(self):62 self.do_test_abort_on_error(use_launch_commands=True)63 64 def test_command_directive_abort_on_error_pre_run_commands(self):65 self.do_test_abort_on_error(use_pre_run_commands=True)66 67 def test_command_directive_abort_on_error_post_run_commands(self):68 self.do_test_abort_on_error(use_post_run_commands=True)69 70 def test_command_directive_abort_on_error_attach_commands(self):71 command_quiet = (72 "settings set target.show-hex-variable-values-with-leading-zeroes false"73 )74 command_abort_on_error = "settings set foo bar"75 program = self.build_and_create_debug_adapter_for_attach()76 resp = self.attach(77 program=program,78 attachCommands=["?!" + command_quiet, "!" + command_abort_on_error],79 expectFailure=True,80 )81 self.assertFalse(resp["success"], "expected 'attach' failure")82 full_output = self.collect_console(pattern=command_abort_on_error)83 self.assertNotIn(command_quiet, full_output)84 self.assertIn(command_abort_on_error, full_output)85