Skip to content

Commit

Permalink
quicklog(tests): simple macro failure cases
Browse files Browse the repository at this point in the history
  • Loading branch information
thog92 committed Feb 29, 2024
1 parent fa4dc10 commit 6f11d63
Show file tree
Hide file tree
Showing 23 changed files with 266 additions and 13 deletions.
2 changes: 1 addition & 1 deletion quicklog/tests/closure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use quicklog::info;

use crate::common::Something;
use common::Something;

mod common;

Expand Down
21 changes: 16 additions & 5 deletions quicklog/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl A {
}
}

#[derive(Clone)]
pub(crate) struct SerializeStruct {
pub(crate) symbol: String,
}
Expand Down Expand Up @@ -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<String> = 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()))
};
}

Expand All @@ -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();
Expand All @@ -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) };
}
2 changes: 1 addition & 1 deletion quicklog/tests/eager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use quicklog::info;

use crate::common::Something;
use common::Something;

mod common;

Expand Down
13 changes: 13 additions & 0 deletions quicklog/tests/failures/assigned_prefixed_arg_after_fmt_str.rs
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
| ^
13 changes: 13 additions & 0 deletions quicklog/tests/failures/prefixed_arg_after_fmt_str.rs
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions quicklog/tests/failures/prefixed_arg_after_fmt_str.stderr
Original file line number Diff line number Diff line change
@@ -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);
| ^
13 changes: 13 additions & 0 deletions quicklog/tests/failures/struct_missing_clone.rs
Original file line number Diff line number Diff line change
@@ -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");
}
24 changes: 24 additions & 0 deletions quicklog/tests/failures/struct_missing_clone.stderr
Original file line number Diff line number Diff line change
@@ -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)]
|
13 changes: 13 additions & 0 deletions quicklog/tests/failures/struct_missing_debug.rs
Original file line number Diff line number Diff line change
@@ -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");
}
34 changes: 34 additions & 0 deletions quicklog/tests/failures/struct_missing_debug.stderr
Original file line number Diff line number Diff line change
@@ -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)]
|
13 changes: 13 additions & 0 deletions quicklog/tests/failures/struct_missing_display.rs
Original file line number Diff line number Diff line change
@@ -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");
}
49 changes: 49 additions & 0 deletions quicklog/tests/failures/struct_missing_display.stderr
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 13 additions & 0 deletions quicklog/tests/failures/struct_missing_serialize.rs
Original file line number Diff line number Diff line change
@@ -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");
}
34 changes: 34 additions & 0 deletions quicklog/tests/failures/struct_missing_serialize.stderr
Original file line number Diff line number Diff line change
@@ -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)]
|
5 changes: 5 additions & 0 deletions quicklog/tests/failures/trailing_comma.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use quicklog::info;

fn main() {
info!("trailing comma",);
}
7 changes: 7 additions & 0 deletions quicklog/tests/failures/trailing_comma.stderr
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions quicklog/tests/fields.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use quicklog::info;

use crate::common::{NestedSomething, Something};
use common::{NestedSomething, Something};

mod common;

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion quicklog/tests/function.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use quicklog::info;

use crate::common::{Something, A};
use common::{Something, A};

mod common;

Expand Down
2 changes: 1 addition & 1 deletion quicklog/tests/move.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use quicklog::info;

use crate::common::Something;
use common::Something;

mod common;

Expand Down
2 changes: 1 addition & 1 deletion quicklog/tests/reference.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use quicklog::info;

use crate::common::Something;
use common::Something;

mod common;

Expand Down
2 changes: 1 addition & 1 deletion quicklog/tests/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use quicklog::info;

use crate::common::{BigStruct, SerializeStruct};
use common::{BigStruct, SerializeStruct};

mod common;

Expand Down
1 change: 1 addition & 0 deletions quicklog/tests/ui.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down

0 comments on commit 6f11d63

Please sign in to comment.