diff --git a/quicklog/tests/closure.rs b/quicklog/tests/closure.rs index cbbc592..e3b5c03 100644 --- a/quicklog/tests/closure.rs +++ b/quicklog/tests/closure.rs @@ -1,6 +1,6 @@ use quicklog::info; -use crate::common::Something; +use common::Something; mod common; diff --git a/quicklog/tests/common/mod.rs b/quicklog/tests/common/mod.rs index 8e03324..27f8b75 100644 --- a/quicklog/tests/common/mod.rs +++ b/quicklog/tests/common/mod.rs @@ -99,6 +99,7 @@ impl A { } } +#[derive(Clone)] pub(crate) struct SerializeStruct { pub(crate) symbol: String, } @@ -153,14 +154,24 @@ impl Serialize for BigStruct { } } +pub(crate) struct SimpleStruct { + some_str: &'static str, +} + +impl std::fmt::Display for SimpleStruct { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.some_str) + } +} + #[macro_export] macro_rules! setup { () => { quicklog::init!(); static mut VEC: Vec = Vec::new(); - let vec_flusher = unsafe { crate::common::VecFlusher::new(&mut VEC) }; + let vec_flusher = unsafe { common::VecFlusher::new(&mut VEC) }; quicklog::logger().use_flush(Box::new(vec_flusher)); - quicklog::logger().use_formatter(Box::new(crate::common::TestFormatter::new())) + quicklog::logger().use_formatter(Box::new(common::TestFormatter::new())) }; } @@ -170,7 +181,7 @@ macro_rules! helper_assert { (@ $f:expr, $format_string:expr, $check_f:expr) => { $f; quicklog::flush!(); - let output = unsafe { crate::common::from_log_lines(&VEC, $check_f) }; + let output = unsafe { common::from_log_lines(&VEC, $check_f) }; assert_eq!(output, vec![$format_string]); unsafe { let _ = &VEC.clear(); @@ -180,10 +191,10 @@ macro_rules! helper_assert { #[macro_export] macro_rules! assert_message_equal { - ($f:expr, $format_string:expr) => { helper_assert!(@ $f, $format_string, crate::common::message_from_log_line) }; + ($f:expr, $format_string:expr) => { helper_assert!(@ $f, $format_string, common::message_from_log_line) }; } #[macro_export] macro_rules! assert_message_with_level_equal { - ($f:expr, $format_string:expr) => { helper_assert!(@ $f, $format_string, crate::common::message_and_level_from_log_line) }; + ($f:expr, $format_string:expr) => { helper_assert!(@ $f, $format_string, common::message_and_level_from_log_line) }; } diff --git a/quicklog/tests/eager.rs b/quicklog/tests/eager.rs index b7527e4..0103cee 100644 --- a/quicklog/tests/eager.rs +++ b/quicklog/tests/eager.rs @@ -1,6 +1,6 @@ use quicklog::info; -use crate::common::Something; +use common::Something; mod common; diff --git a/quicklog/tests/failures/assigned_prefixed_arg_after_fmt_str.rs b/quicklog/tests/failures/assigned_prefixed_arg_after_fmt_str.rs new file mode 100644 index 0000000..d983a4f --- /dev/null +++ b/quicklog/tests/failures/assigned_prefixed_arg_after_fmt_str.rs @@ -0,0 +1,13 @@ +use quicklog::info; + +#[path = "../common/mod.rs"] +mod common; + +use common::Something; + +fn main() { + let s1 = Something { + some_str: "Hello world 1", + }; + info!(a = ?s1, "prefixed arg after fmt str: {b}", b = ?s1); +} diff --git a/quicklog/tests/failures/assigned_prefixed_arg_after_fmt_str.stderr b/quicklog/tests/failures/assigned_prefixed_arg_after_fmt_str.stderr new file mode 100644 index 0000000..9565a7c --- /dev/null +++ b/quicklog/tests/failures/assigned_prefixed_arg_after_fmt_str.stderr @@ -0,0 +1,5 @@ +error: expected an expression + --> tests/failures/assigned_prefixed_arg_after_fmt_str.rs:12:59 + | +12 | info!(a = ?s1, "prefixed arg after fmt str: {b}", b = ?s1); + | ^ diff --git a/quicklog/tests/failures/prefixed_arg_after_fmt_str.rs b/quicklog/tests/failures/prefixed_arg_after_fmt_str.rs new file mode 100644 index 0000000..812fb2d --- /dev/null +++ b/quicklog/tests/failures/prefixed_arg_after_fmt_str.rs @@ -0,0 +1,13 @@ +use quicklog::info; + +#[path = "../common/mod.rs"] +mod common; + +use common::Something; + +fn main() { + let s1 = Something { + some_str: "Hello world 1", + }; + info!(a = ?s1, "prefixed arg after fmt str: {b}", ?s1); +} diff --git a/quicklog/tests/failures/prefixed_arg_after_fmt_str.stderr b/quicklog/tests/failures/prefixed_arg_after_fmt_str.stderr new file mode 100644 index 0000000..202b617 --- /dev/null +++ b/quicklog/tests/failures/prefixed_arg_after_fmt_str.stderr @@ -0,0 +1,5 @@ +error: expected an expression + --> tests/failures/prefixed_arg_after_fmt_str.rs:12:55 + | +12 | info!(a = ?s1, "prefixed arg after fmt str: {b}", ?s1); + | ^ diff --git a/quicklog/tests/failures/struct_missing_clone.rs b/quicklog/tests/failures/struct_missing_clone.rs new file mode 100644 index 0000000..230d2d3 --- /dev/null +++ b/quicklog/tests/failures/struct_missing_clone.rs @@ -0,0 +1,13 @@ +use quicklog::info; + +#[path = "../common/mod.rs"] +mod common; + +use common::SimpleStruct; + +fn main() { + let s1 = SimpleStruct { + some_str: "Hello world 1", + }; + info!(s1, "struct does not implement Clone"); +} diff --git a/quicklog/tests/failures/struct_missing_clone.stderr b/quicklog/tests/failures/struct_missing_clone.stderr new file mode 100644 index 0000000..4020145 --- /dev/null +++ b/quicklog/tests/failures/struct_missing_clone.stderr @@ -0,0 +1,24 @@ +error[E0599]: the method `to_owned` exists for struct `SimpleStruct`, but its trait bounds were not satisfied + --> tests/failures/struct_missing_clone.rs:12:5 + | +12 | info!(s1, "struct does not implement Clone"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `SimpleStruct` due to unsatisfied trait bounds + | + ::: tests/failures/../common/mod.rs + | + | pub(crate) struct SimpleStruct { + | ------------------------------ + | | + | method `to_owned` not found for this struct + | doesn't satisfy `SimpleStruct: Clone` + | doesn't satisfy `SimpleStruct: ToOwned` + | + = note: the following trait bounds were not satisfied: + `SimpleStruct: Clone` + which is required by `SimpleStruct: ToOwned` + = note: this error originates in the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `SimpleStruct` with `#[derive(Clone)]` + --> tests/failures/../common/mod.rs + | + + #[derive(Clone)] + | diff --git a/quicklog/tests/failures/struct_missing_debug.rs b/quicklog/tests/failures/struct_missing_debug.rs new file mode 100644 index 0000000..f991d2c --- /dev/null +++ b/quicklog/tests/failures/struct_missing_debug.rs @@ -0,0 +1,13 @@ +use quicklog::info; + +#[path = "../common/mod.rs"] +mod common; + +use common::SerializeStruct; + +fn main() { + let s1 = SerializeStruct { + symbol: "Hello world 1".to_string(), + }; + info!(?s1, "struct does not implement Debug"); +} diff --git a/quicklog/tests/failures/struct_missing_debug.stderr b/quicklog/tests/failures/struct_missing_debug.stderr new file mode 100644 index 0000000..0cd7ac9 --- /dev/null +++ b/quicklog/tests/failures/struct_missing_debug.stderr @@ -0,0 +1,34 @@ +error[E0277]: `SerializeStruct` doesn't implement `std::fmt::Debug` + --> tests/failures/struct_missing_debug.rs:12:5 + | +12 | info!(?s1, "struct does not implement Debug"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SerializeStruct` cannot be formatted using `{:?}` + | + = help: the trait `std::fmt::Debug` is not implemented for `SerializeStruct` + = note: add `#[derive(Debug)]` to `SerializeStruct` or manually `impl std::fmt::Debug for SerializeStruct` +note: required by a bound in `debug_check` + --> tests/failures/struct_missing_debug.rs:12:5 + | +12 | info!(?s1, "struct does not implement Debug"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `debug_check` + = note: this error originates in the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `SerializeStruct` with `#[derive(Debug)]` + --> tests/failures/../common/mod.rs + | + + #[derive(Debug)] + | + +error[E0277]: `SerializeStruct` doesn't implement `std::fmt::Debug` + --> tests/failures/struct_missing_debug.rs:12:5 + | +12 | info!(?s1, "struct does not implement Debug"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SerializeStruct` cannot be formatted using `{:?}` + | + = help: the trait `std::fmt::Debug` is not implemented for `SerializeStruct` + = note: add `#[derive(Debug)]` to `SerializeStruct` or manually `impl std::fmt::Debug for SerializeStruct` + = note: this error originates in the macro `$crate::format_args` which comes from the expansion of the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `SerializeStruct` with `#[derive(Debug)]` + --> tests/failures/../common/mod.rs + | + + #[derive(Debug)] + | diff --git a/quicklog/tests/failures/struct_missing_display.rs b/quicklog/tests/failures/struct_missing_display.rs new file mode 100644 index 0000000..2ad077e --- /dev/null +++ b/quicklog/tests/failures/struct_missing_display.rs @@ -0,0 +1,13 @@ +use quicklog::info; + +#[path = "../common/mod.rs"] +mod common; + +use common::Something; + +fn main() { + let s1 = Something { + some_str: "Hello world 1", + }; + info!(^s1, "struct does not implement Serialize"); +} diff --git a/quicklog/tests/failures/struct_missing_display.stderr b/quicklog/tests/failures/struct_missing_display.stderr new file mode 100644 index 0000000..d06924a --- /dev/null +++ b/quicklog/tests/failures/struct_missing_display.stderr @@ -0,0 +1,49 @@ +error[E0277]: the trait bound `Something: Serialize` is not satisfied + --> tests/failures/struct_missing_display.rs:12:5 + | +12 | info!(^s1, "struct does not implement Serialize"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Serialize` is not implemented for `Something` + | + = help: the following other types implement trait `Serialize`: + SerializeStruct + BigStruct +note: required by a bound in `serialize_check` + --> tests/failures/struct_missing_display.rs:12:5 + | +12 | info!(^s1, "struct does not implement Serialize"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `serialize_check` + = note: this error originates in the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0599]: no method named `encode` found for struct `Something` in the current scope + --> tests/failures/struct_missing_display.rs:12:5 + | +12 | info!(^s1, "struct does not implement Serialize"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | method not found in `Something` + | + ::: tests/failures/../common/mod.rs + | + | pub(crate) struct Something { + | --------------------------- method `encode` not found for this struct + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `encode`, perhaps you need to implement it: + candidate #1: `Serialize` + = note: this error originates in the macro `quicklog::make_store` which comes from the expansion of the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0599]: no method named `buffer_size_required` found for struct `Something` in the current scope + --> tests/failures/struct_missing_display.rs:12:5 + | +12 | info!(^s1, "struct does not implement Serialize"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `Something` + | + ::: tests/failures/../common/mod.rs + | + | pub(crate) struct Something { + | --------------------------- method `buffer_size_required` not found for this struct + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `buffer_size_required`, perhaps you need to implement it: + candidate #1: `Serialize` + = note: this error originates in the macro `quicklog::make_store` which comes from the expansion of the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/quicklog/tests/failures/struct_missing_serialize.rs b/quicklog/tests/failures/struct_missing_serialize.rs new file mode 100644 index 0000000..f991d2c --- /dev/null +++ b/quicklog/tests/failures/struct_missing_serialize.rs @@ -0,0 +1,13 @@ +use quicklog::info; + +#[path = "../common/mod.rs"] +mod common; + +use common::SerializeStruct; + +fn main() { + let s1 = SerializeStruct { + symbol: "Hello world 1".to_string(), + }; + info!(?s1, "struct does not implement Debug"); +} diff --git a/quicklog/tests/failures/struct_missing_serialize.stderr b/quicklog/tests/failures/struct_missing_serialize.stderr new file mode 100644 index 0000000..824fa8b --- /dev/null +++ b/quicklog/tests/failures/struct_missing_serialize.stderr @@ -0,0 +1,34 @@ +error[E0277]: `SerializeStruct` doesn't implement `std::fmt::Debug` + --> tests/failures/struct_missing_serialize.rs:12:5 + | +12 | info!(?s1, "struct does not implement Debug"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SerializeStruct` cannot be formatted using `{:?}` + | + = help: the trait `std::fmt::Debug` is not implemented for `SerializeStruct` + = note: add `#[derive(Debug)]` to `SerializeStruct` or manually `impl std::fmt::Debug for SerializeStruct` +note: required by a bound in `debug_check` + --> tests/failures/struct_missing_serialize.rs:12:5 + | +12 | info!(?s1, "struct does not implement Debug"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `debug_check` + = note: this error originates in the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `SerializeStruct` with `#[derive(Debug)]` + --> tests/failures/../common/mod.rs + | + + #[derive(Debug)] + | + +error[E0277]: `SerializeStruct` doesn't implement `std::fmt::Debug` + --> tests/failures/struct_missing_serialize.rs:12:5 + | +12 | info!(?s1, "struct does not implement Debug"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SerializeStruct` cannot be formatted using `{:?}` + | + = help: the trait `std::fmt::Debug` is not implemented for `SerializeStruct` + = note: add `#[derive(Debug)]` to `SerializeStruct` or manually `impl std::fmt::Debug for SerializeStruct` + = note: this error originates in the macro `$crate::format_args` which comes from the expansion of the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `SerializeStruct` with `#[derive(Debug)]` + --> tests/failures/../common/mod.rs + | + + #[derive(Debug)] + | diff --git a/quicklog/tests/failures/trailing_comma.rs b/quicklog/tests/failures/trailing_comma.rs new file mode 100644 index 0000000..4b7c892 --- /dev/null +++ b/quicklog/tests/failures/trailing_comma.rs @@ -0,0 +1,5 @@ +use quicklog::info; + +fn main() { + info!("trailing comma",); +} diff --git a/quicklog/tests/failures/trailing_comma.stderr b/quicklog/tests/failures/trailing_comma.stderr new file mode 100644 index 0000000..c2cc28b --- /dev/null +++ b/quicklog/tests/failures/trailing_comma.stderr @@ -0,0 +1,7 @@ +error: unexpected end of input, expected an expression + --> tests/failures/trailing_comma.rs:4:5 + | +4 | info!("trailing comma",); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/quicklog/tests/fields.rs b/quicklog/tests/fields.rs index b68b49a..41280ee 100644 --- a/quicklog/tests/fields.rs +++ b/quicklog/tests/fields.rs @@ -1,6 +1,6 @@ use quicklog::info; -use crate::common::{NestedSomething, Something}; +use common::{NestedSomething, Something}; mod common; @@ -48,7 +48,7 @@ fn main() { "no name field, non-nested field, nested field:" ), format!("no name field, non-nested field, nested field: s1={:?} borrow_s2_field={} some_inner_field.inner.field.inner.arg=hello world", s1, &s2) - ); + ); assert_message_equal!( info!( reuse.debug = ?s1, diff --git a/quicklog/tests/function.rs b/quicklog/tests/function.rs index 8ebd024..a9dc224 100644 --- a/quicklog/tests/function.rs +++ b/quicklog/tests/function.rs @@ -1,6 +1,6 @@ use quicklog::info; -use crate::common::{Something, A}; +use common::{Something, A}; mod common; diff --git a/quicklog/tests/move.rs b/quicklog/tests/move.rs index 0c4e37d..b5b3562 100644 --- a/quicklog/tests/move.rs +++ b/quicklog/tests/move.rs @@ -1,6 +1,6 @@ use quicklog::info; -use crate::common::Something; +use common::Something; mod common; diff --git a/quicklog/tests/reference.rs b/quicklog/tests/reference.rs index 64a2f6c..1742d3b 100644 --- a/quicklog/tests/reference.rs +++ b/quicklog/tests/reference.rs @@ -1,6 +1,6 @@ use quicklog::info; -use crate::common::Something; +use common::Something; mod common; diff --git a/quicklog/tests/serialize.rs b/quicklog/tests/serialize.rs index 4663c32..b7f920e 100644 --- a/quicklog/tests/serialize.rs +++ b/quicklog/tests/serialize.rs @@ -1,6 +1,6 @@ use quicklog::info; -use crate::common::{BigStruct, SerializeStruct}; +use common::{BigStruct, SerializeStruct}; mod common; diff --git a/quicklog/tests/ui.rs b/quicklog/tests/ui.rs index 90c1bca..2dd11ab 100644 --- a/quicklog/tests/ui.rs +++ b/quicklog/tests/ui.rs @@ -1,6 +1,7 @@ #[test] fn ui() { let t = trybuild::TestCases::new(); + t.compile_fail("tests/failures/*.rs"); t.pass("tests/literal.rs"); t.pass("tests/level.rs"); t.pass("tests/closure.rs");