Skip to content

[clang-doc] add nested namespace test case #97681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 16, 2024

Conversation

PeterChou1
Copy link
Contributor

This patch adds a test to clang-doc which test the nested namespace generation of clang-doc

@llvmbot
Copy link
Member

llvmbot commented Jul 4, 2024

@llvm/pr-subscribers-clang-tools-extra

Author: None (PeterChou1)

Changes

This patch adds a test to clang-doc which test the nested namespace generation of clang-doc


Full diff: https://github.com/llvm/llvm-project/pull/97681.diff

1 Files Affected:

  • (added) clang-tools-extra/test/clang-doc/namespace.cpp (+340)
diff --git a/clang-tools-extra/test/clang-doc/namespace.cpp b/clang-tools-extra/test/clang-doc/namespace.cpp
new file mode 100644
index 0000000000000..6fb91c9aa3c51
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/namespace.cpp
@@ -0,0 +1,340 @@
+// RUN: clang-doc --format=html --output=%t/docs --executor=standalone %s
+// RUN: clang-doc --format=md --output=%t/docs --executor=standalone %s
+// RUN: FileCheck %s -input-file=%t/docs/index_json.js -check-prefix=JSON-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/@nonymous_namespace/AnonClass.html -check-prefix=HTML-ANON-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/@nonymous_namespace/index.html -check-prefix=HTML-ANON-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/AnotherNamespace/ClassInAnotherNamespace.html -check-prefix=HTML-ANOTHER-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/AnotherNamespace/index.html -check-prefix=HTML-ANOTHER-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.html -check-prefix=HTML-GLOBAL-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/PrimaryNamespace/NestedNamespace/ClassInNestedNamespace.html -check-prefix=HTML-NESTED-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/PrimaryNamespace/NestedNamespace/index.html -check-prefix=HTML-NESTED-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/PrimaryNamespace/index.html -check-prefix=HTML-PRIMARY-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/PrimaryNamespace/ClassInPrimaryNamespace.html -check-prefix=HTML-PRIMARY-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/@nonymous_namespace/AnonClass.md -check-prefix=MD-ANON-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/@nonymous_namespace/index.md -check-prefix=MD-ANON-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/AnotherNamespace/ClassInAnotherNamespace.md -check-prefix=MD-ANOTHER-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/AnotherNamespace/index.md -check-prefix=MD-ANOTHER-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.md -check-prefix=MD-GLOBAL-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/PrimaryNamespace/NestedNamespace/ClassInNestedNamespace.md -check-prefix=MD-NESTED-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/PrimaryNamespace/NestedNamespace/index.md -check-prefix=MD-NESTED-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/PrimaryNamespace/index.md -check-prefix=MD-PRIMARY-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/PrimaryNamespace/ClassInPrimaryNamespace.md -check-prefix=MD-PRIMARY-CLASS
+// 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
+
+// Anonymous Namespace
+namespace
+{
+    void anonFunction() {}
+    class AnonClass {};
+}
+
+// Primary Namespace
+namespace PrimaryNamespace {
+    // Function in PrimaryNamespace
+    void functionInPrimaryNamespace() {}
+
+    // Class in PrimaryNamespace
+    class ClassInPrimaryNamespace {};
+
+    // Nested namespace
+    namespace NestedNamespace {
+        // Function in NestedNamespace
+        void functionInNestedNamespace() {}
+        // Class in NestedNamespace
+        class ClassInNestedNamespace {};
+    }
+}
+
+// AnotherNamespace
+namespace AnotherNamespace {
+    // Function in AnotherNamespace
+    void functionInAnotherNamespace() {}
+    // Class in AnotherNamespace
+    class ClassInAnotherNamespace {};
+}
+
+// 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:           "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:           "Name": "AnonClass",
+// JSON-INDEX-NEXT:           "RefType": "record",
+// JSON-INDEX-NEXT:           "Path": "@nonymous_namespace",
+// 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": "AnotherNamespace",
+// JSON-INDEX-NEXT:       "RefType": "namespace",
+// JSON-INDEX-NEXT:       "Path": "AnotherNamespace",
+// JSON-INDEX-NEXT:       "Children": [
+// JSON-INDEX-NEXT:         {
+// JSON-INDEX-NEXT:           "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:           "Name": "ClassInAnotherNamespace",
+// JSON-INDEX-NEXT:           "RefType": "record",
+// JSON-INDEX-NEXT:           "Path": "AnotherNamespace",
+// 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": "GlobalNamespace",
+// JSON-INDEX-NEXT:       "RefType": "namespace",
+// JSON-INDEX-NEXT:       "Path": "GlobalNamespace",
+// JSON-INDEX-NEXT:       "Children": []
+// JSON-INDEX-NEXT:     },
+// JSON-INDEX-NEXT:     {
+// JSON-INDEX-NEXT:       "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:       "Name": "PrimaryNamespace",
+// JSON-INDEX-NEXT:       "RefType": "namespace",
+// JSON-INDEX-NEXT:       "Path": "PrimaryNamespace",
+// JSON-INDEX-NEXT:       "Children": [
+// JSON-INDEX-NEXT:         {
+// JSON-INDEX-NEXT:           "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:           "Name": "ClassInPrimaryNamespace",
+// JSON-INDEX-NEXT:           "RefType": "record",
+// JSON-INDEX-NEXT:           "Path": "PrimaryNamespace",
+// JSON-INDEX-NEXT:           "Children": []
+// JSON-INDEX-NEXT:         },
+// JSON-INDEX-NEXT:         {
+// JSON-INDEX-NEXT:           "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:           "Name": "NestedNamespace",
+// JSON-INDEX-NEXT:           "RefType": "namespace",
+// JSON-INDEX-NEXT:           "Path": "PrimaryNamespace{{[\/]+}}NestedNamespace",
+// JSON-INDEX-NEXT:           "Children": [
+// JSON-INDEX-NEXT:             {
+// JSON-INDEX-NEXT:               "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT:               "Name": "ClassInNestedNamespace",
+// JSON-INDEX-NEXT:               "RefType": "record",
+// JSON-INDEX-NEXT:               "Path": "PrimaryNamespace{{[\/]+}}NestedNamespace",
+// 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-CLASS: <h1>class AnonClass</h1>
+// HTML-ANON-CLASS: <p>Defined at line 31 of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+
+// HTML-ANON-INDEX: <h1>namespace @nonymous_namespace</h1>
+// HTML-ANON-INDEX: <div>
+// HTML-ANON-INDEX:   <div>
+// HTML-ANON-INDEX:    <p> Anonymous Namespace</p>
+// HTML-ANON-INDEX:   </div>
+// HTML-ANON-INDEX: </div>
+// HTML-ANON-INDEX: <h2 id="Records">Records</h2>
+// HTML-ANON-INDEX: <ul>
+// HTML-ANON-INDEX:   <li>
+// HTML-ANON-INDEX:     <a href="AnonClass.html">AnonClass</a>
+// HTML-ANON-INDEX:   </li>
+// HTML-ANON-INDEX: </ul>
+// HTML-ANON-INDEX: <h2 id="Functions">Functions</h2>
+// HTML-ANON-INDEX: <div>
+// HTML-ANON-INDEX:   <h3 id="{{([0-9A-F]{40})}}">anonFunction</h3>
+// HTML-ANON-INDEX:   <p>void anonFunction()</p>
+// HTML-ANON-INDEX:   <p>Defined at line 30 of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-ANON-INDEX: </div>
+
+// HTML-ANOTHER-CLASS: <h1>class ClassInAnotherNamespace</h1>
+// HTML-ANOTHER-CLASS: <p>Defined at line 56 of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-ANOTHER-CLASS: <div>
+// HTML-ANOTHER-CLASS:   <div>
+// HTML-ANOTHER-CLASS:     <p> Class in AnotherNamespace</p>
+// HTML-ANOTHER-CLASS:   </div>
+// HTML-ANOTHER-CLASS: </div>
+
+// HTML-ANOTHER-INDEX: <h1>namespace AnotherNamespace</h1>
+// HTML-ANOTHER-INDEX: <div>
+// HTML-ANOTHER-INDEX:   <div>
+// HTML-ANOTHER-INDEX:     <p> AnotherNamespace</p>
+// HTML-ANOTHER-INDEX:   </div>
+// HTML-ANOTHER-INDEX: </div>
+// HTML-ANOTHER-INDEX: <h2 id="Records">Records</h2>
+// HTML-ANOTHER-INDEX: <ul>
+// HTML-ANOTHER-INDEX:   <li>
+// HTML-ANOTHER-INDEX:     <a href="ClassInAnotherNamespace.html">ClassInAnotherNamespace</a>
+// HTML-ANOTHER-INDEX:   </li>
+// HTML-ANOTHER-INDEX: </ul>
+// HTML-ANOTHER-INDEX: <h2 id="Functions">Functions</h2>
+// HTML-ANOTHER-INDEX: <div>
+// HTML-ANOTHER-INDEX:   <h3 id="{{([0-9A-F]{40})}}">functionInAnotherNamespace</h3>
+// HTML-ANOTHER-INDEX:   <p>void functionInAnotherNamespace()</p>
+// HTML-ANOTHER-INDEX:   <p>Defined at line 54 of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-ANOTHER-INDEX:   <div>
+// HTML-ANOTHER-INDEX:     <div>
+// HTML-ANOTHER-INDEX:       <p> Function in AnotherNamespace</p>
+// HTML-ANOTHER-INDEX:     </div>
+// HTML-ANOTHER-INDEX:   </div>
+// HTML-ANOTHER-INDEX: </div>
+
+// HTML-GLOBAL-INDEX: <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
+// HTML-GLOBAL-INDEX:   <h1>Global Namespace</h1>
+// HTML-GLOBAL-INDEX:   <h2 id="Namespaces">Namespaces</h2>
+// HTML-GLOBAL-INDEX:   <ul>
+// HTML-GLOBAL-INDEX:     <li>@nonymous_namespace</li>
+// HTML-GLOBAL-INDEX:     <li>PrimaryNamespace</li>
+// HTML-GLOBAL-INDEX:     <li>AnotherNamespace</li>
+// HTML-GLOBAL-INDEX:   </ul>
+// HTML-GLOBAL-INDEX: </div>
+
+// HTML-NESTED-CLASS: <h1>class ClassInNestedNamespace</h1>
+// HTML-NESTED-CLASS: <p>Defined at line 47 of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-NESTED-CLASS: <div>
+// HTML-NESTED-CLASS:   <div>
+// HTML-NESTED-CLASS:     <p> Class in NestedNamespace</p>
+// HTML-NESTED-CLASS:   </div>
+// HTML-NESTED-CLASS: </div>
+
+// HTML-NESTED-INDEX: <h1>namespace NestedNamespace</h1>
+// HTML-NESTED-INDEX: <div>
+// HTML-NESTED-INDEX:   <div>
+// HTML-NESTED-INDEX:     <p> Nested namespace</p>
+// HTML-NESTED-INDEX:   </div>
+// HTML-NESTED-INDEX: </div>
+// HTML-NESTED-INDEX: <h2 id="Records">Records</h2>
+// HTML-NESTED-INDEX: <ul>
+// HTML-NESTED-INDEX:   <li>
+// HTML-NESTED-INDEX:     <a href="ClassInNestedNamespace.html">ClassInNestedNamespace</a>
+// HTML-NESTED-INDEX:   </li>
+// HTML-NESTED-INDEX: </ul>
+// HTML-NESTED-INDEX: <h2 id="Functions">Functions</h2>
+// HTML-NESTED-INDEX: <div>
+// HTML-NESTED-INDEX:   <h3 id="{{([0-9A-F]{40})}}">functionInNestedNamespace</h3>
+// HTML-NESTED-INDEX:   <p>void functionInNestedNamespace()</p>
+// HTML-NESTED-INDEX:   <p>Defined at line 45 of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-NESTED-INDEX:   <div>
+// HTML-NESTED-INDEX:     <div>
+// HTML-NESTED-INDEX:       <p> Function in NestedNamespace</p>
+// HTML-NESTED-INDEX:     </div>
+// HTML-NESTED-INDEX:   </div>
+// HTML-NESTED-INDEX: </div>
+
+// HTML-PRIMARY-CLASS:  <h1>class ClassInPrimaryNamespace</h1>
+// HTML-PRIMARY-CLASS:  <p>Defined at line 40 of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-PRIMARY-CLASS:  <div>
+// HTML-PRIMARY-CLASS:    <div>
+// HTML-PRIMARY-CLASS:      <p> Class in PrimaryNamespace</p>
+// HTML-PRIMARY-CLASS:    </div>
+// HTML-PRIMARY-CLASS:  </div>
+
+// HTML-PRIMARY-INDEX: <h1>namespace PrimaryNamespace</h1>
+// HTML-PRIMARY-INDEX: <div>
+// HTML-PRIMARY-INDEX:   <div>
+// HTML-PRIMARY-INDEX:     <p> Primary Namespace</p>
+// HTML-PRIMARY-INDEX:   </div>
+// HTML-PRIMARY-INDEX: </div>
+// HTML-PRIMARY-INDEX: <h2 id="Namespaces">Namespaces</h2>
+// HTML-PRIMARY-INDEX: <ul>
+// HTML-PRIMARY-INDEX:   <li>
+// HTML-PRIMARY-INDEX:     <a href="NestedNamespace{{[\/]}}index.html">NestedNamespace</a>
+// HTML-PRIMARY-INDEX:   </li>
+// HTML-PRIMARY-INDEX: </ul>
+// HTML-PRIMARY-INDEX: <h2 id="Records">Records</h2>
+// HTML-PRIMARY-INDEX: <ul>
+// HTML-PRIMARY-INDEX:   <li>
+// HTML-PRIMARY-INDEX:     <a href="ClassInPrimaryNamespace.html">ClassInPrimaryNamespace</a>
+// HTML-PRIMARY-INDEX:   </li>
+// HTML-PRIMARY-INDEX: </ul>
+// HTML-PRIMARY-INDEX: <h2 id="Functions">Functions</h2>
+// HTML-PRIMARY-INDEX: <div>
+// HTML-PRIMARY-INDEX:   <h3 id="{{([0-9A-F]{40})}}">functionInPrimaryNamespace</h3>
+// HTML-PRIMARY-INDEX:   <p>void functionInPrimaryNamespace()</p>
+// HTML-PRIMARY-INDEX:   <p>Defined at line 37 of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-PRIMARY-INDEX:   <div>
+// HTML-PRIMARY-INDEX:     <div>
+// HTML-PRIMARY-INDEX:       <p> Function in PrimaryNamespace</p>
+// HTML-PRIMARY-INDEX:     </div>
+// HTML-PRIMARY-INDEX:   </div>
+// HTML-PRIMARY-INDEX: </div>
+
+// MD-ANON-CLASS: # class AnonClass
+// MD-ANON-CLASS: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#31*
+
+// MD-ANON-INDEX: # namespace @nonymous_namespace
+// MD-ANON-INDEX:  Anonymous Namespace
+// MD-ANON-INDEX: ## Records
+// MD-ANON-INDEX: * [AnonClass](AnonClass.md)
+// MD-ANON-INDEX: ## Functions
+// MD-ANON-INDEX: ### anonFunction
+// MD-ANON-INDEX: *void anonFunction()*
+// MD-ANON-INDEX: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#30*
+
+// MD-ANOTHER-CLASS: # class ClassInAnotherNamespace
+// MD-ANOTHER-CLASS: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#56*
+// MD-ANOTHER-CLASS:  Class in AnotherNamespace
+
+// MD-ANOTHER-INDEX: # namespace AnotherNamespace
+// MD-ANOTHER-INDEX: AnotherNamespace
+// MD-ANOTHER-INDEX: ## Records
+// MD-ANOTHER-INDEX: * [ClassInAnotherNamespace](ClassInAnotherNamespace.md)
+// MD-ANOTHER-INDEX: ## Functions
+// MD-ANOTHER-INDEX: ### functionInAnotherNamespace
+// MD-ANOTHER-INDEX: *void functionInAnotherNamespace()*
+// MD-ANOTHER-INDEX: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#54*
+// MD-ANOTHER-INDEX: Function in AnotherNamespace
+
+// MD-GLOBAL-INDEX: # Global Namespace
+// MD-GLOBAL-INDEX: ## Namespaces
+// MD-GLOBAL-INDEX: * [@nonymous_namespace](..{{[\/]}}@nonymous_namespace{{[\/]}}index.md)
+// MD-GLOBAL-INDEX: * [PrimaryNamespace](..{{[\/]}}PrimaryNamespace{{[\/]}}index.md)
+// MD-GLOBAL-INDEX: * [AnotherNamespace](..{{[\/]}}AnotherNamespace{{[\/]}}index.md)
+
+// MD-NESTED-CLASS: # class ClassInNestedNamespace
+// MD-NESTED-CLASS: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#47*
+// MD-NESTED-CLASS: Class in NestedNamespace
+
+// MD-NESTED-INDEX: # namespace NestedNamespace
+// MD-NESTED-INDEX: Nested namespace
+// MD-NESTED-INDEX: ## Records
+// MD-NESTED-INDEX: * [ClassInNestedNamespace](ClassInNestedNamespace.md)
+// MD-NESTED-INDEX: ## Functions
+// MD-NESTED-INDEX: ### functionInNestedNamespace
+// MD-NESTED-INDEX: *void functionInNestedNamespace()*
+// MD-NESTED-INDEX: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#45*
+// MD-NESTED-INDEX: Function in NestedNamespace
+
+// MD-PRIMARY-CLASS: # class ClassInPrimaryNamespace
+// MD-PRIMARY-CLASS: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#40*
+// MD-PRIMARY-CLASS: Class in PrimaryNamespace
+
+// MD-PRIMARY-INDEX: # namespace PrimaryNamespace
+// MD-PRIMARY-INDEX:  Primary Namespace
+// MD-PRIMARY-INDEX: ## Namespaces
+// MD-PRIMARY-INDEX: * [NestedNamespace](NestedNamespace{{[\/]}}index.md)
+// MD-PRIMARY-INDEX: ## Records
+// MD-PRIMARY-INDEX: * [ClassInPrimaryNamespace](ClassInPrimaryNamespace.md)
+// MD-PRIMARY-INDEX: ## Functions
+// MD-PRIMARY-INDEX: ### functionInPrimaryNamespace
+// MD-PRIMARY-INDEX: *void functionInPrimaryNamespace()*
+// MD-PRIMARY-INDEX: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#37*
+// MD-PRIMARY-INDEX:  Function in PrimaryNamespace
+
+// MD-ALL-FILES: # All Files
+// MD-ALL-FILES: ## [@nonymous_namespace](@nonymous_namespace{{[\/]}}index.md)
+// MD-ALL-FILES: ## [AnotherNamespace](AnotherNamespace{{[\/]}}index.md)
+// MD-ALL-FILES: ## [GlobalNamespace](GlobalNamespace{{[\/]}}index.md)
+// MD-ALL-FILES: ## [PrimaryNamespace](PrimaryNamespace{{[\/]}}index.md)
+
+// MD-INDEX: #  C/C++ Reference
+// MD-INDEX: * Namespace: [@nonymous_namespace](@nonymous_namespace)
+// MD-INDEX: * Namespace: [AnotherNamespace](AnotherNamespace)
+// MD-INDEX: * Namespace: [PrimaryNamespace](PrimaryNamespace)
\ No newline at end of file

