-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[clang-doc] add enum test #97679
Conversation
@llvm/pr-subscribers-clang-tools-extra Author: None (PeterChou1) ChangesThis 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:
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
|
Red, // Red enums | ||
Green, // Green enums | ||
Blue // Blue enums |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
// RUN: clang-doc --format=html --doxygen --output=%t/docs --executor=standalone %s | ||
// RUN: clang-doc --format=md --doxygen --output=%t/docs --executor=standalone %s |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
e5494dc
to
cd98a8c
Compare
a3a6fac
to
517bb21
Compare
/** | ||
* @brief Shape Types | ||
*/ | ||
enum Shapes { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
* @brief specify type of car | ||
*/ | ||
enum Car { | ||
Sedan, // Sedan |
There was a problem hiding this comment.
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.
ec796d6
to
0912ebc
Compare
0912ebc
to
f756c39
Compare
There was a problem hiding this 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.
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra newlines
// MD-INDEX: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE+13]]* | ||
// MD-INDEX: **brief** For specifying RGB colors |
There was a problem hiding this comment.
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?
This patch adds a test which test the enum generation for clang-doc.
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
This patch adds a test which test the enum generation for clang-doc.