[clang-tools-extra] [clang-doc] Pre-commit tests for static members and functions (PR #135456)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 11 16:56:28 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Paul Kirth (ilovepi)
<details>
<summary>Changes</summary>
Issue #<!-- -->59813 mentions that static members are not included in
the documentation generated by clang-doc. This patch adds
some basic testing for that property, with the current incorrect
behavior. Follow up patches will address the missing documentation.
---
Full diff: https://github.com/llvm/llvm-project/pull/135456.diff
3 Files Affected:
- (modified) clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h (+22-1)
- (modified) clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp (+1)
- (modified) clang-tools-extra/test/clang-doc/basic-project.test (+18)
``````````diff
diff --git a/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h b/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h
index 6811834bc0159..195721d56fff6 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h
@@ -43,4 +43,25 @@ class Calculator {
* @throw std::invalid_argument if b is zero.
*/
double divide(int a, int b);
-};
\ No newline at end of file
+
+ /**
+ * @brief Performs the mod operation on integers.
+ *
+ * @param a First integer.
+ * @param b Second integer.
+ * @return The result of a % b.
+ */
+ static int mod(int a, int b) {
+ return a % b;
+ }
+
+ /**
+ * @brief A static value.
+ */
+ static constexpr int static_val = 10;
+
+ /**
+ * @brief Holds a public value.
+ */
+ int public_val = -1;
+};
diff --git a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
index 258ea22e46184..483d050e3225a 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
@@ -15,3 +15,4 @@ int Calculator::multiply(int a, int b) {
double Calculator::divide(int a, int b) {
return static_cast<double>(a) / b;
}
+
diff --git a/clang-tools-extra/test/clang-doc/basic-project.test b/clang-tools-extra/test/clang-doc/basic-project.test
index ef26e5b8916b4..822c93a4b2fc0 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -129,6 +129,12 @@
// HTML-CALC: <div>brief</div>
// HTML-CALC: <p> A simple calculator class.</p>
// HTML-CALC: <p> Provides basic arithmetic operations.</p>
+
+// HTML-CALC: <h2 id="Members">Members</h2>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> Holds a public value.</p>
+// HTML-CALC: <div>public int public_val</div>
+
// HTML-CALC: <h2 id="Functions">Functions</h2>
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">add</h3>
// HTML-CALC: <p>public int add(int a, int b)</p>
@@ -185,6 +191,18 @@
// HTML-CALC: <div>throw</div>
// HTML-CALC: <p>if b is zero.</p>
+// HTML-CALC: <p>public int mod(int a, int b)</p>
+// CALC-NO-REPOSITORY: Defined at line 20 of file .{{.}}src{{.}}Calculator.cpp
+// CALC-REPOSITORY: Defined at line
+// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./src/Calculator.cpp#20">20</a>
+// CALC-LINE-PREFIX: <a href="https://repository.com/./src/Calculator.cpp#L20">20</a>
+// CALC-REPOSITORY-NEXT: of file
+// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./src/Calculator.cpp">Calculator.cpp</a>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> Performs the mod operation on integers.</p>
+// HTML-CALC: <div>return</div>
+// HTML-CALC: <p> The result of a % b.</p>
+
// HTML-RECTANGLE: <h1>class Rectangle</h1>
// RECTANGLE-NO-REPOSITORY: <p>Defined at line 10 of file .{{.}}include{{.}}Rectangle.h</p>
// RECTANGLE-REPOSITORY: <p>
``````````
</details>
https://github.com/llvm/llvm-project/pull/135456
More information about the cfe-commits
mailing list