@PeterChou1 PeterChou1 requested review from ilovepi and petrhosek July 4, 2024 06:54
@PeterChou1 PeterChou1 requested a review from ilovepi July 12, 2024 10:50
Copy link
Contributor

@ilovepi ilovepi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this mostly looks good, but I am concerned with the line number matching. It appears that whenever you’ve up’s the file you’ve had to update all the line numbers.

Is it feasible to rewrite some of the checks to use the “LINE” directive? Perhaps it also makes sense to move those checks close to the lines they expect to match? Another thought is to leave the test as is, but drop the line numbers(or just match any number) and have a small set of check in line with the code that checks the line numbers with the LINE directive and uses a new prefix.

https://llvm.org/docs/CommandGuide/FileCheck.html#filecheck-pseudo-numeric-variables

@PeterChou1
Copy link
Contributor Author

I think this mostly looks good, but I am concerned with the line number matching. It appears that whenever you’ve up’s the file you’ve had to update all the line numbers.

Is it feasible to rewrite some of the checks to use the “LINE” directive? Perhaps it also makes sense to move those checks close to the lines they expect to match? Another thought is to leave the test as is, but drop the line numbers(or just match any number) and have a small set of check in line with the code that checks the line numbers with the LINE directive and uses a new prefix.

https://llvm.org/docs/CommandGuide/FileCheck.html#filecheck-pseudo-numeric-variables

