[clang-tools-extra] [clang-doc] Add regression test for test comments in macros (PR #132510)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 19 04:59:11 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:
Oh, I check the code, this error is due to we change the filename `macro.cpp` to `comments-in-macros.cpp`. But not change in line number match, you can see it. It doesn't failed via matching wrong line number. This is a very funny mistake.
After I change the filename here, you can see the `\` in error log:
```
/home/zhonguncle/Desktop/llvm-project/clang-tools-extra/test/clang-doc/comments-in-macros.cpp:25:18: error: HTML-MYCLASS: expected string not found in input
// HTML-MYCLASS: <p> Declare a method to calculate the sum of two numbers</p>
^
<stdin>:22:18: note: scanning from here
<div>brief</div>
^
<stdin>:23:2: note: possible intended match here
<p> Declare a method to calculate the sum of two numbers\</p>
^
Input file: <stdin>
Check file: /home/zhonguncle/Desktop/llvm-project/clang-tools-extra/test/clang-doc/comments-in-macros.cpp
-dump-input=help explains the following input dump.
Input was:
<<<<<<
.
.
.
17: <p>Defined at line 30 of file /home/zhonguncle/Desktop/llvm-project/clang-tools-extra/test/clang-doc/comments-in-macros.cpp</p>
18: <div>
19: <div>
20: <p>\</p>
21: <div>
22: <div>brief</div>
check:25'0 X error: no match found
23: <p> Declare a method to calculate the sum of two numbers\</p>
check:25'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:25'1 ? possible intended match
24: </div>
check:25'0 ~~~~~~~~
25: </div>
check:25'0 ~~~~~~~~
26: </div>
check:25'0 ~~~~~~~~
27: </div>
check:25'0 ~~~~~~~~
28: </div>
check:25'0 ~~~~~~~~
.
.
.
>>>>>>
--
********************
PASS: Clang Tools :: clang-doc/enum.cpp (9 of 11)
PASS: Clang Tools :: clang-doc/basic-project.test (10 of 11)
PASS: Clang Tools :: clang-doc/namespace.cpp (11 of 11)
********************
Failed Tests (1):
Clang Tools :: clang-doc/comments-in-macros.cpp
```
You can see ` <p> Declare a method to calculate the sum of two numbers\</p>` apper a `\` in EOL.
If I change comment to
<img width="483" alt="截屏2025-04-19 19 53 25" src="https://github.com/user-attachments/assets/e188a29c-81bf-4a68-9451-3f9844841479" />
The test will all passed:
<img width="849" alt="截屏2025-04-19 19 53 43" src="https://github.com/user-attachments/assets/c9701597-0a02-450c-93f0-c0dfce37ede9" />
So should we change match content or `\` in comment?
https://github.com/llvm/llvm-project/pull/132510
More information about the cfe-commits
mailing list