[clang-tools-extra] [clang-doc] add more test to clang-doc (PR #97518)

Paul Kirth via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 2 22:10:31 PDT 2024


================
@@ -0,0 +1,701 @@
+// RUN: sed 's|$test_dir|%/S|g' %S/Inputs/advance-project/database_template.json > %t/build/compile_commands.json
+// RUN: clang-doc --format=html --doxygen --output=%t/docs --executor=all-TUs %t/build/compile_commands.json
+// RUN: clang-doc --format=md --doxygen --output=%t/docs --executor=all-TUs %t/build/compile_commands.json
+// RUN: FileCheck %s -input-file=%t/docs/index_json.js -check-prefix=JSON-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/@nonymous_namespace/index.html -check-prefix=HTML-ANON-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Array.html -check-prefix=HTML-ARRAY
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.html -check-prefix=HTML-GLOBAL-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/OuterNamespace/InnerNamespace/Circle.html -check-prefix=HTML-CIRCLE
+// RUN: FileCheck %s -input-file=%t/docs/OuterNamespace/InnerNamespace/index.html -check-prefix=HTML-INNER-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/OuterNamespace/InnerNamespace/Shape.html -check-prefix=HTML-SHAPE
+// RUN: FileCheck %s -input-file=%t/docs/OuterNamespace/index.html -check-prefix=HTML-OUTER-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/@nonymous_namespace/index.md -check-prefix=MD-ANON-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Array.md -check-prefix=MD-ARRAY
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.md -check-prefix=MD-GLOBAL-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/OuterNamespace/InnerNamespace/Circle.md -check-prefix=MD-CIRCLE
+// RUN: FileCheck %s -input-file=%t/docs/OuterNamespace/InnerNamespace/index.md -check-prefix=MD-INNER
+// RUN: FileCheck %s -input-file=%t/docs/OuterNamespace/InnerNamespace/Shape.md -check-prefix=MD-SHAPE
+// RUN: FileCheck %s -input-file=%t/docs/OuterNamespace/index.md -check-prefix=MD-OUTER-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/all_files.md -check-prefix=MD-ALL-FILES
+// RUN: FileCheck %s -input-file=%t/docs/index.md -check-prefix=MD-INDEX
+
+// JSON-INDEX: async function LoadIndex() {
+// JSON-INDEX-NEXT: return{
+// JSON-INDEX-NEXT:   "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:   "Name": "",
+// JSON-INDEX-NEXT:   "RefType": "default",
+// JSON-INDEX-NEXT:   "Path": "",
+// JSON-INDEX-NEXT:   "Children": [
+// JSON-INDEX-NEXT:     {
+// JSON-INDEX-NEXT:       "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:       "Name": "@nonymous_namespace",
+// JSON-INDEX-NEXT:       "RefType": "namespace",
+// JSON-INDEX-NEXT:       "Path": "@nonymous_namespace",
+// JSON-INDEX-NEXT:       "Children": []
+// JSON-INDEX-NEXT:     },
+// JSON-INDEX-NEXT:     {
+// JSON-INDEX-NEXT:       "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:       "Name": "GlobalNamespace",
+// JSON-INDEX-NEXT:       "RefType": "namespace",
+// JSON-INDEX-NEXT:       "Path": "GlobalNamespace",
+// JSON-INDEX-NEXT:       "Children": [
+// JSON-INDEX-NEXT:         {
+// JSON-INDEX-NEXT:           "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:           "Name": "Array",
+// JSON-INDEX-NEXT:           "RefType": "record",
+// JSON-INDEX-NEXT:           "Path": "GlobalNamespace",
+// JSON-INDEX-NEXT:           "Children": []
+// JSON-INDEX-NEXT:         }
+// JSON-INDEX-NEXT:       ]
+// JSON-INDEX-NEXT:     },
+// JSON-INDEX-NEXT:     {
+// JSON-INDEX-NEXT:       "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:       "Name": "OuterNamespace",
+// JSON-INDEX-NEXT:       "RefType": "namespace",
+// JSON-INDEX-NEXT:       "Path": "OuterNamespace",
+// JSON-INDEX-NEXT:       "Children": [
+// JSON-INDEX-NEXT:         {
+// JSON-INDEX-NEXT:           "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:           "Name": "InnerNamespace",
+// JSON-INDEX-NEXT:           "RefType": "namespace",
+// JSON-INDEX-NEXT:           "Path": "OuterNamespace{{[\/]+}}InnerNamespace",
+// JSON-INDEX-NEXT:           "Children": [
+// JSON-INDEX-NEXT:             {
+// JSON-INDEX-NEXT:               "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:               "Name": "Circle",
+// JSON-INDEX-NEXT:               "RefType": "record",
+// JSON-INDEX-NEXT:               "Path": "OuterNamespace{{[\/]+}}InnerNamespace",
+// JSON-INDEX-NEXT:               "Children": []
+// JSON-INDEX-NEXT:             },
+// JSON-INDEX-NEXT:             {
+// JSON-INDEX-NEXT:               "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:               "Name": "Shape",
+// JSON-INDEX-NEXT:               "RefType": "record",
+// JSON-INDEX-NEXT:               "Path": "OuterNamespace{{[\/]+}}InnerNamespace",
+// JSON-INDEX-NEXT:               "Children": []
+// JSON-INDEX-NEXT:             }
+// JSON-INDEX-NEXT:           ]
+// JSON-INDEX-NEXT:         }
+// JSON-INDEX-NEXT:       ]
+// JSON-INDEX-NEXT:     }
+// JSON-INDEX-NEXT:   ]
+// JSON-INDEX-NEXT: };
+// JSON-INDEX-NEXT: }
+
+// HTML-ANON-INDEX: <!DOCTYPE html>
+// HTML-ANON-INDEX-NEXT: <meta charset="utf-8"/>
+// HTML-ANON-INDEX-NEXT: <title>namespace @nonymous_namespace</title>
+// HTML-ANON-INDEX-NEXT: <link rel="stylesheet" href="..{{[\/]}}clang-doc-default-stylesheet.css"/>
+// HTML-ANON-INDEX-NEXT: <script src="..{{[\/]}}index_json.js"></script>
+// HTML-ANON-INDEX-NEXT: <script src="..{{[\/]}}index.js"></script>
+// HTML-ANON-INDEX-NEXT: <header id="project-title"></header>
+// HTML-ANON-INDEX-NEXT: <main>
+// HTML-ANON-INDEX-NEXT:   <div id="sidebar-left" path="@nonymous_namespace" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left"></div>
+// HTML-ANON-INDEX-NEXT:   <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
+// HTML-ANON-INDEX-NEXT:     <h1>namespace @nonymous_namespace</h1>
+// HTML-ANON-INDEX-NEXT:     <div>
+// HTML-ANON-INDEX-NEXT:       <div>
+// HTML-ANON-INDEX-NEXT:         <p> Anonymous namespace for utility functions</p>
+// HTML-ANON-INDEX-NEXT:       </div>
+// HTML-ANON-INDEX-NEXT:     </div>
+// HTML-ANON-INDEX-NEXT:     <h2 id="Functions">Functions</h2>
+// HTML-ANON-INDEX-NEXT:     <div>
+// HTML-ANON-INDEX-NEXT:       <h3 id="{{([0-9A-F]{40})}}">getRandomNumber</h3>
+// HTML-ANON-INDEX-NEXT:       <p>int getRandomNumber()</p>
+// HTML-ANON-INDEX-NEXT:       <p>Defined at line 9 of file .{{[\/]}}src{{[\/]}}Utils.cpp</p>
+// HTML-ANON-INDEX-NEXT:       <div>
+// HTML-ANON-INDEX-NEXT:         <div></div>
+// HTML-ANON-INDEX-NEXT:         <div>
+// HTML-ANON-INDEX-NEXT:           <p> This function returns a predetermined number to simulate randomness. In a real implementation, this would use a proper random number generator</p>
+// HTML-ANON-INDEX-NEXT:         </div>
+// HTML-ANON-INDEX-NEXT:       </div>
+// HTML-ANON-INDEX-NEXT:       <h3 id="{{([0-9A-F]{40})}}">intToString</h3>
+// HTML-ANON-INDEX-NEXT:       <p>void intToString(int value, char * buffer, int & index)</p>
+// HTML-ANON-INDEX-NEXT:       <p>Defined at line 18 of file .{{[\/]}}src{{[\/]}}Utils.cpp</p>
+// HTML-ANON-INDEX-NEXT:       <div>
+// HTML-ANON-INDEX-NEXT:         <div></div>
+// HTML-ANON-INDEX-NEXT:         <div>
+// HTML-ANON-INDEX-NEXT:           <p> Converts an integer value to its string representation and stores the result in the provided buffer.</p>
+// HTML-ANON-INDEX-NEXT:         </div>
+// HTML-ANON-INDEX-NEXT:       </div>
+// HTML-ANON-INDEX-NEXT:       <h3 id="{{([0-9A-F]{40})}}">doubleToString</h3>
+// HTML-ANON-INDEX-NEXT:       <p>void doubleToString(double value, char * buffer, int & index)</p>
+// HTML-ANON-INDEX-NEXT:       <p>Defined at line 26 of file .{{[\/]}}src{{[\/]}}Utils.cpp</p>
+// HTML-ANON-INDEX-NEXT:       <div>
+// HTML-ANON-INDEX-NEXT:         <div></div>
+// HTML-ANON-INDEX-NEXT:         <div>
+// HTML-ANON-INDEX-NEXT:           <p> Converts a double value to its string representation with two decimal places and stores the result in the provided buffer.</p>
+// HTML-ANON-INDEX-NEXT:         </div>
+// HTML-ANON-INDEX-NEXT:       </div>
+// HTML-ANON-INDEX-NEXT:       <h3 id="{{([0-9A-F]{40})}}">print</h3>
+// HTML-ANON-INDEX-NEXT:       <p>void print(const char * str)</p>
+// HTML-ANON-INDEX-NEXT:       <p>Defined at line 33 of file .{{[\/]}}src{{[\/]}}Utils.cpp</p>
+// HTML-ANON-INDEX-NEXT:       <div>
+// HTML-ANON-INDEX-NEXT:         <div></div>
+// HTML-ANON-INDEX-NEXT:         <div>
+// HTML-ANON-INDEX-NEXT:           <p> Prints the provided null-terminated string to the standard output.</p>
+// HTML-ANON-INDEX-NEXT:         </div>
+// HTML-ANON-INDEX-NEXT:       </div>
+// HTML-ANON-INDEX-NEXT:     </div>
+// HTML-ANON-INDEX-NEXT:   </div>
+// HTML-ANON-INDEX-NEXT:   <div id="sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
+// HTML-ANON-INDEX-NEXT:     <ol>
+// HTML-ANON-INDEX-NEXT:       <li>
+// HTML-ANON-INDEX-NEXT:         <span>
+// HTML-ANON-INDEX-NEXT:           <a href="#Functions">Functions</a>
+// HTML-ANON-INDEX-NEXT:         </span>
+// HTML-ANON-INDEX-NEXT:         <ul>
+// HTML-ANON-INDEX-NEXT:           <li>
+// HTML-ANON-INDEX-NEXT:             <span>
+// HTML-ANON-INDEX-NEXT:               <a href="#{{([0-9A-F]{40})}}">getRandomNumber</a>
+// HTML-ANON-INDEX-NEXT:             </span>
+// HTML-ANON-INDEX-NEXT:           </li>
+// HTML-ANON-INDEX-NEXT:           <li>
+// HTML-ANON-INDEX-NEXT:             <span>
+// HTML-ANON-INDEX-NEXT:               <a href="#{{([0-9A-F]{40})}}">intToString</a>
+// HTML-ANON-INDEX-NEXT:             </span>
+// HTML-ANON-INDEX-NEXT:           </li>
+// HTML-ANON-INDEX-NEXT:           <li>
+// HTML-ANON-INDEX-NEXT:             <span>
+// HTML-ANON-INDEX-NEXT:               <a href="#{{([0-9A-F]{40})}}">doubleToString</a>
+// HTML-ANON-INDEX-NEXT:             </span>
+// HTML-ANON-INDEX-NEXT:           </li>
+// HTML-ANON-INDEX-NEXT:           <li>
+// HTML-ANON-INDEX-NEXT:             <span>
+// HTML-ANON-INDEX-NEXT:               <a href="#{{([0-9A-F]{40})}}">print</a>
+// HTML-ANON-INDEX-NEXT:             </span>
+// HTML-ANON-INDEX-NEXT:           </li>
+// HTML-ANON-INDEX-NEXT:         </ul>
+// HTML-ANON-INDEX-NEXT:       </li>
+// HTML-ANON-INDEX-NEXT:     </ol>
+// HTML-ANON-INDEX-NEXT:   </div>
+// HTML-ANON-INDEX-NEXT: </main>
----------------
ilovepi wrote:

I'm starting to wonder how much value there is in matching all of the HTML, more ore less exactly. Do you think it makes sense to limit the checking to only particular lines, and omit much of the boiler plate/tag matching?

So, I'm thinking maybe you can only match certain lines, like ` <a href="#Functions">Functions</a>` in line 145, w/o matching the `<span></span>` bits. WDYT? does that sound like a more useful check.

I think we probably want 1-2 tests that have the full HTML, but we can choose those to be smaller examples.

I've also, been thinking about moving some of the checks into the source files, but then they aren't really Input anymore, so that's probably not a great option for the project files. Still, for standalone test files, its probably a good option.

https://github.com/llvm/llvm-project/pull/97518


More information about the cfe-commits mailing list