-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Generating a documentation for tests #130463
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -341,6 +341,7 @@ struct AllTypes { | |
attribute_macros: FxIndexSet<ItemEntry>, | ||
derive_macros: FxIndexSet<ItemEntry>, | ||
trait_aliases: FxIndexSet<ItemEntry>, | ||
tests: FxIndexSet<ItemEntry>, | ||
} | ||
|
||
impl AllTypes { | ||
|
@@ -360,6 +361,7 @@ impl AllTypes { | |
attribute_macros: new_set(100), | ||
derive_macros: new_set(100), | ||
trait_aliases: new_set(100), | ||
tests: new_set(100), | ||
} | ||
} | ||
|
||
|
@@ -385,6 +387,7 @@ impl AllTypes { | |
} | ||
ItemType::ProcDerive => self.derive_macros.insert(ItemEntry::new(new_url, name)), | ||
ItemType::TraitAlias => self.trait_aliases.insert(ItemEntry::new(new_url, name)), | ||
ItemType::Test => self.tests.insert(ItemEntry::new(new_url, name)), | ||
_ => true, | ||
}; | ||
} | ||
|
@@ -414,6 +417,9 @@ impl AllTypes { | |
if !self.functions.is_empty() { | ||
sections.insert(ItemSection::Functions); | ||
} | ||
if !self.tests.is_empty() { | ||
ifxfrancois marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sections.insert(ItemSection::Tests); | ||
} | ||
if !self.type_aliases.is_empty() { | ||
sections.insert(ItemSection::TypeAliases); | ||
} | ||
|
@@ -432,6 +438,9 @@ impl AllTypes { | |
if !self.trait_aliases.is_empty() { | ||
sections.insert(ItemSection::TraitAliases); | ||
} | ||
if !self.tests.is_empty() { | ||
sections.insert(ItemSection::Tests); | ||
} | ||
|
||
sections | ||
} | ||
|
@@ -468,6 +477,7 @@ impl AllTypes { | |
print_entries(f, &self.attribute_macros, ItemSection::AttributeMacros); | ||
print_entries(f, &self.derive_macros, ItemSection::DeriveMacros); | ||
print_entries(f, &self.functions, ItemSection::Functions); | ||
print_entries(f, &self.tests, ItemSection::Tests); | ||
print_entries(f, &self.type_aliases, ItemSection::TypeAliases); | ||
print_entries(f, &self.trait_aliases, ItemSection::TraitAliases); | ||
print_entries(f, &self.statics, ItemSection::Statics); | ||
|
@@ -2227,6 +2237,7 @@ pub(crate) enum ItemSection { | |
Statics, | ||
Traits, | ||
Functions, | ||
Tests, | ||
TypeAliases, | ||
Unions, | ||
Implementations, | ||
|
@@ -2259,6 +2270,7 @@ impl ItemSection { | |
Statics, | ||
Traits, | ||
Functions, | ||
Tests, | ||
TypeAliases, | ||
Unions, | ||
Implementations, | ||
|
@@ -2284,6 +2296,7 @@ impl ItemSection { | |
Self::Unions => "unions", | ||
Self::Enums => "enums", | ||
Self::Functions => "functions", | ||
Self::Tests => "tests", | ||
Self::TypeAliases => "types", | ||
Self::Statics => "statics", | ||
Self::Constants => "constants", | ||
|
@@ -2313,6 +2326,7 @@ impl ItemSection { | |
Self::Unions => "Unions", | ||
Self::Enums => "Enums", | ||
Self::Functions => "Functions", | ||
Self::Tests => "Tests", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "Unit tests" instead? Same above. |
||
Self::TypeAliases => "Type Aliases", | ||
Self::Statics => "Statics", | ||
Self::Constants => "Constants", | ||
|
@@ -2343,6 +2357,7 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection { | |
ItemType::Union => ItemSection::Unions, | ||
ItemType::Enum => ItemSection::Enums, | ||
ItemType::Function => ItemSection::Functions, | ||
ItemType::Test => ItemSection::Tests, | ||
ItemType::TypeAlias => ItemSection::TypeAliases, | ||
ItemType::Static => ItemSection::Statics, | ||
ItemType::Constant => ItemSection::Constants, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,7 @@ pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buf | |
} | ||
} | ||
clean::FunctionItem(..) | clean::ForeignFunctionItem(..) => "Function ", | ||
clean::TestItem(..) => "Test ", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GuillaumeGomez We also want to call this documentation build on integration tests. If we change this to "Unit Test", the integration tests will also appear as Unit tests. |
||
clean::TraitItem(..) => "Trait ", | ||
clean::StructItem(..) => "Struct ", | ||
clean::UnionItem(..) => "Union ", | ||
|
@@ -254,9 +255,9 @@ pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buf | |
|
||
match &item.kind { | ||
clean::ModuleItem(ref m) => item_module(buf, cx, item, &m.items), | ||
clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f, _) => { | ||
item_function(buf, cx, item, f) | ||
} | ||
clean::FunctionItem(ref f) | ||
| clean::ForeignFunctionItem(ref f, _) | ||
| clean::TestItem(ref f) => item_function(buf, cx, item, f), | ||
clean::TraitItem(ref t) => item_trait(buf, cx, item, t), | ||
clean::StructItem(ref s) => item_struct(buf, cx, item, s), | ||
clean::UnionItem(ref s) => item_union(buf, cx, item, s), | ||
|
@@ -332,6 +333,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: | |
ItemType::Static => 8, | ||
ItemType::Trait => 9, | ||
ItemType::Function => 10, | ||
ItemType::Test => 11, | ||
ItemType::TypeAlias => 12, | ||
ItemType::Union => 13, | ||
_ => 14 + ty as u8, | ||
|
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.
Modelling a
#[test] fn
as a distinctItemKind
seems a bit strange:#[test] fn
s are still function items, I wonder if you can distinguish non-#[test]
fns versus#[test]
fns by looking at the existence/absence of the#[test]
attribute.But yeah, rendering docs for tests do seem useful. Though a question that immediately comes to my mind is that do test-affiliated module docs get rendered too? As in e.g. docs on
#[cfg(test)] mod tests;
. I would think that they do, but I haven't looked closely if they do in this implementation.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.
Yes, they are rendered in this implementation though they are most likely not
pub
therefore the additional flag--document-private-items
may be needed.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 agree with @jieyouxu, but also I like this difference as it makes it simpler to know what's being manipulated... I suppose it's fine as is for now. :)
Another approach could be to add a bool value saying whether or not it's a test function.
As for
cfg
ed out items, unfortunately you will need to pass--cfg test
to have them (alongside--document-private-items
).