Debian Codegraph @

debian/missing-sources/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 #[test]
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 that the given expression panics.
77 macro_rules! assert_panic {
78 ($($x:tt)*) => {
79 assert!(std::panic::catch_unwind(|| {
80 $($x)*
81 })
82 .is_err())
83 }
84 }
85
86 /// `assert_eq!` or `assert_ne!` depending on the value of `$is_eq`.
87 ///
88 /// This provides better diagnostics than `assert_eq!($left == $right, $is_eq)`.
89 macro_rules! assert_eq_ne {
90 ($left:expr, $right:expr, $is_eq:expr $(, $($rest:tt)*)?) => {{
91 if $is_eq {
92 assert_eq!($left, $right $(, $($rest)*)?);
93 } else {
94 assert_ne!($left, $right $(, $($rest)*)?);
95 }
96 }}
97 }
98
99 mod convert;
100 mod date;
101 mod derives;
102 mod duration;
103 mod error;
104 mod ext;
105 mod format_description;
106 mod formatting;
107 mod instant;
108 mod macros;
109 mod meta;
110 mod month;
111 mod offset_date_time;
112 mod parse_format_description;
113 mod parsed;
114 mod parsing;
115 mod primitive_date_time;
116 #[path = "quickcheck.rs"]
117 mod quickcheck_mod;
118 mod rand;
119 mod serde;
120 mod serde_helpers;
121 mod time;
122 mod utc_date_time;
123 mod utc_offset;
124 mod util;
125 mod weekday;
126
127 #[cfg(__ui_tests)]
128 #[test]
129 fn compile_fail() {
130 let tests = trybuild::TestCases::new();
131 // Path is relative from `time/Cargo.toml`.
132 tests.compile_fail("./tests/integration/compile-fail/*.rs");
133 }
134 }