• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 include!(concat!(env!("OUT_DIR"), "/generated/generated.rs"));
6 
say_hello_from_crate()7 pub fn say_hello_from_crate() {
8     assert_eq!(run_some_generated_code(), 42);
9     #[cfg(is_new_rustc)]
10     println!("Is new rustc!");
11     #[cfg(is_old_rustc)]
12     println!("Is old rustc!");
13     #[cfg(is_android)]
14     println!("Is android!");
15     #[cfg(is_mac)]
16     println!("Is darwin!");
17     #[cfg(has_feature_a)]
18     println!("Has feature A!");
19     #[cfg(not(has_feature_a))]
20     panic!("Wasn't passed feature a");
21     #[cfg(not(has_feature_b))]
22     #[cfg(test_a_and_b)]
23     panic!("Wasn't passed feature b");
24     #[cfg(has_feature_b)]
25     #[cfg(not(test_a_and_b))]
26     panic!("Was passed feature b");
27 }
28 
29 #[cfg(test)]
30 mod tests {
31     /// Test features are passed through from BUILD.gn correctly. This test is
32     /// the target1 configuration.
33     #[test]
34     #[cfg(test_a_and_b)]
test_features_passed_target1()35     fn test_features_passed_target1() {
36         #[cfg(not(has_feature_a))]
37         panic!("Wasn't passed feature a");
38         #[cfg(not(has_feature_b))]
39         panic!("Wasn't passed feature b");
40     }
41 
42     /// This tests the target2 configuration is passed through correctly.
43     #[test]
44     #[cfg(not(test_a_and_b))]
test_features_passed_target2()45     fn test_features_passed_target2() {
46         #[cfg(not(has_feature_a))]
47         panic!("Wasn't passed feature a");
48         #[cfg(has_feature_b)]
49         panic!("Was passed feature b");
50     }
51 
52     #[test]
test_generated_code_works()53     fn test_generated_code_works() {
54         assert_eq!(crate::run_some_generated_code(), 42);
55     }
56 }
57