https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/178235
>From 786043098370be415a9c8a81086a77a432600056 Mon Sep 17 00:00:00 2001 From: David Spickett <[email protected]> Date: Tue, 27 Jan 2026 14:35:46 +0000 Subject: [PATCH 1/2] [lldb] Make "help format" test more strict Originally added in a81bd7f1014f316b42bf7274f76a340b833e663b, this test either was not strict enough, or lldb's behaviour has drifted since. I think the intention was to check exactly when the output of "help format" would wrap. Which should happen when we have printed up to the terminal width, minus a few characters because we walk backwards to the closest whitespace point to break at (so we don't split a word). I've updated the test to check the exact outputs and cover printing one line and two instances where we need to split different amounts onto a second line. --- lldb/test/API/commands/help/TestHelp.py | 30 +++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lldb/test/API/commands/help/TestHelp.py b/lldb/test/API/commands/help/TestHelp.py index 6aaff17fa4ea6..d03924ecf8b27 100644 --- a/lldb/test/API/commands/help/TestHelp.py +++ b/lldb/test/API/commands/help/TestHelp.py @@ -237,12 +237,38 @@ def test_help_unknown_flag(self): @no_debug_info_test def test_help_format_output(self): - """Test that help output reaches TerminalWidth.""" + """Test that help output reaches TerminalWidth and wraps to the next + line if needed.""" + self.runCmd("settings set term-width 118") + self.expect( + "help format", + matching=True, + patterns=[ + r"^<format> -- One of the format names \(or one-character names\) that can be used to show a variable's value:\n" + r"\s+\"default\"\n" + ], + ) + + # The length of the first line will not be exactly 108 because we split + # at the last whitespace point before the limit. self.runCmd("settings set term-width 108") self.expect( "help format", matching=True, - substrs=["<format> -- One of the format names"], + patterns=[ + r"^<format> -- One of the format names \(or one-character names\) that can be used to show a variable's\n" + r"\s+value:\n" + ], + ) + + self.runCmd("settings set term-width 90") + self.expect( + "help format", + matching=True, + patterns=[ + r"<format> -- One of the format names \(or one-character names\) that can be used to show a\n" + r"\s+variable's value:\n" + ], ) @no_debug_info_test >From 41b6f51714c009fa08439ce6279d82b6d68af15c Mon Sep 17 00:00:00 2001 From: David Spickett <[email protected]> Date: Tue, 27 Jan 2026 15:26:20 +0000 Subject: [PATCH 2/2] [lldb][test] Add tests for formatting of command option descriptions These test the existing behaviour before I attempt to fix #177570. I chose "breakpoint set" because it has options with ANSI underlines in the description. The tests cover no ANSI (use-colour off) and with ANSI (use-color on). The latter is where we have problems right now. --- lldb/test/API/commands/help/TestHelp.py | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/lldb/test/API/commands/help/TestHelp.py b/lldb/test/API/commands/help/TestHelp.py index d03924ecf8b27..15cb07b1f32e6 100644 --- a/lldb/test/API/commands/help/TestHelp.py +++ b/lldb/test/API/commands/help/TestHelp.py @@ -296,6 +296,62 @@ def test_help_option_group_format_options_usage(self): ], ) + @no_debug_info_test + def test_help_option_description_terminal_width_no_ansi(self): + """Test that help on commands formats option descriptions acccording + to the terminal width.""" + # Should fit on one line. + self.runCmd("settings set term-width 138") + self.expect( + "help breakpoint set", + matching=True, + patterns=[ + r"\s+Set the breakpoint only in this shared library. Can repeat this option multiple times to specify multiple shared libraries.\n" + ], + ) + + # Must be printed on two lines. + self.runCmd("settings set term-width 100") + self.expect( + "help breakpoint set", + matching=True, + patterns=[ + r"\s+Set the breakpoint only in this shared library. Can repeat this option multiple times\n" + r"\s+to specify multiple shared libraries.\n" + ], + ) + + @no_debug_info_test + def test_help_option_description_terminal_width_with_ansi(self): + """Test that help on commands formats option descriptions that include + ANSI codes acccording to the terminal width.""" + self.runCmd("settings set use-color on") + + # FIXME: lldb crashes when the width is exactly 135 - https://github.com/llvm/llvm-project/issues/177570 + + # Should fit on one line. + self.runCmd("settings set term-width 138") + self.expect( + "help breakpoint set", + matching=True, + patterns=[ + # The "S" of "Set" is underlined. + r"\s+\x1b\[4mS\x1b\[0met the breakpoint only in this shared library. Can repeat this option multiple times to specify multiple shared libraries.\n" + ], + ) + + # Must be printed on two lines. + # FIXME: Second line is truncated - https://github.com/llvm/llvm-project/issues/177570 + self.runCmd("settings set term-width 100") + self.expect( + "help breakpoint set", + matching=True, + patterns=[ + r"\s+\x1b\[4mS\x1b\[0met the breakpoint only in this shared library. Can repeat this option\n" + r"\s+multiple times to specify multiple shared li\n" + ], + ) + @no_debug_info_test def test_help_shows_optional_short_options(self): """Test that optional short options are printed and that they are in _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
