rmv_bevy_testing_tools/
lib.rs1#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
2
3#[allow(dead_code)]
6mod deprecated {
7 use konst::{iter, result, string};
8 use static_assertions::const_assert_eq;
9 const VERSION: [u32; 3] = iter::collect_const!(u32 =>
10 string::split(env!("CARGO_PKG_VERSION"), "."),
11 map(|s| result::unwrap!(u32::from_str_radix(s, 10))));
12 const MAJOR: u32 = VERSION[0];
13 const MINOR: u32 = VERSION[1];
14 const PATCH: u32 = VERSION[2];
15 const_assert_eq!(MAJOR, 0);
16}
17
18#[cfg(feature = "speculoos")]
19pub(crate) mod assertions;
20#[cfg(any(test, feature = "rstest"))]
21pub(crate) mod fixtures;
22#[cfg(any(all(test, feature = "rstest"), feature = "trait_collect_messages"))]
23pub(crate) mod messages;
24#[allow(unused_imports)] pub(crate) mod test_app;
26pub(crate) mod traits;
27
28#[cfg(feature = "insta")]
29#[macro_export]
30macro_rules! set_snapshot_suffix {
31 ($($expr:expr),*) => {
32 let mut settings = insta::Settings::clone_current();
33 settings.set_snapshot_suffix(format!($($expr,)*));
34 let _guard = settings.bind_to_scope();
35 }
36}
37
38pub mod prelude {
39 #[cfg(feature = "speculoos")]
40 pub use super::assertions::*;
41 #[cfg(any(test, feature = "rstest"))]
42 pub use super::fixtures::*;
43 #[cfg(feature = "trait_collect_messages")]
44 pub use super::messages::*;
45 #[cfg(feature = "insta")]
46 pub use super::set_snapshot_suffix;
47 pub use super::test_app::*;
48 #[allow(unused_imports)]
49 pub use super::traits::*;
50}
51
52#[doc = include_str!("../Readme.md")]
53#[cfg(doctest)]
54pub struct ReadmeDoctests;
55
56#[cfg(test)]
57#[cfg_attr(coverage_nightly, coverage(off))]
58mod tests {
59 #[allow(unused_imports)]
60 use rstest::rstest;
61
62 #[cfg(feature = "rstest")]
63 use crate::prelude::{TestApp, test_app};
64
65 #[cfg(feature = "rstest")]
66 #[rstest]
67 fn with_rstest_fixtures(#[from(test_app)] mut app: TestApp) {
68 if skip_feature_test_body() {
70 return;
71 }
72
73 use bevy_app::AppExit;
74
75 use crate::prelude::{CollectMessages, WriteMessages};
76
77 app.collect_messages::<AppExit>()
78 .write_message_default::<AppExit>();
79 }
80
81 #[cfg(feature = "insta")]
82 #[rstest]
83 fn can_access_insta_macro() {
84 if skip_feature_test_body() {
86 return;
87 }
88
89 set_snapshot_suffix!("works");
90 }
91
92 #[cfg(feature = "speculoos")]
93 #[rstest]
94 fn can_access_assertions() {
95 if skip_feature_test_body() {
97 return;
98 }
99
100 use speculoos::assert_that;
101
102 use crate::prelude::IsContainedIn;
103
104 let items = vec![1, 2, 3];
105 assert_that!(1).is_contained_in(&items);
106 }
107
108 #[ignore = "fix immediate_query.rs"]
109 #[cfg(feature = "itertools")]
110 #[rstest]
111 fn can_access_query_vec() {
112 if skip_feature_test_body() {
114 return;
115 }
116
117 }
122
123 #[allow(dead_code)]
124 fn skip_feature_test_body() -> bool {
125 std::env::var("_SKIP_FEATURE_TESTS_")
128 .map(|s| matches!(s.as_str(), "true" | "1"))
129 .unwrap_or(true)
130 }
131}