[clang-tools-extra] [clang-doc] Add regression test for test comments in macros (PR #132510)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 16 23:58:21 PDT 2025
================
@@ -0,0 +1,35 @@
+// Regression test for https://github.com/llvm/llvm-project/issues/59819
+
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --format=md --doxygen --output=%t --executor=standalone %s
+// RUN: FileCheck %s < %t/GlobalNamespace/MyClass.md --check-prefix=MD-MYCLASS-LINE
+// RUN: FileCheck %s < %t/GlobalNamespace/MyClass.md --check-prefix=MD-MYCLASS
+
+// RUN: clang-doc --format=html --doxygen --output=%t --executor=standalone %s
+// RUN: FileCheck %s < %t/GlobalNamespace/MyClass.html --check-prefix=HTML-MYCLASS-LINE
+// RUN: FileCheck %s < %t/GlobalNamespace/MyClass.html --check-prefix=HTML-MYCLASS
+
+#define DECLARE_METHODS \
+ /** \
+ * @brief Declare a method to calculate the sum of two numbers\
+ */ \
+ int Add(int a, int b) { \
+ return a + b; \
+ }
+
+// MD-MYCLASS: ### Add
+// MD-MYCLASS: *public int Add(int a, int b)*
+// MD-MYCLASS: **brief** Declare a method to calculate the sum of two numbers
+
+// HTML-MYCLASS: <p>public int Add(int a, int b)</p>
+// HTML-MYCLASS: <div>brief</div>
+// HTML-MYCLASS: <p> Declare a method to calculate the sum of two numbers</p>
+
+
+class MyClass {
+public:
+// MD-MYCLASS-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}macro.cpp#[[@LINE+2]]*
+// HTML-MYCLASS-LINE: <p>Defined at line [[@LINE+1]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}macro.cpp</p>
----------------
ZhongUncle wrote:
> So does `ninja check-clang-extra-clang-doc` pass w/ your changes?
No, it doesn't passed w/ my change. I also test it via `llvm-lit llvm-project/clang-tools-extra/test/clang-doc/`.
Because below code
```
#define DECLARE_METHODS \
/** \
* @brief Declare a method to calculate the sum of two numbers\
*/ \
int Add(int a, int b) { \
return a + b; \
}
```
will generate something like below (there are additional `\` appearing):
```
\
Declare a method to calculate the sum of two numbers\
```
rather than correct content generated:
```
Declare a method to calculate the sum of two numbers
```
But I test it using correct content generated. It is why not pass test. They don't match, so not pass.
We discussed this rare comment style before, and you suggested that I add a `\` to each EOL, because it is example in #59819. But recently, I noticed via the editor highlighting that if you add a `\`, it will be considered as a character in the comment, rather than indicating the comment as a whole. If you add a `\`, it will be considered as a character in the comment.
Below image is in vim, you can see color of `\` is same as comment (I also test it in VS Code, same highlight):
<img width="490" alt="截屏2025-04-17 14 39 51" src="https://github.com/user-attachments/assets/27343500-690d-4081-b228-4083f9e57246" />
So I don't think that it is issues of other feature. The problem is our example.
At beginning, I use this kind of comment
```
#define DECLARE_METHODS \
/**
* @brief Declare a method to calculate the sum of two numbers
*/ \
int Add(int a, int b) { \
return a + b; \
}
```
It passed test. So I think: **Should I change code like above**?
> Well, its a test, so it needs to be correct w.r.t. the thing you're testing, and shouldn't be broken overall (or at least not broken in a new way).
Oh, make sense. I will remove this line check in Class. I checked the line numbers here because I saw it written in other tests, so I thought I had to check all the key parts.
https://github.com/llvm/llvm-project/pull/132510
More information about the cfe-commits
mailing list