I don't think this possible since the line directive matches the line of the html or md file you pipe into FileCheck, which is different from the line that's define in the source code. I've opted for just matching any number to make the test case less brittle

@ilovepi
Copy link
Contributor

ilovepi commented Jul 15, 2024

I don't think this possible since the line directive matches the line of the html or md file you pipe into FileCheck, which is different from the line that's define in the source code. I've opted for just matching any number to make the test case less brittle

I’m not sure I follow. The LINE directive should work fine regardless of what output you’re checking. It should match the current line that the check is on, so if you do something like LINE-1 with the check right after the thing you’re trying to match, it should work fine. If you look at tests in Clang, LLVM , or compiler-rt you should find plenty of examples demonstrating the typical usage.

// JSON-INDEX-NEXT: }

// HTML-ANON-CLASS: <h1>class AnonClass</h1>
// HTML-ANON-CLASS: <p>Defined at line {{.*}} of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.* will match anything, not just any number. I think [[#]] will work, as suggested in your other PR.

@ilovepi
Copy link
Contributor

ilovepi commented Jul 15, 2024

To clarify my earlier comment, FileCheck is just matching text on the input based on the check lines. So in this cases the LINE directive should just affect what text will be accepted when doin matching. It won’t try to match the lines to the position in the file being checked.

