Skip to content

Commit

Permalink
remove #[cfg(any(test, trybuild))] from generated codes
Browse files Browse the repository at this point in the history
... at least until rust-lang/rust#45599 is resolved.
  • Loading branch information
ubnt-intrepid committed Apr 8, 2020
1 parent 50bcd3c commit d541f32
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 35 deletions.
2 changes: 0 additions & 2 deletions crates/rye-macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ impl ToTokens for Generated<'_> {
let test_case_id = quote::format_ident!("__TEST_CASE_{}", ident);

tokens.append_all(Some(quote! {
#[cfg(any(test, trybuild))]
#[allow(non_upper_case_globals)]
const #ident: & #crate_path::_test_reexports::TestCase = {
#[allow(unused_imports)]
Expand All @@ -387,7 +386,6 @@ impl ToTokens for Generated<'_> {
}));

tokens.append_all(Some(quote! {
#[cfg(any(test, trybuild))]
#crate_path::__test_case! {
#[allow(non_upper_case_globals)]
static #test_case_id: & #crate_path::_test_reexports::TestCase = #ident;
Expand Down
1 change: 0 additions & 1 deletion crates/rye-macros/src/test_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ pub(crate) fn test_main(_args: TokenStream, item: TokenStream) -> TokenStream {
// TODO: add type check.

quote! {
#[cfg(any(test, trybuild))]
#[export_name = "__rye_test_main"]
fn #ident(test_cases: #crate_path::_test_main_reexports::TestCases) {
#[allow(unused_imports)]
Expand Down
2 changes: 0 additions & 2 deletions crates/rye-macros/tests/test/01-sync.out.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(any(test, trybuild))]
#[allow(non_upper_case_globals)]
const case_sync: & ::rye::_test_reexports::TestCase = {
#[allow(unused_imports)]
Expand Down Expand Up @@ -28,7 +27,6 @@ const case_sync: & ::rye::_test_reexports::TestCase = {
}
};

#[cfg(any(test, trybuild))]
::rye::__test_case! {
#[allow(non_upper_case_globals)]
static __TEST_CASE_case_sync: & ::rye::_test_reexports::TestCase = case_sync;
Expand Down
2 changes: 0 additions & 2 deletions crates/rye-macros/tests/test/02-sync-nested.out.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(any(test, trybuild))]
#[allow(non_upper_case_globals)]
const case_sync_nested: & ::rye::_test_reexports::TestCase = {
#[allow(unused_imports)]
Expand Down Expand Up @@ -34,7 +33,6 @@ const case_sync_nested: & ::rye::_test_reexports::TestCase = {
}
};

#[cfg(any(test, trybuild))]
::rye::__test_case! {
#[allow(non_upper_case_globals)]
static __TEST_CASE_case_sync_nested: & ::rye::_test_reexports::TestCase = case_sync_nested;
Expand Down
2 changes: 0 additions & 2 deletions crates/rye-macros/tests/test/03-async.out.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(any(test, trybuild))]
#[allow(non_upper_case_globals)]
const case_async: & ::rye::_test_reexports::TestCase = {
#[allow(unused_imports)]
Expand Down Expand Up @@ -28,7 +27,6 @@ const case_async: & ::rye::_test_reexports::TestCase = {
}
};

#[cfg(any(test, trybuild))]
::rye::__test_case! {
#[allow(non_upper_case_globals)]
static __TEST_CASE_case_async: & ::rye::_test_reexports::TestCase = case_async;
Expand Down
2 changes: 0 additions & 2 deletions crates/rye-macros/tests/test/04-async-nested.out.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(any(test, trybuild))]
#[allow(non_upper_case_globals)]
const case_async_nested: & ::rye::_test_reexports::TestCase = {
#[allow(unused_imports)]
Expand Down Expand Up @@ -34,7 +33,6 @@ const case_async_nested: & ::rye::_test_reexports::TestCase = {
}
};

#[cfg(any(test, trybuild))]
::rye::__test_case! {
#[allow(non_upper_case_globals)]
static __TEST_CASE_case_async_nested: & ::rye::_test_reexports::TestCase = case_async_nested;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(any(test, trybuild))]
#[allow(non_upper_case_globals)]
const multi_section_in_scope: & ::rye::_test_reexports::TestCase = {
#[allow(unused_imports)]
Expand Down Expand Up @@ -47,7 +46,6 @@ const multi_section_in_scope: & ::rye::_test_reexports::TestCase = {
}
};

#[cfg(any(test, trybuild))]
::rye::__test_case! {
#[allow(non_upper_case_globals)]
static __TEST_CASE_multi_section_in_scope: & ::rye::_test_reexports::TestCase = multi_section_in_scope;
Expand Down
2 changes: 0 additions & 2 deletions crates/rye-macros/tests/test/06-ignore-inner-items.out.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(any(test, trybuild))]
#[allow(non_upper_case_globals)]
const ignore_inner_items: & ::rye::_test_reexports::TestCase = {
#[allow(unused_imports)]
Expand All @@ -24,7 +23,6 @@ const ignore_inner_items: & ::rye::_test_reexports::TestCase = {
}
};

#[cfg(any(test, trybuild))]
::rye::__test_case! {
#[allow(non_upper_case_globals)]
static __TEST_CASE_ignore_inner_items: & ::rye::_test_reexports::TestCase = ignore_inner_items;
Expand Down
2 changes: 0 additions & 2 deletions crates/rye-macros/tests/test/07-no-sections.out.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(any(test, trybuild))]
#[allow(non_upper_case_globals)]
const no_sections: & ::rye::_test_reexports::TestCase = {
#[allow(unused_imports)]
Expand All @@ -18,7 +17,6 @@ const no_sections: & ::rye::_test_reexports::TestCase = {
}
};

#[cfg(any(test, trybuild))]
::rye::__test_case! {
#[allow(non_upper_case_globals)]
static __TEST_CASE_no_sections: & ::rye::_test_reexports::TestCase = no_sections;
Expand Down
2 changes: 0 additions & 2 deletions crates/rye-macros/tests/test/08-attributes.out.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(any(test, trybuild))]
#[allow(non_upper_case_globals)]
const attributes: & path::to::rye::_test_reexports::TestCase = {
#[allow(unused_imports)]
Expand Down Expand Up @@ -33,7 +32,6 @@ const attributes: & path::to::rye::_test_reexports::TestCase = {
}
};

#[cfg(any(test, trybuild))]
path::to::rye::__test_case! {
#[allow(non_upper_case_globals)]
static __TEST_CASE_attributes: & path::to::rye::_test_reexports::TestCase = attributes;
Expand Down
2 changes: 0 additions & 2 deletions crates/rye-macros/tests/test/09-return-result.out.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(any(test, trybuild))]
#[allow(non_upper_case_globals)]
const return_result: & ::rye::_test_reexports::TestCase = {
#[allow(unused_imports)]
Expand All @@ -23,7 +22,6 @@ const return_result: & ::rye::_test_reexports::TestCase = {
}
};

#[cfg(any(test, trybuild))]
::rye::__test_case! {
#[allow(non_upper_case_globals)]
static __TEST_CASE_return_result: & ::rye::_test_reexports::TestCase = return_result;
Expand Down
1 change: 1 addition & 0 deletions docs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ path = "doctest.rs"

[dev-dependencies]
rye = { path = "../crates/rye" }
anyhow = "1"
doc-comment = "0.3"
4 changes: 2 additions & 2 deletions docs/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

use doc_comment::doc_comment;

doc_comment!(include_str!("src/section.md"));
doc_comment!(include_str!("src/test_case.md"));
doc_comment!(include_str!("src/section.md"), pub mod section {});
doc_comment!(include_str!("src/test_case.md"), pub mod test_case {});
6 changes: 3 additions & 3 deletions docs/src/section.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ test case:
```rust
# fn main() {}
#[rye::test]
fn has_multi_section() {
fn has_multi_section(cx: &mut rye::Context<'_>) {
println!("startup");

section!("section 1", {
section!(cx, "section 1", {
println!("section 1");
});

section!("section 2", {
section!(cx, "section 2", {
println!("section 2");
});

Expand Down
31 changes: 22 additions & 9 deletions docs/src/test_case.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,34 @@ The test case can be registered as a test target by applying the attribute-style

```rust
# fn main() {}
# mod inner {
#[rye::test]
fn case1() {
assert!(1 + 1 == 2);
fn case1(cx: &mut rye::Context<'_>) {
// ...
}
# }
```

The type that implements `Termination` can be specified as the output type of the
test function.

```rust
# fn main() {}
fn do_something(counter: &mut i32) -> anyhow::Result<()> {
// ...
# *counter += 1;
# Ok(())
}

#[rye::test]
fn fallible() -> std::io::Result<()> {
fn fallible(cx: &mut rye::Context<'_>) -> anyhow::Result<()> {
let mut counter = 0;

do_something(&mut counter)?;
if counter != 1 {
rye::fail!(cx, "assertion failed: counter is not incremented");
}

Ok(())
}
# fn main() {}
```

```rust,ignore
Expand All @@ -40,15 +51,17 @@ The asynchronous functions could be used in test cases.
```rust
# fn main() {}
#[rye::test]
async fn case_async() {
async fn case_async(cx: &mut rye::Context<'_>) {
let mut counter = 0usize;

async {
counter += 1;
}
.await;

assert_eq!(counter, 1);
if counter != 1 {
rye::fail!(cx, "assertion failed: count != 1");
}
}
```

Expand All @@ -61,7 +74,7 @@ the attribute `#[test]` as follows:
# use std::{cell::Cell, rc::Rc};
# fn main() {}
#[rye::test(?Send)]
async fn case_async_nosend() {
async fn case_async_nosend(cx: &mut rye::Context<'_>) {
let counter = Rc::new(Cell::new(0usize));

async {
Expand Down

0 comments on commit d541f32

Please sign in to comment.