]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
unittests: test_tokenizer: better handle mismatch error
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Wed, 18 Mar 2026 09:11:01 +0000 (10:11 +0100)
committerJonathan Corbet <corbet@lwn.net>
Sun, 22 Mar 2026 21:10:39 +0000 (15:10 -0600)
The current logic is too sensitive to how c_lex name is
placed. Also, it doesn't really check the log.

Change it to check if the expected message will be reported
after a call to C tokenizer with an invalid source.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Message-ID: <6e19578bc1ffa96e536dc31997ff658017f60173.1773823995.git.mchehab+huawei@kernel.org>

tools/unittests/test_tokenizer.py

index 5634b4a7283e59de8c1ca0c526bbc5adb08d1299..d1f3c565b9cf24cf74805b831fa1141f852c006e 100755 (executable)
@@ -46,10 +46,17 @@ def make_tokenizer_test(name, data):
         #
         # Check if logger is working
         #
-        if "log_level" in data:
-            with self.assertLogs('kdoc.c_lex', level='ERROR') as cm:
+        if "log_msg" in data:
+            with self.assertLogs() as cm:
                 tokenizer = CTokenizer(data["source"])
 
+                msg_found = False
+                for result in cm.output:
+                    if data["log_msg"] in result:
+                        msg_found = True
+
+                self.assertTrue(msg_found, f"Missing log {data['log_msg']}")
+
             return
 
         #
@@ -124,7 +131,7 @@ TESTS_TOKENIZER = {
 
     "mismatch_error": {
         "source": "int a$ = 5;",          # $ is illegal
-        "log_level": "ERROR",
+        "log_msg": "Unexpected token",
     },
 }