From: 闲逛 <2368492046@qq.com>
To: corbet <corbet@lwn.net>, mchehab <mchehab@kernel.org>
Cc: wy <wy@wyuan.org>, linux-doc <linux-doc@vger.kernel.org>,
skhan <skhan@linuxfoundation.org>,
rdunlap <rdunlap@infradead.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 4/4] docs: kernel-doc: import sys for YAML failure diagnostics
Date: Sat, 14 Nov 2026 17:06:36 +0800 [thread overview]
Message-ID: <tencent_50889D4FAD577261C37393C80A483FA47906@qq.com> (raw)
From: yuehua-meng <2368492046@qq.com>
Missing PyYAML and nonexistent output directories reach sys.exit()
without importing sys. This raises NameError instead of reporting
the intended diagnostic.
Import sys and add CLI tests for both failures and successful YAML
generation. The missing-dependency test disables site packages.
Fixes: b37b3cbbb1f1 ("docs: add a new file to write kernel-doc output to a YAML file")
Signed-off-by: yuehua-meng <2368492046@qq.com>
---
Changes in v2:
Rebase onto docs-next; no functional change from the signed v1.
tools/lib/python/kdoc/kdoc_yaml_file.py | 1 +
tools/unittests/test_kdoc_yaml.py | 37 +++++++++++++++++++++++++
2 files changed, 38 insertions(+)
create mode 100644 tools/unittests/test_kdoc_yaml.py
diff --git a/tools/lib/python/kdoc/kdoc_yaml_file.py b/tools/lib/python/kdoc/kdoc_yaml_file.py
index 0be020d50..eb5e51c36 100644
--- a/tools/lib/python/kdoc/kdoc_yaml_file.py
+++ b/tools/lib/python/kdoc/kdoc_yaml_file.py
@@ -3,6 +3,7 @@
# Copyright(c) 2026: Mauro Carvalho Chehab <mchehab@kernel.org>.
import os
+import sys
from kdoc.kdoc_output import ManFormat, RestFormat
diff --git a/tools/unittests/test_kdoc_yaml.py b/tools/unittests/test_kdoc_yaml.py
new file mode 100644
index 000000000..e38ddd131
--- /dev/null
+++ b/tools/unittests/test_kdoc_yaml.py
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: GPL-2.0
+"""Regression tests for kernel-doc YAML generation and error handling."""
+
+import yaml
+
+from kdoc_cli_helper import KernelDocCliTest
+
+
+class TestKernelDocYaml(KernelDocCliTest):
+ def setUp(self):
+ super().setUp()
+ self.input = self.source("example.c", (
+ "/**\n * example - documented function\n */\n"
+ "void example(void) {}\n"
+ ))
+
+ def test_missing_dependency(self):
+ result = self.run_kdoc("--yaml", self.directory / "test.yaml",
+ self.input, no_site=True)
+ self.assertEqual(result.returncode, 1)
+ self.assertIn("yaml package not available", result.stderr)
+ self.assertNotIn("Traceback", result.stderr)
+
+ def test_missing_directory(self):
+ result = self.run_kdoc("--yaml", self.directory / "missing/test.yaml",
+ self.input)
+ self.assertEqual(result.returncode, 1)
+ self.assertIn("doesn't exist", result.stderr)
+ self.assertNotIn("Traceback", result.stderr)
+
+ def test_valid_output(self):
+ output = self.directory / "test.yaml"
+ result = self.run_kdoc("--yaml", output, self.input)
+ self.assertEqual(result.returncode, 0, result.stderr)
+ data = yaml.safe_load(output.read_text(encoding="utf-8"))
+ self.assertEqual(len(data["tests"]), 1)
+ self.assertEqual(data["tests"][0]["name"], "example")
--
2.53.0.windows.2
reply other threads:[~2026-11-14 9:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_50889D4FAD577261C37393C80A483FA47906@qq.com \
--to=2368492046@qq.com \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=wy@wyuan.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®