Skip to content
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

[clang-doc] add enum test #97679

Merged
merged 6 commits into from
Jul 16, 2024
Merged

Conversation

PeterChou1
Copy link
Contributor

This patch adds a test which test the enum generation for clang-doc.

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 4, 2024

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

Author: None (PeterChou1)

Changes

This patch adds a test which test the enum generation for clang-doc.


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

1 Files Affected:

  • (added) clang-tools-extra/test/clang-doc/enum.cpp (+38)
diff --git a/clang-tools-extra/test/clang-doc/enum.cpp b/clang-tools-extra/test/clang-doc/enum.cpp
new file mode 100644
index 0000000000000..2f25eaf4e44e2
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/enum.cpp
@@ -0,0 +1,38 @@
+// RUN: clang-doc --format=html --doxygen --output=%t/docs --executor=standalone %s
+// RUN: clang-doc --format=md --doxygen --output=%t/docs --executor=standalone %s
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.html -check-prefix=HTML-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.md -check-prefix=MD-INDEX
+
+/**
+ * @brief For specifying RGB colors
+ */
+enum Color {
+  Red, // Red enums
+  Green, // Green enums
+  Blue // Blue enums
+};
+
+// HTML-INDEX: <h1>Global Namespace</h1>
+// HTML-INDEX: <h2 id="Enums">Enums</h2>
+// HTML-INDEX: <div>
+// HTML-INDEX:   <h3 id="{{([0-9A-F]{40})}}">enum Color</h3>
+// HTML-INDEX:   <ul>
+// HTML-INDEX:     <li>Red</li>
+// HTML-INDEX:     <li>Green</li>
+// HTML-INDEX:     <li>Blue</li>
+// HTML-INDEX:   </ul>
+// HTML-INDEX:   <p>Defined at line 11 of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
+// HTML-INDEX:   <div>
+// HTML-INDEX:     <div></div>
+// HTML-INDEX:   </div>
+// HTML-INDEX: </div>
+
+// MD-INDEX: # Global Namespace
+// MD-INDEX: ## Enums
+// MD-INDEX: | enum Color |
+// MD-INDEX: --
+// MD-INDEX: | Red |
+// MD-INDEX: | Green |
+// MD-INDEX: | Blue |
+// MD-INDEX: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#11*
+// MD-INDEX: **brief** For specifying RGB colors
\ No newline at end of file

Comment on lines 10 to 12
Red, // Red enums
Green, // Green enums
Blue // Blue enums
Copy link
Contributor

Choose a reason for hiding this comment

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

should these be doc comments?

Copy link
Contributor

Choose a reason for hiding this comment

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

These seem to be gone now, but isn’t it common to document the enum values? I know we do that in several places in LLVM.

Thinking about other cases, it probably also worth having an “enum class”, an enum within a class, and one in a namespace. I’d suggest also varying in at least one case where the doc comments are: e.g., above the value vs on the same line.

Comment on lines 1 to 2
// RUN: clang-doc --format=html --doxygen --output=%t/docs --executor=standalone %s
// RUN: clang-doc --format=md --doxygen --output=%t/docs --executor=standalone %s
Copy link
Contributor

Choose a reason for hiding this comment

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

This can't work right, can it? you haven't made %t, you also don't need docs, right? It would be good if I didn't have to point these out in every patch... I've given this piece of feedback in almost all of your patches.

Copy link
Contributor Author

@PeterChou1 PeterChou1 Jul 12, 2024

Choose a reason for hiding this comment

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

sorry I've realize originally that we didn't need to explicitly mkdir but its probably better to specify it

clang-tools-extra/test/clang-doc/enum.cpp Outdated Show resolved Hide resolved
@PeterChou1 PeterChou1 requested a review from ilovepi July 12, 2024 11:04
@PeterChou1 PeterChou1 force-pushed the clang-doc-add-enum-test branch 2 times, most recently from a3a6fac to 517bb21 Compare July 15, 2024 09:07
/**
* @brief Shape Types
*/
enum Shapes {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this can be ‘enum class’? We already have a normal enum above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not know that enum classes were a thing, I thought you meant enum embedded in a class, I've update the code

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, those cases are distinct, so its good to have both.

clang-tools-extra/test/clang-doc/enum.cpp Outdated Show resolved Hide resolved
* @brief specify type of car
*/
enum Car {
Sedan, // Sedan
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn’t these be documentation comments? So using /// or the doxygen style comments?

My earlier point was that in LLVM and other projects, there are often documentation comments attached the the enum entries. It would be good to test that. If it doesn’t work, we can add a TODO and a tracking bug on GitHub.

@PeterChou1 PeterChou1 force-pushed the clang-doc-add-enum-test branch 2 times, most recently from ec796d6 to 0912ebc Compare July 15, 2024 22:00
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, modulo some nits. I do think you may want to have a separate prefix for the lines, but if you change --check-prefix= to --check-prefixes=HTML-ANIMAL,HTML-ANIMAL-LINE, you should be able to check them w/o having to rewrite everything. Plus keeping the LINE comments right after the source line makes it a lot easier to keep the tests stable.

Comment on lines +10 to +11


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 newlines

Comment on lines 20 to 21
// MD-INDEX: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE+13]]*
// MD-INDEX: **brief** For specifying RGB colors
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a lot better, but maybe its better to move this and the HTML line check below the LINE you want to check and then do

enum Color {
// MD-INDEX: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
// HTML-INDEX: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>

Any remaining checks can go below the class, or these line checks could be MD-INDEX-LINE & HTML-INDEX-LINE, and you can list 2 prefixes to check, then only the 2 line checks would be out of order w/ the rest. WDYT?

@PeterChou1 PeterChou1 merged commit eab3738 into llvm:main Jul 16, 2024
7 checks passed
sgundapa pushed a commit to sgundapa/upstream_effort that referenced this pull request Jul 23, 2024
This patch adds a test which test the enum generation for clang-doc.
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary: This patch adds a test which test the enum generation for clang-doc.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250871
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