1 //! A small test library for ensuring `--stamp` data is correctly set at compile time.
2
build_timestamp() -> &'static str3 pub fn build_timestamp() -> &'static str {
4 env!("BUILD_TIMESTAMP")
5 }
6
build_user() -> &'static str7 pub fn build_user() -> &'static str {
8 env!("BUILD_USER")
9 }
10
11 #[cfg(test)]
12 mod test {
13 use super::*;
14
15 #[cfg(any(
16 feature = "always_stamp",
17 feature = "consult_cmdline_value_is_true",
18 feature = "always_stamp_build_flag_true",
19 feature = "always_stamp_build_flag_false"
20 ))]
21 #[test]
stamp_resolved_for_library()22 fn stamp_resolved_for_library() {
23 assert!(!build_timestamp().contains("BUILD_TIMESTAMP"));
24 assert!(build_timestamp().chars().all(char::is_numeric));
25
26 assert!(!build_user().contains("BUILD_USER"));
27 }
28
29 #[cfg(any(
30 feature = "always_stamp",
31 feature = "consult_cmdline_value_is_true",
32 feature = "always_stamp_build_flag_true",
33 feature = "always_stamp_build_flag_false"
34 ))]
35 #[test]
stamp_resolved_for_test()36 fn stamp_resolved_for_test() {
37 assert!(!env!("BUILD_TIMESTAMP").contains("BUILD_TIMESTAMP"));
38 assert!(env!("BUILD_TIMESTAMP").chars().all(char::is_numeric));
39
40 assert!(!env!("BUILD_USER").contains("BUILD_USER"));
41 }
42
43 #[cfg(any(
44 feature = "never_stamp",
45 feature = "consult_cmdline_value_is_false",
46 feature = "never_stamp_build_flag_true",
47 feature = "never_stamp_build_flag_false"
48 ))]
49 #[test]
stamp_not_resolved_for_library()50 fn stamp_not_resolved_for_library() {
51 assert!(build_timestamp().contains("BUILD_TIMESTAMP"));
52 assert!(build_user().contains("BUILD_USER"));
53 }
54
55 #[cfg(any(
56 feature = "never_stamp",
57 feature = "consult_cmdline_value_is_false",
58 feature = "never_stamp_build_flag_true",
59 feature = "never_stamp_build_flag_false"
60 ))]
61 #[test]
stamp_not_resolved_for_test()62 fn stamp_not_resolved_for_test() {
63 assert!(env!("BUILD_TIMESTAMP").contains("BUILD_TIMESTAMP"));
64 assert!(env!("BUILD_USER").contains("BUILD_USER"));
65 }
66 }
67