From 3ef8ca95310be9d10e47be845f043a547abccdd2 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Tue, 15 Feb 2022 17:38:36 -0800 Subject: [PATCH 01/24] Define macro for creating trybuild tests. --- Cargo.toml | 2 ++ tests/trybuild.rs | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/trybuild.rs diff --git a/Cargo.toml b/Cargo.toml index 074a2e44..bb54b75b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,9 @@ rayon = {version = "1.5.1", optional = true} serde = {version = "1.0.133", default-features = false, features = ["alloc"], optional = true} [dev-dependencies] +rustversion = "1.0.6" serde_test = "1.0.133" +trybuild = "1.0.56" [features] # TODO: Rename this to "rayon" when namespaced dependencies are stabilized in 1.60.0. diff --git a/tests/trybuild.rs b/tests/trybuild.rs new file mode 100644 index 00000000..c27ae31c --- /dev/null +++ b/tests/trybuild.rs @@ -0,0 +1,9 @@ +macro_rules! trybuild_test { + ($test_name:ident) => { + #[test] + #[rustversion::attr(not(nightly), ignore)] + fn $test_name() { + trybuild::TestCases::new().compile_fail(concat!("tests/trybuild/", stringify!($test_name), "/*.rs")); + } + } +} From 91f4173c41364c5674c356c76d046780885f93e7 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Tue, 15 Feb 2022 17:39:27 -0800 Subject: [PATCH 02/24] Trybuild tests for entities macro. --- tests/trybuild.rs | 2 ++ tests/trybuild/entities/component_order.rs | 9 +++++++++ tests/trybuild/entities/component_order.stderr | 11 +++++++++++ tests/trybuild/entities/same_components.rs | 10 ++++++++++ tests/trybuild/entities/same_components.stderr | 5 +++++ 5 files changed, 37 insertions(+) create mode 100644 tests/trybuild/entities/component_order.rs create mode 100644 tests/trybuild/entities/component_order.stderr create mode 100644 tests/trybuild/entities/same_components.rs create mode 100644 tests/trybuild/entities/same_components.stderr diff --git a/tests/trybuild.rs b/tests/trybuild.rs index c27ae31c..2d4ac6c0 100644 --- a/tests/trybuild.rs +++ b/tests/trybuild.rs @@ -7,3 +7,5 @@ macro_rules! trybuild_test { } } } + +trybuild_test!(entities); diff --git a/tests/trybuild/entities/component_order.rs b/tests/trybuild/entities/component_order.rs new file mode 100644 index 00000000..67b1a12a --- /dev/null +++ b/tests/trybuild/entities/component_order.rs @@ -0,0 +1,9 @@ +use brood::entities; + +// Define components. +struct A; +struct B; + +fn main () { + let entities = entities!((A, B), (B, A)); +} diff --git a/tests/trybuild/entities/component_order.stderr b/tests/trybuild/entities/component_order.stderr new file mode 100644 index 00000000..aa1531e2 --- /dev/null +++ b/tests/trybuild/entities/component_order.stderr @@ -0,0 +1,11 @@ +error[E0308]: mismatched types + --> tests/trybuild/entities/component_order.rs:8:39 + | +8 | let entities = entities!((A, B), (B, A)); + | ^ expected struct `A`, found struct `B` + +error[E0308]: mismatched types + --> tests/trybuild/entities/component_order.rs:8:42 + | +8 | let entities = entities!((A, B), (B, A)); + | ^ expected struct `B`, found struct `A` diff --git a/tests/trybuild/entities/same_components.rs b/tests/trybuild/entities/same_components.rs new file mode 100644 index 00000000..57897352 --- /dev/null +++ b/tests/trybuild/entities/same_components.rs @@ -0,0 +1,10 @@ +use brood::entities; + +// Define components. +struct A; +struct B; +struct C; + +fn main () { + let entities = entities!((A, B), (A, C)); +} diff --git a/tests/trybuild/entities/same_components.stderr b/tests/trybuild/entities/same_components.stderr new file mode 100644 index 00000000..7b3223db --- /dev/null +++ b/tests/trybuild/entities/same_components.stderr @@ -0,0 +1,5 @@ +error[E0308]: mismatched types + --> tests/trybuild/entities/same_components.rs:9:42 + | +9 | let entities = entities!((A, B), (A, C)); + | ^ expected struct `B`, found struct `C` From a14efb8aeed9c0f627db1683fc57f2e0213fd966 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Tue, 15 Feb 2022 17:40:49 -0800 Subject: [PATCH 03/24] Trybuild test and fix for incorrect stages commands. --- src/lib.rs | 1 + src/macro.rs | 16 ++++++++++++++++ src/system/schedule/stage/mod.rs | 5 ++++- tests/trybuild.rs | 2 ++ tests/trybuild/stages/unexpected_command.rs | 7 +++++++ tests/trybuild/stages/unexpected_command.stderr | 5 +++++ 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/macro.rs create mode 100644 tests/trybuild/stages/unexpected_command.rs create mode 100644 tests/trybuild/stages/unexpected_command.stderr diff --git a/src/lib.rs b/src/lib.rs index 8a56195b..47a0eaa6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ mod archetype; mod archetypes; mod doc; mod hlist; +mod r#macro; #[doc(inline)] pub use world::World; diff --git a/src/macro.rs b/src/macro.rs new file mode 100644 index 00000000..668f1d50 --- /dev/null +++ b/src/macro.rs @@ -0,0 +1,16 @@ +//! Helper macros specifically for use by other macros within this crate. +//! +//! Although the macros here are exported publicly, it is only for use by other macros within this +//! crate. These should not be depended upon by any external code, and are not considered a part of +//! the public API. + +/// Indicate that the given tokens were unexpected. +/// +/// Calling this macro with any tokens will return an error pointing to those tokens within the +/// original macro. This allows more precise error messages from macros when input is not formatted +/// correctly. +#[macro_export] +#[doc(hidden)] +macro_rules! unexpected { + () => {}; +} diff --git a/src/system/schedule/stage/mod.rs b/src/system/schedule/stage/mod.rs index ebdaa4ff..ec925424 100644 --- a/src/system/schedule/stage/mod.rs +++ b/src/system/schedule/stage/mod.rs @@ -127,8 +127,11 @@ doc::non_root_macro! { (internal @ $processed:ty; flush, $($idents:tt $(: $systems:tt)?),* $(,)?) => ( stages!(internal @ ($crate::system::schedule::stage::Stage<$crate::system::Null, $crate::system::Null>, $processed); $($idents $(: $systems)?,)*) ); - (internal @ $processed:ty; $($idents:tt $(: $systems:tt)?),* $(,)?) => ( + (internal @ $processed:ty;) => ( $processed ); + (internal @ $processed:ty; $ident:tt $(: $system:tt)?, $($idents:tt $(: $systems:tt)?),* $(,)?) => ( + $crate::unexpected!($ident $(: $system:tt)?) + ); } } diff --git a/tests/trybuild.rs b/tests/trybuild.rs index 2d4ac6c0..ee4fecf3 100644 --- a/tests/trybuild.rs +++ b/tests/trybuild.rs @@ -9,3 +9,5 @@ macro_rules! trybuild_test { } trybuild_test!(entities); +#[cfg(feature = "parallel")] +trybuild_test!(stages); diff --git a/tests/trybuild/stages/unexpected_command.rs b/tests/trybuild/stages/unexpected_command.rs new file mode 100644 index 00000000..15b96c37 --- /dev/null +++ b/tests/trybuild/stages/unexpected_command.rs @@ -0,0 +1,7 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + unexpected, +}; + +fn main() {} diff --git a/tests/trybuild/stages/unexpected_command.stderr b/tests/trybuild/stages/unexpected_command.stderr new file mode 100644 index 00000000..313a581a --- /dev/null +++ b/tests/trybuild/stages/unexpected_command.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `unexpected` + --> tests/trybuild/stages/unexpected_command.rs:4:5 + | +4 | unexpected, + | ^^^^^^^^^^ no rules expected this token in macro call From 3e04a58e7240c59153c6d847475cabd4f267c988 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Tue, 15 Feb 2022 18:41:30 -0800 Subject: [PATCH 04/24] Trybuild tests for more unexpected command variations. --- tests/trybuild/stages/unexpected_command_first.rs | 8 ++++++++ tests/trybuild/stages/unexpected_command_first.stderr | 5 +++++ tests/trybuild/stages/unexpected_command_last.rs | 8 ++++++++ tests/trybuild/stages/unexpected_command_last.stderr | 5 +++++ tests/trybuild/stages/unexpected_command_middle.rs | 9 +++++++++ tests/trybuild/stages/unexpected_command_middle.stderr | 5 +++++ tests/trybuild/stages/unexpected_command_with_colon.rs | 7 +++++++ .../trybuild/stages/unexpected_command_with_colon.stderr | 5 +++++ 8 files changed, 52 insertions(+) create mode 100644 tests/trybuild/stages/unexpected_command_first.rs create mode 100644 tests/trybuild/stages/unexpected_command_first.stderr create mode 100644 tests/trybuild/stages/unexpected_command_last.rs create mode 100644 tests/trybuild/stages/unexpected_command_last.stderr create mode 100644 tests/trybuild/stages/unexpected_command_middle.rs create mode 100644 tests/trybuild/stages/unexpected_command_middle.stderr create mode 100644 tests/trybuild/stages/unexpected_command_with_colon.rs create mode 100644 tests/trybuild/stages/unexpected_command_with_colon.stderr diff --git a/tests/trybuild/stages/unexpected_command_first.rs b/tests/trybuild/stages/unexpected_command_first.rs new file mode 100644 index 00000000..de2e0788 --- /dev/null +++ b/tests/trybuild/stages/unexpected_command_first.rs @@ -0,0 +1,8 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + unexpected, + flush, +}; + +fn main() {} diff --git a/tests/trybuild/stages/unexpected_command_first.stderr b/tests/trybuild/stages/unexpected_command_first.stderr new file mode 100644 index 00000000..71abdd32 --- /dev/null +++ b/tests/trybuild/stages/unexpected_command_first.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `unexpected` + --> tests/trybuild/stages/unexpected_command_first.rs:4:5 + | +4 | unexpected, + | ^^^^^^^^^^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/unexpected_command_last.rs b/tests/trybuild/stages/unexpected_command_last.rs new file mode 100644 index 00000000..aaaca571 --- /dev/null +++ b/tests/trybuild/stages/unexpected_command_last.rs @@ -0,0 +1,8 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + flush, + unexpected, +}; + +fn main() {} diff --git a/tests/trybuild/stages/unexpected_command_last.stderr b/tests/trybuild/stages/unexpected_command_last.stderr new file mode 100644 index 00000000..ede05e44 --- /dev/null +++ b/tests/trybuild/stages/unexpected_command_last.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `unexpected` + --> tests/trybuild/stages/unexpected_command_last.rs:5:5 + | +5 | unexpected, + | ^^^^^^^^^^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/unexpected_command_middle.rs b/tests/trybuild/stages/unexpected_command_middle.rs new file mode 100644 index 00000000..507717fd --- /dev/null +++ b/tests/trybuild/stages/unexpected_command_middle.rs @@ -0,0 +1,9 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + flush, + unexpected, + flush, +}; + +fn main() {} diff --git a/tests/trybuild/stages/unexpected_command_middle.stderr b/tests/trybuild/stages/unexpected_command_middle.stderr new file mode 100644 index 00000000..fc64d8bb --- /dev/null +++ b/tests/trybuild/stages/unexpected_command_middle.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `unexpected` + --> tests/trybuild/stages/unexpected_command_middle.rs:5:5 + | +5 | unexpected, + | ^^^^^^^^^^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/unexpected_command_with_colon.rs b/tests/trybuild/stages/unexpected_command_with_colon.rs new file mode 100644 index 00000000..6a55bffc --- /dev/null +++ b/tests/trybuild/stages/unexpected_command_with_colon.rs @@ -0,0 +1,7 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + unexpected: value, +}; + +fn main() {} diff --git a/tests/trybuild/stages/unexpected_command_with_colon.stderr b/tests/trybuild/stages/unexpected_command_with_colon.stderr new file mode 100644 index 00000000..4085d577 --- /dev/null +++ b/tests/trybuild/stages/unexpected_command_with_colon.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `unexpected` + --> tests/trybuild/stages/unexpected_command_with_colon.rs:4:5 + | +4 | unexpected: value, + | ^^^^^^^^^^ no rules expected this token in macro call From 9a71c8dc8e84e10676ccef055cbcd735c81a5279 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Tue, 15 Feb 2022 22:45:11 -0800 Subject: [PATCH 05/24] Trybuild tests for stages macro, with rewritten macro to pass these tests. --- src/system/schedule/stage/mod.rs | 170 ++++++++++++++++-- tests/trybuild/stages/colon_alone.rs | 7 + tests/trybuild/stages/colon_alone.stderr | 5 + tests/trybuild/stages/comma_alone.rs | 7 + tests/trybuild/stages/comma_alone.stderr | 5 + tests/trybuild/stages/flush_missing_comma.rs | 8 + .../stages/flush_missing_comma.stderr | 5 + tests/trybuild/stages/flush_with_colon.rs | 7 + tests/trybuild/stages/flush_with_colon.stderr | 5 + .../stages/par_system_missing_comma.rs | 17 ++ .../stages/par_system_missing_comma.stderr | 5 + tests/trybuild/stages/par_system_no_colon.rs | 7 + .../stages/par_system_no_colon.stderr | 5 + tests/trybuild/stages/system_missing_comma.rs | 17 ++ .../stages/system_missing_comma.stderr | 5 + tests/trybuild/stages/system_no_colon.rs | 7 + tests/trybuild/stages/system_no_colon.stderr | 5 + 17 files changed, 270 insertions(+), 17 deletions(-) create mode 100644 tests/trybuild/stages/colon_alone.rs create mode 100644 tests/trybuild/stages/colon_alone.stderr create mode 100644 tests/trybuild/stages/comma_alone.rs create mode 100644 tests/trybuild/stages/comma_alone.stderr create mode 100644 tests/trybuild/stages/flush_missing_comma.rs create mode 100644 tests/trybuild/stages/flush_missing_comma.stderr create mode 100644 tests/trybuild/stages/flush_with_colon.rs create mode 100644 tests/trybuild/stages/flush_with_colon.stderr create mode 100644 tests/trybuild/stages/par_system_missing_comma.rs create mode 100644 tests/trybuild/stages/par_system_missing_comma.stderr create mode 100644 tests/trybuild/stages/par_system_no_colon.rs create mode 100644 tests/trybuild/stages/par_system_no_colon.stderr create mode 100644 tests/trybuild/stages/system_missing_comma.rs create mode 100644 tests/trybuild/stages/system_missing_comma.stderr create mode 100644 tests/trybuild/stages/system_no_colon.rs create mode 100644 tests/trybuild/stages/system_no_colon.stderr diff --git a/src/system/schedule/stage/mod.rs b/src/system/schedule/stage/mod.rs index ec925424..aef07863 100644 --- a/src/system/schedule/stage/mod.rs +++ b/src/system/schedule/stage/mod.rs @@ -115,23 +115,159 @@ doc::non_root_macro! { /// [`schedule::Builder`]: crate::system::schedule::Builder /// [`System`]: crate::system::System macro_rules! stages { - ($($idents:tt $(: $systems:tt)?),* $(,)?) => ( - stages!(internal @ $crate::system::schedule::stage::Null; $($idents $(: $systems)?,)*) - ); - (internal @ $processed:ty; system: $system:ty, $($idents:tt $(: $systems:tt)?),* $(,)?) => ( - stages!(internal @ ($crate::system::schedule::stage::Stage<$system, $crate::system::Null>, $processed); $($idents $(: $systems)?,)*) - ); - (internal @ $processed:ty; par_system: $par_system:ty, $($idents:tt $(: $systems:tt)?),* $(,)?) => ( - stages!(internal @ ($crate::system::schedule::stage::Stage<$crate::system::Null, $par_system>, $processed); $($idents $(: $systems)?,)*) - ); - (internal @ $processed:ty; flush, $($idents:tt $(: $systems:tt)?),* $(,)?) => ( - stages!(internal @ ($crate::system::schedule::stage::Stage<$crate::system::Null, $crate::system::Null>, $processed); $($idents $(: $systems)?,)*) - ); - (internal @ $processed:ty;) => ( - $processed - ); - (internal @ $processed:ty; $ident:tt $(: $system:tt)?, $($idents:tt $(: $systems:tt)?),* $(,)?) => ( - $crate::unexpected!($ident $(: $system:tt)?) + // Entry point for the macro. + // + // This just calls into the internal macro with all of the correct parameters. + ($($tt:tt)*) => ( + $crate::stages_internal!(@task $crate::system::schedule::stage::Null; ($($tt)*) ($($tt)*)) ); } } + +#[doc(hidden)] +#[macro_export] +macro_rules! stages_internal { + /////////////////////////////////////////////////////////////////////////////////////////////// + // Generic task macro. + // + // These patterns are for matching and processing generic tasks listed in the token tree. When + // each of the valid task types (system, par_system, and flush) are encountered, the tokens are + // passed to the appropriate patterns (@system, @par_system, and @flush) to be consumed. + // + // Note that we require two copies of the input token tree here. The first is matched on, and + // the second is used to trigger errors. + // + // Invoked as: + // $crate::stages_internal!(@task $crate::system::schedule::stage::Null; ($($tt)*) ($($tt)*)) + /////////////////////////////////////////////////////////////////////////////////////////////// + + // Match a system task. + (@task $processed:ty; (system $($rest:tt)*) $copy:tt) => ( + $crate::stages_internal!(@system $processed; ($($rest)*) ($($rest)*)) + ); + + // Match a par_system task. + (@task $processed:ty; (par_system $($rest:tt)*) $copy:tt) => ( + $crate::stages_internal!(@par_system $processed; ($($rest)*) ($($rest)*)) + ); + + // Match a flush task. + (@task $processed:ty; (flush $($rest:tt)*) $copy:tt) => ( + $crate::stages_internal!(@flush $processed; ($($rest)*) ($($rest)*)) + ); + + // End case. We return the processed result. + (@task $processed:ty; () ()) => ( + $processed + ); + + // Match any other unexpected input. This will output an error. + (@task $processed:ty; ($($rest:tt)*) $copy:tt) => ( + $crate::unexpected!($($rest)*) + ); + + /////////////////////////////////////////////////////////////////////////////////////////////// + // System task macro. + // + // These patterns match the remainder of a system task entry. This will match a colon followed + // by a system type. Trailing commas are also matched here. + // + // Note that we require two copies of the input token tree here. The first is matched on, and + // the second is used to trigger errors. + /////////////////////////////////////////////////////////////////////////////////////////////// + + // Match a system type without a trailing comma. This will only match at the end of the token + // tree. + (@system $processed:ty; (: $system:ty) $copy:tt) => { + $crate::stages_internal(@task ($crate::system::schedule::stage::Stage<$system, $crate::system::Null>, $processed); () ()) + }; + + // Match a system type with a trailing comma. + (@system $processed:ty; (: $system:ty, $($rest:tt)*) $copy:tt) => ( + $crate::stages_internal!(@task ($crate::system::schedule::stage::Stage<$system, $crate::system::Null>, $processed); ($($rest)*) ($($rest)*)) + ); + + // Match a system type with no trailing comma not at the end of the token tree. This will + // output an error. + (@system $processed:ty; (: $system:tt $($rest:tt)*) $copy:tt) => { + $crate::unexpected!($($rest)*) + }; + + // Match a comma with no system type provided. This will output an error. + (@system $processed:ty; (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => ( + $crate::unexpected!($comma) + ); + + // Match any other unexpected input. This will output an error. + (@system $processed:ty; ($($rest:tt)*) $copy:tt) => ( + $crate::unexpected!($($rest)*) + ); + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Parallel system task macro. + // + // These patterns match the remainder of a par_system task entry. This will match a colon + // followed by a parallel system type. Trailing commas are also matched here. + // + // Note that we require two copies of the input token tree here. The first is matched on, and + // the second is used to trigger errors. + /////////////////////////////////////////////////////////////////////////////////////////////// + + // Match a parallel system type without a trailing comma. This will only match at the end of + // the token tree. + (@par_system $processed:ty; (: $par_system:ty) $copy:tt) => ( + $crate::stages_internal!(@task ($crate::system::schedule::stage::Stage<$crate::system::Null, $par_system>, $processed); () ()) + ); + + // Match a parallel system type with a trailing comma. + (@par_system $processed:ty; (: $par_system:ty, $($rest:tt)*) $copy:tt) => ( + $crate::stages_internal!(@task ($crate::system::schedule::stage::Stage<$crate::system::Null, $par_system>, $processed); ($($rest)*) ($($rest)*)) + ); + + // Match a parallel system type with no trailing comma not at the end of the token tree. This + // will output an error. + (@par_system $processed:ty; (: $par_system:tt $($rest:tt)*) $copy:tt) => { + $crate::unexpected!($($rest)*) + }; + + // Match a comma with no parallel system type provided. This will output an error. + (@par_system $processed:ty; (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => ( + $crate::unexpected!($comma) + ); + + // Match any other unexpected input. This will output an error. + (@par_system $processed:ty; ($($rest:tt)*) $copy:tt) => ( + $crate::unexpected!($($rest)*) + ); + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Flush task macro. + // + // These patterns match the remainder of a flush task entry, which is only either a comma or + // nothing. + // + // Note that we require two copies of the input token tree here. The first is matched on, and + // the second is used to trigger errors. + /////////////////////////////////////////////////////////////////////////////////////////////// + + // Match a comma. + (@flush $processed:ty; (, $($rest:tt)*) $copy:tt) => ( + $crate::stages_internal!(@task ($crate::system::schedule::stage::Stage<$crate::system::Null, $crate::system::Null>, $processed); ($($rest)*) ($($rest)*)) + ); + + // Match a colon. This is invalid and will output an error. + (@flush $processed:ty; (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => ( + $crate::unexpected!($colon) + ); + + // Match nothing. This will only occur at the end of the input token tree, which is the only + // time when a trailing comma is not required. + (@flush $processed:ty; () ()) => ( + $crate::stages_internal!(@task ($crate::system::schedule::stage::Stage<$crate::system::Null, $crate::system::Null>, $processed); () ()) + ); + + // Match any other unexpected input. This will output an error. + (@flush $processed:ty; ($($rest:tt)*) $copy:tt) => ( + $crate::unexpected!($($rest)*) + ); +} diff --git a/tests/trybuild/stages/colon_alone.rs b/tests/trybuild/stages/colon_alone.rs new file mode 100644 index 00000000..4a7faf56 --- /dev/null +++ b/tests/trybuild/stages/colon_alone.rs @@ -0,0 +1,7 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + : +}; + +fn main() {} diff --git a/tests/trybuild/stages/colon_alone.stderr b/tests/trybuild/stages/colon_alone.stderr new file mode 100644 index 00000000..3029e913 --- /dev/null +++ b/tests/trybuild/stages/colon_alone.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `:` + --> tests/trybuild/stages/colon_alone.rs:4:5 + | +4 | : + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/comma_alone.rs b/tests/trybuild/stages/comma_alone.rs new file mode 100644 index 00000000..285cfde9 --- /dev/null +++ b/tests/trybuild/stages/comma_alone.rs @@ -0,0 +1,7 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + , +}; + +fn main() {} diff --git a/tests/trybuild/stages/comma_alone.stderr b/tests/trybuild/stages/comma_alone.stderr new file mode 100644 index 00000000..0e1aa5f1 --- /dev/null +++ b/tests/trybuild/stages/comma_alone.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `,` + --> tests/trybuild/stages/comma_alone.rs:4:5 + | +4 | , + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/flush_missing_comma.rs b/tests/trybuild/stages/flush_missing_comma.rs new file mode 100644 index 00000000..89bfa4c6 --- /dev/null +++ b/tests/trybuild/stages/flush_missing_comma.rs @@ -0,0 +1,8 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + flush + flush +}; + +fn main() {} diff --git a/tests/trybuild/stages/flush_missing_comma.stderr b/tests/trybuild/stages/flush_missing_comma.stderr new file mode 100644 index 00000000..10982a86 --- /dev/null +++ b/tests/trybuild/stages/flush_missing_comma.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `flush` + --> tests/trybuild/stages/flush_missing_comma.rs:5:5 + | +5 | flush + | ^^^^^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/flush_with_colon.rs b/tests/trybuild/stages/flush_with_colon.rs new file mode 100644 index 00000000..d3ca05b5 --- /dev/null +++ b/tests/trybuild/stages/flush_with_colon.rs @@ -0,0 +1,7 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + flush: value, +}; + +fn main() {} diff --git a/tests/trybuild/stages/flush_with_colon.stderr b/tests/trybuild/stages/flush_with_colon.stderr new file mode 100644 index 00000000..87c69e7b --- /dev/null +++ b/tests/trybuild/stages/flush_with_colon.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `:` + --> tests/trybuild/stages/flush_with_colon.rs:4:10 + | +4 | flush: value, + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/par_system_missing_comma.rs b/tests/trybuild/stages/par_system_missing_comma.rs new file mode 100644 index 00000000..b6834c7b --- /dev/null +++ b/tests/trybuild/stages/par_system_missing_comma.rs @@ -0,0 +1,17 @@ +use brood::{query::{filter, result, views}, registry::Registry, system::{schedule::stages, ParSystem}}; + +struct MySystem; + +impl<'a> ParSystem<'a> for MySystem { + type Views = views!(); + type Filter = filter::None; + + fn run(&mut self, query_results: result::ParIter<'a, R, Self::Filter, Self::Views>) where R: Registry + 'a {} +} + +type Stages = stages!{ + par_system: MySystem + flush +}; + +fn main() {} diff --git a/tests/trybuild/stages/par_system_missing_comma.stderr b/tests/trybuild/stages/par_system_missing_comma.stderr new file mode 100644 index 00000000..169a799e --- /dev/null +++ b/tests/trybuild/stages/par_system_missing_comma.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `flush` + --> tests/trybuild/stages/par_system_missing_comma.rs:14:5 + | +14 | flush + | ^^^^^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/par_system_no_colon.rs b/tests/trybuild/stages/par_system_no_colon.rs new file mode 100644 index 00000000..62dea422 --- /dev/null +++ b/tests/trybuild/stages/par_system_no_colon.rs @@ -0,0 +1,7 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + par_system, +}; + +fn main() {} diff --git a/tests/trybuild/stages/par_system_no_colon.stderr b/tests/trybuild/stages/par_system_no_colon.stderr new file mode 100644 index 00000000..56cb349f --- /dev/null +++ b/tests/trybuild/stages/par_system_no_colon.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `,` + --> tests/trybuild/stages/par_system_no_colon.rs:4:15 + | +4 | par_system, + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/system_missing_comma.rs b/tests/trybuild/stages/system_missing_comma.rs new file mode 100644 index 00000000..5fd6dd01 --- /dev/null +++ b/tests/trybuild/stages/system_missing_comma.rs @@ -0,0 +1,17 @@ +use brood::{query::{filter, result, views}, registry::Registry, system::{schedule::stages, System}}; + +struct MySystem; + +impl<'a> System<'a> for MySystem { + type Views = views!(); + type Filter = filter::None; + + fn run(&mut self, query_results: result::Iter<'a, R, Self::Filter, Self::Views>) where R: Registry + 'a {} +} + +type Stages = stages!{ + system: MySystem + flush +}; + +fn main() {} diff --git a/tests/trybuild/stages/system_missing_comma.stderr b/tests/trybuild/stages/system_missing_comma.stderr new file mode 100644 index 00000000..43b337a2 --- /dev/null +++ b/tests/trybuild/stages/system_missing_comma.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `flush` + --> tests/trybuild/stages/system_missing_comma.rs:14:5 + | +14 | flush + | ^^^^^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/system_no_colon.rs b/tests/trybuild/stages/system_no_colon.rs new file mode 100644 index 00000000..9f52909d --- /dev/null +++ b/tests/trybuild/stages/system_no_colon.rs @@ -0,0 +1,7 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + system, +}; + +fn main() {} diff --git a/tests/trybuild/stages/system_no_colon.stderr b/tests/trybuild/stages/system_no_colon.stderr new file mode 100644 index 00000000..84b6a2d8 --- /dev/null +++ b/tests/trybuild/stages/system_no_colon.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `,` + --> tests/trybuild/stages/system_no_colon.rs:4:11 + | +4 | system, + | ^ no rules expected this token in macro call From 9d6c783c04e0ad90fba63258e04c833ff391f694 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Tue, 15 Feb 2022 22:50:33 -0800 Subject: [PATCH 06/24] Formatting. --- src/system/schedule/stage/mod.rs | 6 +++--- tests/trybuild.rs | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/system/schedule/stage/mod.rs b/src/system/schedule/stage/mod.rs index aef07863..79bc419f 100644 --- a/src/system/schedule/stage/mod.rs +++ b/src/system/schedule/stage/mod.rs @@ -234,7 +234,7 @@ macro_rules! stages_internal { (@par_system $processed:ty; (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => ( $crate::unexpected!($comma) ); - + // Match any other unexpected input. This will output an error. (@par_system $processed:ty; ($($rest:tt)*) $copy:tt) => ( $crate::unexpected!($($rest)*) @@ -249,7 +249,7 @@ macro_rules! stages_internal { // Note that we require two copies of the input token tree here. The first is matched on, and // the second is used to trigger errors. /////////////////////////////////////////////////////////////////////////////////////////////// - + // Match a comma. (@flush $processed:ty; (, $($rest:tt)*) $copy:tt) => ( $crate::stages_internal!(@task ($crate::system::schedule::stage::Stage<$crate::system::Null, $crate::system::Null>, $processed); ($($rest)*) ($($rest)*)) @@ -265,7 +265,7 @@ macro_rules! stages_internal { (@flush $processed:ty; () ()) => ( $crate::stages_internal!(@task ($crate::system::schedule::stage::Stage<$crate::system::Null, $crate::system::Null>, $processed); () ()) ); - + // Match any other unexpected input. This will output an error. (@flush $processed:ty; ($($rest:tt)*) $copy:tt) => ( $crate::unexpected!($($rest)*) diff --git a/tests/trybuild.rs b/tests/trybuild.rs index ee4fecf3..4fdf8d39 100644 --- a/tests/trybuild.rs +++ b/tests/trybuild.rs @@ -3,9 +3,13 @@ macro_rules! trybuild_test { #[test] #[rustversion::attr(not(nightly), ignore)] fn $test_name() { - trybuild::TestCases::new().compile_fail(concat!("tests/trybuild/", stringify!($test_name), "/*.rs")); + trybuild::TestCases::new().compile_fail(concat!( + "tests/trybuild/", + stringify!($test_name), + "/*.rs" + )); } - } + }; } trybuild_test!(entities); From 39f8f5669bba6f5a98a35cf45d9b39688f3e3fe5 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Wed, 16 Feb 2022 15:13:34 -0800 Subject: [PATCH 07/24] more trybuild tests for unexpected tokens in stages macro. --- tests/trybuild/stages/double_comma.rs | 7 +++++++ tests/trybuild/stages/double_comma.stderr | 5 +++++ tests/trybuild/stages/unexpected_token.rs | 9 +++++++++ tests/trybuild/stages/unexpected_token.stderr | 5 +++++ 4 files changed, 26 insertions(+) create mode 100644 tests/trybuild/stages/double_comma.rs create mode 100644 tests/trybuild/stages/double_comma.stderr create mode 100644 tests/trybuild/stages/unexpected_token.rs create mode 100644 tests/trybuild/stages/unexpected_token.stderr diff --git a/tests/trybuild/stages/double_comma.rs b/tests/trybuild/stages/double_comma.rs new file mode 100644 index 00000000..b6bea712 --- /dev/null +++ b/tests/trybuild/stages/double_comma.rs @@ -0,0 +1,7 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + flush,, +}; + +fn main() {} diff --git a/tests/trybuild/stages/double_comma.stderr b/tests/trybuild/stages/double_comma.stderr new file mode 100644 index 00000000..d83279b6 --- /dev/null +++ b/tests/trybuild/stages/double_comma.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `,` + --> tests/trybuild/stages/double_comma.rs:4:11 + | +4 | flush,, + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/stages/unexpected_token.rs b/tests/trybuild/stages/unexpected_token.rs new file mode 100644 index 00000000..b1a0c8a1 --- /dev/null +++ b/tests/trybuild/stages/unexpected_token.rs @@ -0,0 +1,9 @@ +use brood::system::schedule::stages; + +type Stages = stages!{ + flush, + +, + flush, +}; + +fn main() {} diff --git a/tests/trybuild/stages/unexpected_token.stderr b/tests/trybuild/stages/unexpected_token.stderr new file mode 100644 index 00000000..b581bc69 --- /dev/null +++ b/tests/trybuild/stages/unexpected_token.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `+` + --> tests/trybuild/stages/unexpected_token.rs:5:5 + | +5 | +, + | ^ no rules expected this token in macro call From 6ccf37bf1b58c9a6e72b02f11f86b574fddb782e Mon Sep 17 00:00:00 2001 From: Anders429 Date: Wed, 16 Feb 2022 20:45:11 -0800 Subject: [PATCH 08/24] More trybuild tests for entities macro. --- src/entities/mod.rs | 7 +++++-- tests/trybuild/entities/comma_alone.rs | 5 +++++ tests/trybuild/entities/comma_alone.stderr | 5 +++++ tests/trybuild/entities/double_comma.rs | 9 +++++++++ tests/trybuild/entities/double_comma.stderr | 5 +++++ tests/trybuild/entities/length_not_integer.rs | 11 +++++++++++ tests/trybuild/entities/length_not_integer.stderr | 5 +++++ tests/trybuild/entities/semicolon_separated.rs | 11 +++++++++++ tests/trybuild/entities/semicolon_separated.stderr | 5 +++++ tests/trybuild/entities/unexpected_token.rs | 9 +++++++++ tests/trybuild/entities/unexpected_token.stderr | 5 +++++ 11 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tests/trybuild/entities/comma_alone.rs create mode 100644 tests/trybuild/entities/comma_alone.stderr create mode 100644 tests/trybuild/entities/double_comma.rs create mode 100644 tests/trybuild/entities/double_comma.stderr create mode 100644 tests/trybuild/entities/length_not_integer.rs create mode 100644 tests/trybuild/entities/length_not_integer.stderr create mode 100644 tests/trybuild/entities/semicolon_separated.rs create mode 100644 tests/trybuild/entities/semicolon_separated.stderr create mode 100644 tests/trybuild/entities/unexpected_token.rs create mode 100644 tests/trybuild/entities/unexpected_token.stderr diff --git a/src/entities/mod.rs b/src/entities/mod.rs index 01d7b60e..90547053 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -227,10 +227,10 @@ macro_rules! entities { ) } }; - ($(($($components:expr),*)),* $(,)?) => { + ($(($($components:expr),*)),+ $(,)?) => { unsafe { $crate::entities::Batch::new_unchecked( - $crate::entities!(@transpose [] $(($($components),*)),*) + $crate::entities!(@transpose [] $(($($components),*)),+) ) } }; @@ -244,18 +244,21 @@ macro_rules! entities { $crate::entities::Batch::new_unchecked($crate::entities::Null) } }; + (@cloned ($component:expr $(,$components:expr)* $(,)?); $n:expr) => { ($crate::reexports::vec![$component; $n], $crate::entities!(@cloned ($($components),*); $n)) }; (@cloned (); $n:expr) => { $crate::entities::Null }; + (@transpose [$([$($column:expr),*])*] $(($component:expr $(,$components:expr)* $(,)?)),*) => { $crate::entities!(@transpose [$([$($column),*])* [$($component),*]] $(($($components),*)),*) }; (@transpose [$([$($column:expr),*])*] $(()),*) => { $crate::entities!(@as_vec ($(($($column),*)),*)) }; + (@as_vec (($($column:expr),*) $(,($($columns:expr),*))* $(,)?)) => { ($crate::reexports::vec![$($column),*], $crate::entities!(@as_vec ($(($($columns),*)),*))) }; diff --git a/tests/trybuild/entities/comma_alone.rs b/tests/trybuild/entities/comma_alone.rs new file mode 100644 index 00000000..df66b8f6 --- /dev/null +++ b/tests/trybuild/entities/comma_alone.rs @@ -0,0 +1,5 @@ +use brood::entities; + +fn main () { + let entities = entities!(,); +} diff --git a/tests/trybuild/entities/comma_alone.stderr b/tests/trybuild/entities/comma_alone.stderr new file mode 100644 index 00000000..741603f1 --- /dev/null +++ b/tests/trybuild/entities/comma_alone.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `,` + --> tests/trybuild/entities/comma_alone.rs:4:30 + | +4 | let entities = entities!(,); + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/entities/double_comma.rs b/tests/trybuild/entities/double_comma.rs new file mode 100644 index 00000000..375057bc --- /dev/null +++ b/tests/trybuild/entities/double_comma.rs @@ -0,0 +1,9 @@ +use brood::entities; + +// Define components. +struct A; +struct B; + +fn main () { + let entities = entities!((A, B),, (A, B)); +} diff --git a/tests/trybuild/entities/double_comma.stderr b/tests/trybuild/entities/double_comma.stderr new file mode 100644 index 00000000..8bb8ef30 --- /dev/null +++ b/tests/trybuild/entities/double_comma.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `,` + --> tests/trybuild/entities/double_comma.rs:8:37 + | +8 | let entities = entities!((A, B),, (A, B)); + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/entities/length_not_integer.rs b/tests/trybuild/entities/length_not_integer.rs new file mode 100644 index 00000000..1ce35f45 --- /dev/null +++ b/tests/trybuild/entities/length_not_integer.rs @@ -0,0 +1,11 @@ +use brood::entities; + +// Define components. +#[derive(Clone)] +struct A; +#[derive(Clone)] +struct B; + +fn main () { + let entities = entities!((A, B); 1.5); +} diff --git a/tests/trybuild/entities/length_not_integer.stderr b/tests/trybuild/entities/length_not_integer.stderr new file mode 100644 index 00000000..72499e1a --- /dev/null +++ b/tests/trybuild/entities/length_not_integer.stderr @@ -0,0 +1,5 @@ +error[E0308]: mismatched types + --> tests/trybuild/entities/length_not_integer.rs:10:38 + | +10 | let entities = entities!((A, B); 1.5); + | ^^^ expected `usize`, found floating-point number diff --git a/tests/trybuild/entities/semicolon_separated.rs b/tests/trybuild/entities/semicolon_separated.rs new file mode 100644 index 00000000..69d9dde2 --- /dev/null +++ b/tests/trybuild/entities/semicolon_separated.rs @@ -0,0 +1,11 @@ +use brood::entities; + +// Define components. +#[derive(Clone)] +struct A; +#[derive(Clone)] +struct B; + +fn main () { + let entities = entities!((A, B); (A, B); (A, B)); +} diff --git a/tests/trybuild/entities/semicolon_separated.stderr b/tests/trybuild/entities/semicolon_separated.stderr new file mode 100644 index 00000000..b94f8808 --- /dev/null +++ b/tests/trybuild/entities/semicolon_separated.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `;` + --> tests/trybuild/entities/semicolon_separated.rs:10:44 + | +10 | let entities = entities!((A, B); (A, B); (A, B)); + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/entities/unexpected_token.rs b/tests/trybuild/entities/unexpected_token.rs new file mode 100644 index 00000000..8ece19d4 --- /dev/null +++ b/tests/trybuild/entities/unexpected_token.rs @@ -0,0 +1,9 @@ +use brood::entities; + +// Define components. +struct A; +struct B; + +fn main () { + let entities = entities!((A, B), (A, B), + (A, B)); +} diff --git a/tests/trybuild/entities/unexpected_token.stderr b/tests/trybuild/entities/unexpected_token.stderr new file mode 100644 index 00000000..5bfc1166 --- /dev/null +++ b/tests/trybuild/entities/unexpected_token.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `+` + --> tests/trybuild/entities/unexpected_token.rs:8:46 + | +8 | let entities = entities!((A, B), (A, B), + (A, B)); + | ^ no rules expected this token in macro call From a73da88257dfcac499157c872cc0965db07eea58 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Wed, 16 Feb 2022 21:29:06 -0800 Subject: [PATCH 09/24] trybuild tests for entity macro. --- tests/trybuild.rs | 1 + tests/trybuild/entity/comma_alone.rs | 5 +++++ tests/trybuild/entity/comma_alone.stderr | 5 +++++ tests/trybuild/entity/unexpected_token.rs | 9 +++++++++ tests/trybuild/entity/unexpected_token.stderr | 5 +++++ 5 files changed, 25 insertions(+) create mode 100644 tests/trybuild/entity/comma_alone.rs create mode 100644 tests/trybuild/entity/comma_alone.stderr create mode 100644 tests/trybuild/entity/unexpected_token.rs create mode 100644 tests/trybuild/entity/unexpected_token.stderr diff --git a/tests/trybuild.rs b/tests/trybuild.rs index 4fdf8d39..79560828 100644 --- a/tests/trybuild.rs +++ b/tests/trybuild.rs @@ -13,5 +13,6 @@ macro_rules! trybuild_test { } trybuild_test!(entities); +trybuild_test!(entity); #[cfg(feature = "parallel")] trybuild_test!(stages); diff --git a/tests/trybuild/entity/comma_alone.rs b/tests/trybuild/entity/comma_alone.rs new file mode 100644 index 00000000..f59e4529 --- /dev/null +++ b/tests/trybuild/entity/comma_alone.rs @@ -0,0 +1,5 @@ +use brood::entity; + +fn main() { + let entity = entity!(,); +} diff --git a/tests/trybuild/entity/comma_alone.stderr b/tests/trybuild/entity/comma_alone.stderr new file mode 100644 index 00000000..4d0a639c --- /dev/null +++ b/tests/trybuild/entity/comma_alone.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `,` + --> tests/trybuild/entity/comma_alone.rs:4:26 + | +4 | let entity = entity!(,); + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/entity/unexpected_token.rs b/tests/trybuild/entity/unexpected_token.rs new file mode 100644 index 00000000..0e468880 --- /dev/null +++ b/tests/trybuild/entity/unexpected_token.rs @@ -0,0 +1,9 @@ +use brood::entity; + +// Define components. +struct A; +struct B; + +fn main() { + let entity = entity!(A, + B,); +} diff --git a/tests/trybuild/entity/unexpected_token.stderr b/tests/trybuild/entity/unexpected_token.stderr new file mode 100644 index 00000000..39a9f218 --- /dev/null +++ b/tests/trybuild/entity/unexpected_token.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `+` + --> tests/trybuild/entity/unexpected_token.rs:8:29 + | +8 | let entity = entity!(A, + B,); + | ^ no rules expected this token in macro call From 774ff48a189202d89adc6a018964c689ec46c044 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Wed, 16 Feb 2022 21:37:00 -0800 Subject: [PATCH 10/24] trybuild tests for registry macro. --- tests/trybuild.rs | 1 + tests/trybuild/registry/comma_alone.rs | 5 +++++ tests/trybuild/registry/comma_alone.stderr | 5 +++++ tests/trybuild/registry/unexpected_token.rs | 9 +++++++++ tests/trybuild/registry/unexpected_token.stderr | 5 +++++ 5 files changed, 25 insertions(+) create mode 100644 tests/trybuild/registry/comma_alone.rs create mode 100644 tests/trybuild/registry/comma_alone.stderr create mode 100644 tests/trybuild/registry/unexpected_token.rs create mode 100644 tests/trybuild/registry/unexpected_token.stderr diff --git a/tests/trybuild.rs b/tests/trybuild.rs index 79560828..d459cd44 100644 --- a/tests/trybuild.rs +++ b/tests/trybuild.rs @@ -14,5 +14,6 @@ macro_rules! trybuild_test { trybuild_test!(entities); trybuild_test!(entity); +trybuild_test!(registry); #[cfg(feature = "parallel")] trybuild_test!(stages); diff --git a/tests/trybuild/registry/comma_alone.rs b/tests/trybuild/registry/comma_alone.rs new file mode 100644 index 00000000..5c0030b9 --- /dev/null +++ b/tests/trybuild/registry/comma_alone.rs @@ -0,0 +1,5 @@ +use brood::registry; + +fn main() { + let registry = registry!(,); +} diff --git a/tests/trybuild/registry/comma_alone.stderr b/tests/trybuild/registry/comma_alone.stderr new file mode 100644 index 00000000..fc7c90d9 --- /dev/null +++ b/tests/trybuild/registry/comma_alone.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `,` + --> tests/trybuild/registry/comma_alone.rs:4:30 + | +4 | let registry = registry!(,); + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/registry/unexpected_token.rs b/tests/trybuild/registry/unexpected_token.rs new file mode 100644 index 00000000..d72b6eb1 --- /dev/null +++ b/tests/trybuild/registry/unexpected_token.rs @@ -0,0 +1,9 @@ +use brood::registry; + +// Define components. +struct A; +struct B; + +fn main() { + let registry = registry!(A, + B,); +} diff --git a/tests/trybuild/registry/unexpected_token.stderr b/tests/trybuild/registry/unexpected_token.stderr new file mode 100644 index 00000000..021b0ab6 --- /dev/null +++ b/tests/trybuild/registry/unexpected_token.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `+` + --> tests/trybuild/registry/unexpected_token.rs:8:33 + | +8 | let registry = registry!(A, + B,); + | ^ no rules expected this token in macro call From ac2c576b0407735624fa0a9ec0a730b82e424ad5 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Thu, 17 Feb 2022 16:07:19 -0800 Subject: [PATCH 11/24] trybuild tests for views macro. --- tests/trybuild/registry/comma_alone.rs | 6 +++--- tests/trybuild/registry/comma_alone.stderr | 6 +++--- tests/trybuild/registry/unexpected_token.rs | 6 +++--- tests/trybuild/registry/unexpected_token.stderr | 6 +++--- tests/trybuild/views/comma_alone.rs | 0 tests/trybuild/views/comma_alone.stderr | 0 tests/trybuild/views/unexpected_token.rs | 0 tests/trybuild/views/unexpected_token.stderr | 0 8 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 tests/trybuild/views/comma_alone.rs create mode 100644 tests/trybuild/views/comma_alone.stderr create mode 100644 tests/trybuild/views/unexpected_token.rs create mode 100644 tests/trybuild/views/unexpected_token.stderr diff --git a/tests/trybuild/registry/comma_alone.rs b/tests/trybuild/registry/comma_alone.rs index 5c0030b9..88e7af8e 100644 --- a/tests/trybuild/registry/comma_alone.rs +++ b/tests/trybuild/registry/comma_alone.rs @@ -1,5 +1,5 @@ use brood::registry; -fn main() { - let registry = registry!(,); -} +type Registry = registry!(,); + +fn main() {} diff --git a/tests/trybuild/registry/comma_alone.stderr b/tests/trybuild/registry/comma_alone.stderr index fc7c90d9..3530431f 100644 --- a/tests/trybuild/registry/comma_alone.stderr +++ b/tests/trybuild/registry/comma_alone.stderr @@ -1,5 +1,5 @@ error: no rules expected the token `,` - --> tests/trybuild/registry/comma_alone.rs:4:30 + --> tests/trybuild/registry/comma_alone.rs:3:27 | -4 | let registry = registry!(,); - | ^ no rules expected this token in macro call +3 | type Registry = registry!(,); + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/registry/unexpected_token.rs b/tests/trybuild/registry/unexpected_token.rs index d72b6eb1..7b0e8269 100644 --- a/tests/trybuild/registry/unexpected_token.rs +++ b/tests/trybuild/registry/unexpected_token.rs @@ -4,6 +4,6 @@ use brood::registry; struct A; struct B; -fn main() { - let registry = registry!(A, + B,); -} +type Registry = registry!(A, + B,); + +fn main() {} diff --git a/tests/trybuild/registry/unexpected_token.stderr b/tests/trybuild/registry/unexpected_token.stderr index 021b0ab6..617aaddb 100644 --- a/tests/trybuild/registry/unexpected_token.stderr +++ b/tests/trybuild/registry/unexpected_token.stderr @@ -1,5 +1,5 @@ error: no rules expected the token `+` - --> tests/trybuild/registry/unexpected_token.rs:8:33 + --> tests/trybuild/registry/unexpected_token.rs:7:30 | -8 | let registry = registry!(A, + B,); - | ^ no rules expected this token in macro call +7 | type Registry = registry!(A, + B,); + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/views/comma_alone.rs b/tests/trybuild/views/comma_alone.rs new file mode 100644 index 00000000..e69de29b diff --git a/tests/trybuild/views/comma_alone.stderr b/tests/trybuild/views/comma_alone.stderr new file mode 100644 index 00000000..e69de29b diff --git a/tests/trybuild/views/unexpected_token.rs b/tests/trybuild/views/unexpected_token.rs new file mode 100644 index 00000000..e69de29b diff --git a/tests/trybuild/views/unexpected_token.stderr b/tests/trybuild/views/unexpected_token.stderr new file mode 100644 index 00000000..e69de29b From 92c597e8b5a508eecf6f24c5140f075e7d49960d Mon Sep 17 00:00:00 2001 From: Anders429 Date: Thu, 17 Feb 2022 21:43:53 -0800 Subject: [PATCH 12/24] Actually write the trybuild tests. --- tests/trybuild.rs | 1 + tests/trybuild/views/comma_alone.rs | 5 +++++ tests/trybuild/views/comma_alone.stderr | 5 +++++ tests/trybuild/views/unexpected_token.rs | 9 +++++++++ tests/trybuild/views/unexpected_token.stderr | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/tests/trybuild.rs b/tests/trybuild.rs index d459cd44..02e7ab5b 100644 --- a/tests/trybuild.rs +++ b/tests/trybuild.rs @@ -17,3 +17,4 @@ trybuild_test!(entity); trybuild_test!(registry); #[cfg(feature = "parallel")] trybuild_test!(stages); +trybuild_test!(views); diff --git a/tests/trybuild/views/comma_alone.rs b/tests/trybuild/views/comma_alone.rs index e69de29b..7b7cb8fd 100644 --- a/tests/trybuild/views/comma_alone.rs +++ b/tests/trybuild/views/comma_alone.rs @@ -0,0 +1,5 @@ +use brood::query::views; + +type Views = views!(,); + +fn main() {} diff --git a/tests/trybuild/views/comma_alone.stderr b/tests/trybuild/views/comma_alone.stderr index e69de29b..7c98bb7d 100644 --- a/tests/trybuild/views/comma_alone.stderr +++ b/tests/trybuild/views/comma_alone.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `,` + --> tests/trybuild/views/comma_alone.rs:3:21 + | +3 | type Views = views!(,); + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/views/unexpected_token.rs b/tests/trybuild/views/unexpected_token.rs index e69de29b..2aa75080 100644 --- a/tests/trybuild/views/unexpected_token.rs +++ b/tests/trybuild/views/unexpected_token.rs @@ -0,0 +1,9 @@ +use brood::query::views; + +// Define components. +struct A; +struct B; + +type Views = views!(&A, + &B,); + +fn main() {} diff --git a/tests/trybuild/views/unexpected_token.stderr b/tests/trybuild/views/unexpected_token.stderr index e69de29b..880c37f5 100644 --- a/tests/trybuild/views/unexpected_token.stderr +++ b/tests/trybuild/views/unexpected_token.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `+` + --> tests/trybuild/views/unexpected_token.rs:7:25 + | +7 | type Views = views!(&A, + &B,); + | ^ no rules expected this token in macro call From fe82b70b9074e05b5c8a320adaa1009eff175221 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Thu, 17 Feb 2022 21:48:55 -0800 Subject: [PATCH 13/24] trybuild tests for result macro. --- tests/trybuild.rs | 1 + tests/trybuild/result/comma_alone.rs | 5 +++++ tests/trybuild/result/comma_alone.stderr | 5 +++++ tests/trybuild/result/unexpected_token.rs | 9 +++++++++ tests/trybuild/result/unexpected_token.stderr | 5 +++++ 5 files changed, 25 insertions(+) create mode 100644 tests/trybuild/result/comma_alone.rs create mode 100644 tests/trybuild/result/comma_alone.stderr create mode 100644 tests/trybuild/result/unexpected_token.rs create mode 100644 tests/trybuild/result/unexpected_token.stderr diff --git a/tests/trybuild.rs b/tests/trybuild.rs index 02e7ab5b..b792859f 100644 --- a/tests/trybuild.rs +++ b/tests/trybuild.rs @@ -15,6 +15,7 @@ macro_rules! trybuild_test { trybuild_test!(entities); trybuild_test!(entity); trybuild_test!(registry); +trybuild_test!(result); #[cfg(feature = "parallel")] trybuild_test!(stages); trybuild_test!(views); diff --git a/tests/trybuild/result/comma_alone.rs b/tests/trybuild/result/comma_alone.rs new file mode 100644 index 00000000..c1b2ce4e --- /dev/null +++ b/tests/trybuild/result/comma_alone.rs @@ -0,0 +1,5 @@ +use brood::query::result; + +fn main() { + let result!(,) = result::Null; +} diff --git a/tests/trybuild/result/comma_alone.stderr b/tests/trybuild/result/comma_alone.stderr new file mode 100644 index 00000000..eaade1ed --- /dev/null +++ b/tests/trybuild/result/comma_alone.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `,` + --> tests/trybuild/result/comma_alone.rs:4:17 + | +4 | let result!(,) = result::Null; + | ^ no rules expected this token in macro call diff --git a/tests/trybuild/result/unexpected_token.rs b/tests/trybuild/result/unexpected_token.rs new file mode 100644 index 00000000..0f25f3ec --- /dev/null +++ b/tests/trybuild/result/unexpected_token.rs @@ -0,0 +1,9 @@ +use brood::query::result; + +// Define components. +struct A; +struct B; + +fn main() { + let result!(a, + b) = (A, (A, result::Null)); +} diff --git a/tests/trybuild/result/unexpected_token.stderr b/tests/trybuild/result/unexpected_token.stderr new file mode 100644 index 00000000..79d33194 --- /dev/null +++ b/tests/trybuild/result/unexpected_token.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `+` + --> tests/trybuild/result/unexpected_token.rs:8:20 + | +8 | let result!(a, + b) = (A, (A, result::Null)); + | ^ no rules expected this token in macro call From 9b37dde81be75f96fae3db5c00d1aed7147571e0 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Thu, 17 Feb 2022 23:25:23 -0800 Subject: [PATCH 14/24] Install valgrind from source. --- .github/workflows/test.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2112f1c7..817560f7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -141,7 +141,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: sudo apt-get install valgrind + - run: wget https://sourceware.org/pub/valgrind/valgrind-3.18.1.tar.bz2 + - run: tar xvf valgrind-3.18.1.tar.bz2 + - run: cd valgrind-3.18.1 + - run: sudo make install - uses: actions-rs/toolchain@v1 with: toolchain: nightly From fc71248ad639537c5cdec05d2ddafa7f63ce73c8 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Thu, 17 Feb 2022 23:27:29 -0800 Subject: [PATCH 15/24] Add missing command. --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 817560f7..303d83d4 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -144,6 +144,7 @@ jobs: - run: wget https://sourceware.org/pub/valgrind/valgrind-3.18.1.tar.bz2 - run: tar xvf valgrind-3.18.1.tar.bz2 - run: cd valgrind-3.18.1 + - run: make - run: sudo make install - uses: actions-rs/toolchain@v1 with: From ed72fee21f9de736a833f2794ad473d24fb02034 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Thu, 17 Feb 2022 23:34:07 -0800 Subject: [PATCH 16/24] Run configure binary. --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 303d83d4..fe44a84a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -144,6 +144,7 @@ jobs: - run: wget https://sourceware.org/pub/valgrind/valgrind-3.18.1.tar.bz2 - run: tar xvf valgrind-3.18.1.tar.bz2 - run: cd valgrind-3.18.1 + - run: ./configure - run: make - run: sudo make install - uses: actions-rs/toolchain@v1 From 880db4c85879754e8b7e4474f1bc14b60f29f3c0 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Thu, 17 Feb 2022 23:39:52 -0800 Subject: [PATCH 17/24] Run from root directory. --- .github/workflows/test.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fe44a84a..1d4a6bd7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -143,10 +143,9 @@ jobs: - uses: actions/checkout@v2 - run: wget https://sourceware.org/pub/valgrind/valgrind-3.18.1.tar.bz2 - run: tar xvf valgrind-3.18.1.tar.bz2 - - run: cd valgrind-3.18.1 - - run: ./configure - - run: make - - run: sudo make install + - run: ./valgrind-3.18.1/configure + - run: make -C valgrind-3.18.1 + - run: sudo make -C valgrind-3.18.1 install - uses: actions-rs/toolchain@v1 with: toolchain: nightly From 062d0ad370067f9e23c5376208f17b16348ba6ce Mon Sep 17 00:00:00 2001 From: Anders429 Date: Fri, 18 Feb 2022 12:04:22 -0800 Subject: [PATCH 18/24] Specify working directory for make commands. --- .github/workflows/test.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1d4a6bd7..352ad181 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -143,9 +143,12 @@ jobs: - uses: actions/checkout@v2 - run: wget https://sourceware.org/pub/valgrind/valgrind-3.18.1.tar.bz2 - run: tar xvf valgrind-3.18.1.tar.bz2 - - run: ./valgrind-3.18.1/configure - - run: make -C valgrind-3.18.1 - - run: sudo make -C valgrind-3.18.1 install + - run: /configure + working-directory: ./valgrind-3.18.1 + - run: make + working-directory: ./valgrind-3.18.1 + - run: sudo make install + working-directory: ./valgrind-3.18.1 - uses: actions-rs/toolchain@v1 with: toolchain: nightly From 006e5fdbd29d6ad2a872d57f41a86d406fa5f434 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Fri, 18 Feb 2022 12:05:55 -0800 Subject: [PATCH 19/24] Fix typo in command. --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 352ad181..5f19737a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -143,7 +143,7 @@ jobs: - uses: actions/checkout@v2 - run: wget https://sourceware.org/pub/valgrind/valgrind-3.18.1.tar.bz2 - run: tar xvf valgrind-3.18.1.tar.bz2 - - run: /configure + - run: ./configure working-directory: ./valgrind-3.18.1 - run: make working-directory: ./valgrind-3.18.1 From 72edffb1897ed1df23a21e93630ce2122a9b4c55 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Fri, 18 Feb 2022 12:29:33 -0800 Subject: [PATCH 20/24] Install 32-bit libc6-dbg. --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5f19737a..4bd1461e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -149,6 +149,7 @@ jobs: working-directory: ./valgrind-3.18.1 - run: sudo make install working-directory: ./valgrind-3.18.1 + - run: apt-get install libc6-dbg:i386 - uses: actions-rs/toolchain@v1 with: toolchain: nightly From f06f2411c3b4c38772d2a5c694474cbb278eed92 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Fri, 18 Feb 2022 12:36:46 -0800 Subject: [PATCH 21/24] Install as root. --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4bd1461e..004b03f0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -149,7 +149,7 @@ jobs: working-directory: ./valgrind-3.18.1 - run: sudo make install working-directory: ./valgrind-3.18.1 - - run: apt-get install libc6-dbg:i386 + - run: sudo apt-get install libc6-dbg:i386 - uses: actions-rs/toolchain@v1 with: toolchain: nightly From 4ac1117127f611e51879650b280cfc9f09226494 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Fri, 18 Feb 2022 12:43:25 -0800 Subject: [PATCH 22/24] Install 64-bit libc6-dbg. --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 004b03f0..91bd4163 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -149,7 +149,7 @@ jobs: working-directory: ./valgrind-3.18.1 - run: sudo make install working-directory: ./valgrind-3.18.1 - - run: sudo apt-get install libc6-dbg:i386 + - run: sudo apt-get install libc6-dbg - uses: actions-rs/toolchain@v1 with: toolchain: nightly From 635e2ae9ff106ebac2beaae0d2b69d4259d4f363 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Sat, 19 Feb 2022 22:22:15 -0800 Subject: [PATCH 23/24] Ignore trybuild tests in valgrind and miri workflow jobs. --- .github/workflows/test.yaml | 3 +++ tests/trybuild.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 91bd4163..650c9e0f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -136,6 +136,7 @@ jobs: args: miri test --feature-powerset --optional-deps env: MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-ignore-leaks + RUSTFLAGS: --cfg skip_trybuild valgrind: runs-on: ubuntu-latest @@ -164,6 +165,8 @@ jobs: with: command: hack args: valgrind test --feature-powerset --optional-deps + env: + RUSTFLAGS: --cfg skip_trybuild codecov: runs-on: ubuntu-latest diff --git a/tests/trybuild.rs b/tests/trybuild.rs index b792859f..968edf8f 100644 --- a/tests/trybuild.rs +++ b/tests/trybuild.rs @@ -1,3 +1,5 @@ +#![cfg(not(skip_trybuild))] + macro_rules! trybuild_test { ($test_name:ident) => { #[test] From 1e8dcfa6934d1961fb638db730773166f9642637 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Sat, 19 Feb 2022 22:24:46 -0800 Subject: [PATCH 24/24] Fix environment variable typo. --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 650c9e0f..c805fb10 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -165,8 +165,8 @@ jobs: with: command: hack args: valgrind test --feature-powerset --optional-deps - env: - RUSTFLAGS: --cfg skip_trybuild + env: + RUSTFLAGS: --cfg skip_trybuild codecov: runs-on: ubuntu-latest