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