From 478baa1c746025daaf196aafde20a070d6987620 Mon Sep 17 00:00:00 2001 From: michele Date: Sun, 15 Jan 2023 11:21:35 +0100 Subject: [PATCH] Fix #176 --- rstest_reuse/src/lib.rs | 1 + rstest_reuse/tests/acceptance.rs | 20 +++++++++++++++---- .../tests/resources/export_not_used.rs | 9 +++++++++ rstest_reuse/tests/resources/not_used.rs | 8 ++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 rstest_reuse/tests/resources/export_not_used.rs create mode 100644 rstest_reuse/tests/resources/not_used.rs diff --git a/rstest_reuse/src/lib.rs b/rstest_reuse/src/lib.rs index a3e2848..b4fb5fb 100644 --- a/rstest_reuse/src/lib.rs +++ b/rstest_reuse/src/lib.rs @@ -357,6 +357,7 @@ pub fn template(_args: proc_macro::TokenStream, input: proc_macro::TokenStream) } } } + #[allow(unused_imports)] pub(crate) use #macro_name as #macro_name; }); tokens.into() diff --git a/rstest_reuse/tests/acceptance.rs b/rstest_reuse/tests/acceptance.rs index aa5a324..36e157c 100644 --- a/rstest_reuse/tests/acceptance.rs +++ b/rstest_reuse/tests/acceptance.rs @@ -1,7 +1,10 @@ -use rstest_test::{assert_not_in, sanitize_name, testname, Project, Stringable, TestResults}; +use rstest_test::{ + assert_in, assert_not_in, sanitize_name, testname, Project, Stringable, TestResults, +}; use lazy_static::lazy_static; +use rstest::rstest; use std::path::{Path, PathBuf}; use temp_testdir::TempDir; @@ -50,13 +53,22 @@ fn use_before_define() { .assert(output); } -#[test] -fn not_show_any_warning() { - let (output, _) = run_test("simple_example.rs"); +#[rstest] +#[case::simple("simple_example.rs")] +#[case::export_not_used("export_not_used.rs")] +fn not_show_any_warning(#[case] path: &str) { + let (output, _) = run_test(path); assert_not_in!(output.stderr.str(), "warning:"); } +#[test] +fn should_show_warning_if_not_used_template() { + let (output, _) = run_test("not_used.rs"); + + assert_in!(output.stderr.str(), "warning:"); +} + #[test] fn in_mod() { let (output, _) = run_test("in_mod.rs"); diff --git a/rstest_reuse/tests/resources/export_not_used.rs b/rstest_reuse/tests/resources/export_not_used.rs new file mode 100644 index 0000000..b58ec19 --- /dev/null +++ b/rstest_reuse/tests/resources/export_not_used.rs @@ -0,0 +1,9 @@ +mod foo { + use rstest_reuse::template; + + #[template] + #[export] + #[rstest] + #[case("bar")] + fn not_used(#[case] s: &str) {} +} diff --git a/rstest_reuse/tests/resources/not_used.rs b/rstest_reuse/tests/resources/not_used.rs new file mode 100644 index 0000000..7fbb04d --- /dev/null +++ b/rstest_reuse/tests/resources/not_used.rs @@ -0,0 +1,8 @@ +mod foo { + use rstest_reuse::template; + + #[template] + #[rstest] + #[case("bar")] + fn not_used(#[case] s: &str) {} +}