[PATCH 08/10] docs: kdoc_yaml_file: use a better name for the tests

Mauro Carvalho Chehab posted 10 patches 1 week, 4 days ago
[PATCH 08/10] docs: kdoc_yaml_file: use a better name for the tests
Posted by Mauro Carvalho Chehab 1 week, 4 days ago
Instead of always using a name with a number on it, use
the name of the object directly whenever possible.

When the name is already used, append a number prefix at
the end.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 tools/lib/python/kdoc/kdoc_yaml_file.py | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/tools/lib/python/kdoc/kdoc_yaml_file.py b/tools/lib/python/kdoc/kdoc_yaml_file.py
index 1e2ae7c59d70..0be020d50df0 100644
--- a/tools/lib/python/kdoc/kdoc_yaml_file.py
+++ b/tools/lib/python/kdoc/kdoc_yaml_file.py
@@ -25,6 +25,7 @@ class KDocTestFile():
         self.config = config
         self.test_file = os.path.expanduser(yaml_file)
         self.yaml_content = yaml_content
+        self.test_names = set()
 
         self.tests = []
 
@@ -102,13 +103,10 @@ class KDocTestFile():
         if not symbols:
             return
 
-        base_name = "test_" + fname.replace(".", "_").replace("/", "_")
         expected_dict = {}
         start_line=1
 
-        for i in range(0, len(symbols)):
-            arg = symbols[i]
-
+        for arg in symbols:
             source = arg.get("source", "")
 
             if arg and "KdocItem" in self.yaml_content:
@@ -120,6 +118,21 @@ class KDocTestFile():
 
                 expected_dict["kdoc_item"] = msg
 
+            base_name = arg.name
+            if not base_name:
+                base_name = fname
+            base_name = base_name.lower().replace(".", "_").replace("/", "_")
+
+
+            # Don't add duplicated names
+            i = 0
+            name = base_name
+            while name in self.test_names:
+                i += 1
+                name = f"{base_name}_{i:03d}"
+
+            self.test_names.add(name)
+
             for out_style in self.out_style:
                 if isinstance(out_style, ManFormat):
                     key = "man"
@@ -128,8 +141,6 @@ class KDocTestFile():
 
                 expected_dict[key]= out_style.output_symbols(fname, [arg]).strip()
 
-            name = f"{base_name}_{i:03d}"
-
             test = {
                 "name": name,
                 "description": f"{fname} line {arg.declaration_start_line}",
-- 
2.53.0