1
Fork 0

Move /src/test to /tests

This commit is contained in:
Albert Larsan 2023-01-05 09:13:28 +01:00
parent ca855e6e42
commit cf2dff2b1e
No known key found for this signature in database
GPG key ID: 92709B88BB8F13EA
27592 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,41 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass
//! Make sure to have some docs on your crate root
#[allow(missing_docs)]
pub mod mod_foo {
pub struct Bar;
}
/// This is a struct with an `#[allow(missing_docs)]`
pub struct AllowTheMissingDocs {
#[allow(missing_docs)]
pub empty_str: String,
/// This has
#[allow(missing_docs)]
/// but also has documentation comments
pub hello: usize,
/// The doc id just to create a boilerplate comment
pub doc_id: Vec<u8>,
}
/// A function that has a documentation
pub fn this_is_func() {}
#[allow(missing_docs)]
pub struct DemoStruct {
something: usize,
}
#[allow(missing_docs)]
pub mod bar {
#[warn(missing_docs)]
pub struct Bar { //~ WARN
pub f: u32, //~ WARN
}
pub struct NeedsNoDocs;
}

View file

@ -0,0 +1,20 @@
warning: missing documentation for a struct
--> $DIR/allow_missing_docs.rs:36:5
|
LL | pub struct Bar {
| ^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/allow_missing_docs.rs:35:12
|
LL | #[warn(missing_docs)]
| ^^^^^^^^^^^^
warning: missing documentation for a struct field
--> $DIR/allow_missing_docs.rs:37:9
|
LL | pub f: u32,
| ^^^^^^^^^^
warning: 2 warnings emitted

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...i/coverage/allow_missing_docs.rs | 5 | 71.4% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 5 | 71.4% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+

View file

@ -0,0 +1,50 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass
#![feature(extern_types)]
//! Make sure to have some docs on your crate root
/// This struct is documented, but its fields are not.
///
/// However, one field is private, so it shouldn't show in the total.
pub struct SomeStruct {
pub some_field: usize,
other_field: usize,
}
impl SomeStruct {
/// Method with docs
pub fn this_fn(&self) {}
// Method without docs
pub fn other_method(&self) {}
}
// struct without docs
pub struct OtherStruct;
// function with no docs
pub fn some_fn() {}
/// Function with docs
pub fn other_fn() {}
pub enum SomeEnum {
/// Some of these variants are documented...
VarOne,
/// ...but some of them are not.
VarTwo,
// (like this one)
VarThree,
}
/// There's a macro here, too
#[macro_export]
macro_rules! some_macro {
() => {};
}
extern "C" {
pub type ExternType;
}

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...est/rustdoc-ui/coverage/basic.rs | 7 | 50.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 7 | 50.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+

View file

@ -0,0 +1,13 @@
// check-pass
// compile-flags:-Z unstable-options --output-format json --show-coverage
// This check ensures that only one doc example is counted since they're "optional" on
// certain items.
/// ```
/// let x = 12;
/// ```
pub const Foo: u32 = 0;
/// doc
pub const Bar: u32 = 0;

View file

@ -0,0 +1 @@
{"$DIR/doc-examples-json.rs":{"total":3,"with_docs":2,"total_examples":2,"with_examples":1}}

View file

@ -0,0 +1,27 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass
//! This test ensure that only rust code examples are counted.
/// Doc
///
/// ```
/// let x = 2;
/// ```
pub struct Foo;
/// Doc
///
/// ```text
/// yolo
/// ```
pub trait Bar {}
/// Doc
///
/// ```ignore (just for the sake of this test)
/// let x = 2;
/// ```
pub fn foo<T: Bar, D: ::std::fmt::Debug>(a: Foo, b: u32, c: T, d: D) -> u32 {
0
}

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...tdoc-ui/coverage/doc-examples.rs | 4 | 100.0% | 1 | 25.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 4 | 100.0% | 1 | 25.0% |
+-------------------------------------+------------+------------+------------+------------+

View file

@ -0,0 +1,4 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass
// an empty crate still has one item to document: the crate root

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...est/rustdoc-ui/coverage/empty.rs | 0 | 0.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 0 | 0.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+

View file

@ -0,0 +1,37 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass
// The point of this test is to ensure that the number of "documented" items
// is higher than in `enum-tuple.rs`.
//! (remember the crate root is still a module)
/// so check out this enum here
pub enum ThisEnum {
/// VarOne.
VarOne(
/// hello!
String,
),
/// Var Two.
VarTwo(
/// Hello
String,
/// Bis repetita.
String,
),
}
/// Struct.
pub struct ThisStruct(
/// hello
u32,
);
/// Struct.
pub struct ThisStruct2(
/// hello
u32,
/// Bis repetita.
u8,
);

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...overage/enum-tuple-documented.rs | 9 | 100.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 9 | 100.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+

View file

@ -0,0 +1,18 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass
//! (remember the crate root is still a module)
/// so check out this enum here
pub enum ThisEnum {
/// No need to document the field if there is only one in a tuple variant!
VarOne(String),
/// But if there is more than one... still fine!
VarTwo(String, String),
}
/// Struct.
pub struct ThisStruct(u32);
/// Struct.
pub struct ThisStruct2(u32, u8);

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...ustdoc-ui/coverage/enum-tuple.rs | 6 | 100.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 6 | 100.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+

View file

@ -0,0 +1,22 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass
//! (remember the crate root is still a module)
/// so check out this enum here
pub enum ThisEnum {
/// this variant has some weird stuff going on
VarOne {
/// like, it has some named fields inside
field_one: usize,
// (these show up as struct fields)
field_two: usize,
},
/// here's another variant for you
VarTwo(String),
// but not all of them need to be documented as thoroughly
VarThree,
}
/// uninhabited enums? sure, let's throw one of those around
pub enum OtherEnum {}

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...est/rustdoc-ui/coverage/enums.rs | 6 | 75.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 6 | 75.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+

View file

@ -0,0 +1,15 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass
#![feature(rustdoc_internals)]
//! the features only used in std also have entries in the table, so make sure those get pulled out
//! properly as well
/// woo, check it out, we can write our own primitive docs lol
#[doc(primitive="unit")]
mod prim_unit {}
/// keywords? sure, pile them on
#[doc(keyword="where")]
mod where_keyword {}

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...st/rustdoc-ui/coverage/exotic.rs | 3 | 100.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 3 | 100.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+

View file

@ -0,0 +1,4 @@
// compile-flags:-Z unstable-options --output-format html --show-coverage
/// Foo
pub struct Xo;

View file

@ -0,0 +1,2 @@
error: html output format isn't supported for the --show-coverage option

View file

@ -0,0 +1,65 @@
// check-pass
// compile-flags:-Z unstable-options --output-format json --show-coverage
pub mod foo {
/// Hello!
pub struct Foo;
/// Bar
pub enum Bar { A }
}
/// X
pub struct X;
/// Bar
///
/// ```
/// let x = 12;
/// ```
pub mod bar {
/// bar
pub struct Bar;
/// X
pub enum X {
/// ```
/// let x = "should be ignored!";
/// ```
Y
}
}
/// yolo
///
/// ```text
/// should not be counted as a code example!
/// ```
pub enum Yolo { X }
impl Yolo {
/// ```
/// let x = "should be ignored!";
/// ```
pub const Const: u32 = 0;
}
pub struct Xo<T: Clone> {
/// ```
/// let x = "should be ignored!";
/// ```
x: T,
}
/// ```
/// let x = "should be ignored!";
/// ```
pub static StaticFoo: u32 = 0;
/// ```
/// let x = "should be ignored!";
/// ```
pub const ConstFoo: u32 = 0;
/// ```
/// let x = "should be ignored!";
/// ```
pub type TypeFoo = u32;

View file

@ -0,0 +1 @@
{"$DIR/json.rs":{"total":17,"with_docs":12,"total_examples":15,"with_examples":6}}

View file

@ -0,0 +1,21 @@
// compile-flags:-Z unstable-options --show-coverage --document-private-items
// check-pass
#![allow(unused)]
//! when `--document-private-items` is passed, nothing is safe. everything must have docs or your
//! score will suffer the consequences
mod this_mod {
fn private_fn() {}
}
/// See, our public items have docs!
pub struct SomeStruct {
/// Look, all perfectly documented!
pub field: usize,
other: usize,
}
/// Nothing shady going on here. Just a bunch of well-documented code. (cough)
pub fn public_fn() {}

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...t/rustdoc-ui/coverage/private.rs | 4 | 57.1% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 4 | 57.1% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+

View file

@ -0,0 +1,23 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass
//! gotta make sure we can count statics and consts correctly, too
/// static like electricity, right?
pub static THIS_STATIC: usize = 0;
/// (it's not electricity, is it)
pub const THIS_CONST: usize = 1;
/// associated consts show up separately, but let's throw them in as well
pub trait SomeTrait {
/// just like that, yeah
const ASSOC_CONST: usize;
}
pub struct SomeStruct;
impl SomeStruct {
/// wait, structs can have them too, can't forget those
pub const ASSOC_CONST: usize = 100;
}

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...oc-ui/coverage/statics-consts.rs | 6 | 85.7% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 6 | 85.7% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+

View file

@ -0,0 +1,38 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass
#![feature(trait_alias)]
#![feature(type_alias_impl_trait)]
/// look at this trait right here
pub trait ThisTrait {
/// that's a trait all right
fn right_here(&self);
/// even the provided functions show up as trait methods
fn aww_yeah(&self) {}
/// gotta check those associated types, they're slippery
type SomeType;
}
/// so what happens if we take some struct...
#[derive(Clone)]
pub struct SomeStruct;
/// ...and slap this trait on it?
impl ThisTrait for SomeStruct {
/// nothing! trait impls are totally ignored in this calculation, sorry.
fn right_here(&self) {}
type SomeType = String;
}
/// but what about those aliases? i hear they're pretty exotic
pub trait MyAlias = ThisTrait + Send + Sync;
/// woah, getting all opaque in here
pub type ThisExists = impl ThisTrait;
/// why don't we get a little more concrete
pub fn defines() -> ThisExists { SomeStruct {} }

View file

@ -0,0 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...st/rustdoc-ui/coverage/traits.rs | 8 | 88.9% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 8 | 88.9% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+