If you run into problems, post the errors here, as we can probably help diagnose them.

@PeterChou1
Copy link
Contributor Author

PeterChou1 commented Jul 15, 2024

To clarify my earlier comment, FileCheck is just matching text on the input based on the check lines. So in this cases the LINE directive should just affect what text will be accepted when doin matching. It won’t try to match the lines to the position in the file being checked.

If you run into problems, post the errors here, as we can probably help diagnose them.

My bad I think I was mistaken in how the @line directive worked initially I think i fixed up the pr so that it works with it now
I also switched up the location for the checks, I tried to but every generated output ontop of the declaration that way its more readable

Copy link
Contributor

@ilovepi ilovepi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, once the LINE checks are in a more stable position w/ their own prefixes, and a couple of nits on whitespace.

// HTML-ANON-INDEX: <h2 id="Functions">Functions</h2>
// HTML-ANON-INDEX: <h3 id="{{([0-9A-F]{40})}}">anonFunction</h3>
// HTML-ANON-INDEX: <p>void anonFunction()</p>
// HTML-ANON-INDEX: <p>Defined at line [[@LINE+6]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in your other PR, lets check these right after the line they're checking, and use a *-LINE tag to check these w/ --check-prefixes. That should prevent instability in the test due to more test checks getting added. Once that's done for all these tests, this will probably be good to go, modulo some nits.

// Anonymous Namespace
namespace
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra newline.

@PeterChou1 PeterChou1 merged commit c461058 into llvm:main Jul 16, 2024
7 checks passed
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary:
This patch adds a test to clang-doc which test the nested namespace
generation of clang-doc

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251608
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants