Debian Codegraph @

debian/rust-vendor/time/tests/integration/main.rs

raw
1 #![allow(missing_docs, reason = "may be removed in the future")]
2 #![allow(
3 clippy::missing_const_for_fn,
4 clippy::std_instead_of_core,
5 clippy::std_instead_of_alloc,
6 clippy::alloc_instead_of_core,
7 reason = "irrelevant for tests"
8 )]
9
10 #[cfg(not(all(
11 feature = "default",
12 feature = "alloc",
13 feature = "formatting",
14 feature = "large-dates",
15 feature = "local-offset",
16 feature = "macros",
17 feature = "parsing",
18 feature = "quickcheck",
19 feature = "serde-human-readable",
20 feature = "serde-well-known",
21 feature = "std",
22 feature = "rand",
23 feature = "serde",
24 )))]
25 #[rstest]
26 fn run_with_all_features() -> Result<(), Box<dyn std::error::Error>> {
27 #[derive(Debug)]
28 struct Error(std::process::ExitStatus);
29
30 impl std::fmt::Display for Error {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 self.0.fmt(f)
33 }
34 }
35
36 impl std::error::Error for Error {}
37
38 let status = std::process::Command::new("cargo")
39 .args(["test", "--all-features"])
40 .status()?;
41
42 return if status.success() {
43 Ok(())
44 } else {
45 Err(Box::new(Error(status)))
46 };
47
48 // Intentionally unreachable. This is to show the user a warning when they don't provide
49 // `--all-features`.
50 "Tests must be run with `--all-features`. Because the flag was not provided, `cargo test \
51 --all-features` is run.";
52 }
53
54 macro_rules! require_all_features {
55 ($($x:item)*) => {$(
56 #[cfg(all(
57 feature = "default",
58 feature = "alloc",
59 feature = "formatting",
60 feature = "large-dates",
61 feature = "local-offset",
62 feature = "macros",
63 feature = "parsing",
64 feature = "quickcheck",
65 feature = "serde-human-readable",
66 feature = "serde-well-known",
67 feature = "std",
68 feature = "rand",
69 feature = "serde",
70 ))]
71 $x
72 )*};
73 }
74
75 require_all_features! {
76 /// `assert_eq!` or `assert_ne!` depending on the value of `$is_eq`.
77 ///
78 /// This provides better diagnostics than `assert_eq!($left == $right, $is_eq)`.
79 macro_rules! assert_eq_ne {
80 ($left:expr, $right:expr, $is_eq:expr $(, $($rest:tt)*)?) => {{
81 if $is_eq {
82 assert_eq!($left, $right $(, $($rest)*)?);
83 } else {
84 assert_ne!($left, $right $(, $($rest)*)?);
85 }
86 }}
87 }
88
89 #[cfg(__ui_tests)]
90 use rstest::rstest;
91
92 mod convert;
93 mod date;
94 mod date_iter;
95 mod month_iter;
96 mod weekday_iter;
97 mod derives;
98 mod duration;
99 mod error;
100 mod ext;
101 mod format_description;
102 mod formatting;
103 mod instant;
104 mod macros;
105 mod meta;
106 mod month;
107 mod offset_date_time;
108 mod parse_format_description;
109 mod parsed;
110 mod parsing;
111 mod plain_date_time;
112 #[path = "quickcheck.rs"]
113 mod quickcheck_mod;
114 mod rand;
115 mod serde;
116 mod serde_helpers;
117 mod time;
118 mod timestamp;
119 mod utc_date_time;
120 mod utc_offset;
121 mod util;
122 mod weekday;
123
124 #[cfg(__ui_tests)]
125 #[rstest]
126 fn compile_fail() {
127 let tests = trybuild::TestCases::new();
128 // Path is relative from `time/Cargo.toml`.
129 tests.compile_fail("./tests/integration/compile-fail/*.rs");
130 }
131 }