[Lldb-commits] [PATCH] D123500: [lldb][NFC] Add more tests for GenerateOptionsUsage

David Spickett via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 25 07:33:42 PDT 2022


DavidSpickett updated this revision to Diff 424900.
DavidSpickett added a comment.

I realised that in theory the tests could still pass if your ordering
just happend to land in the right way.

For the short option `[-ABCabc]` there's not a lot I can do about that,
so I added another check for a different command. More chance to catch
non-determinism. I don't think any commands have enough options to make
it 100% sure.

For the detailed options I switched from a regex to cutting up the
output with python. Then once we've got all the short names we can
check the whole order.

(and I checked, when it fails you do get a list specific comparison output)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123500/new/

https://reviews.llvm.org/D123500

Files:
  lldb/test/API/commands/help/TestHelp.py


Index: lldb/test/API/commands/help/TestHelp.py
===================================================================
--- lldb/test/API/commands/help/TestHelp.py
+++ lldb/test/API/commands/help/TestHelp.py
@@ -243,3 +243,63 @@
                 "-f <format> ( --format <format> )", "The format to use for each of the value to be written.",
                 "-s <byte-size> ( --size <byte-size> )", "The size in bytes to write from input file or each value."])
 
+    @no_debug_info_test
+    def test_help_shows_optional_short_options(self):
+        """Test that optional short options are printed and that they are in
+           alphabetical order with upper case options first."""
+        self.expect("help memory read",
+                    substrs=["memory read [-br]", "memory read [-AFLORTr]"])
+        self.expect("help target modules lookup",
+                    substrs=["target modules lookup [-Airv]"])
+
+    @no_debug_info_test
+    def test_help_shows_command_options_usage(self):
+        """Test that we start the usage section with a specific line."""
+        self.expect("help memory read", substrs=["Command Options Usage:\n  memory read"])
+
+    @no_debug_info_test
+    def test_help_detailed_information_spacing(self):
+        """Test that we put a break between the usage and the options help lines,
+           and between the options themselves."""
+        self.expect("help memory read", substrs=[
+                    "[<address-expression>]\n\n       --show-tags",
+                    # Starts with the end of the show-tags line
+                    "output).\n\n       -A"])
+
+    @no_debug_info_test
+    def test_help_detailed_information_ordering(self):
+        """Test that we order options alphabetically, upper case first."""
+        # You could test this with a simple regex like:
+        # <upper case>.*<later upper case>.*<lower case>.*<later lower case>
+        # Except that that could pass sometimes even with shuffled output.
+        # This makes sure that doesn't happen.
+
+        self.runCmd("help memory read")
+        got = self.res.GetOutput()
+        _, options_lines = got.split("Command Options Usage:")
+        options_lines = options_lines.lstrip().splitlines()
+
+        # Skip over "memory read [-xyz] lines.
+        while("memory read" in options_lines[0]):
+            options_lines.pop(0)
+        # Plus the newline after that.
+        options_lines.pop(0)
+
+        short_options = []
+        for line in options_lines:
+            # Ignore line breaks and descriptions.
+            # (not stripping the line here in case some line of the descriptions
+            # happens to start with "-")
+            if not line or not line.startswith("       -"):
+                continue
+            # This apears at the end after the options.
+            if "This command takes options and free form arguments." in line:
+                break
+            line = line.strip()
+            # The order of -- only options is not enforced so ignore their position.
+            if not line.startswith("--"):
+                # Save its short char name.
+                short_options.append(line[1])
+
+        self.assertEqual(sorted(short_options), short_options,
+                         "Short option help displayed in an incorrect order!")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123500.424900.patch
Type: text/x-patch
Size: 3325 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220425/bef99be5/attachment.bin>


More information about the lldb-commits mailing list