1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15//! test_rlib_cargo_crate
16include!(concat!(env!("OUT_DIR"), "/generated/generated.rs"));
17
18/// say_hello_from_crate
19pub fn say_hello_from_crate() {
20    assert_eq!(run_some_generated_code(), 45);
21    #[cfg(is_new_rustc)]
22    println!("Is new rustc");
23    #[cfg(is_old_rustc)]
24    println!("Is old rustc");
25    #[cfg(is_ohos)]
26    println!("Is ohos");
27    #[cfg(is_mac)]
28    println!("Is darwin");
29    #[cfg(has_feature_a)]
30    println!("Has feature_a");
31    #[cfg(not(has_feature_a))]
32    panic!("Wasn't passed feature_a");
33    #[cfg(not(has_feature_b))]
34    #[cfg(test_a_and_b)]
35    panic!("feature_b wasn't passed");
36    #[cfg(has_feature_b)]
37    #[cfg(not(test_a_and_b))]
38    panic!("feature_b was passed");
39}
40
41#[cfg(test)]
42mod tests {
43    /// Test features are passed through from BUILD.gn correctly. This test is the target configuration.
44    #[test]
45    #[cfg(test_a_and_b)]
46    fn test_features_passed_target1() {
47        #[cfg(not(has_feature_a))]
48        panic!("feature a was not passed");
49        #[cfg(not(has_feature_b))]
50        panic!("feature b was not passed");
51    }
52
53    #[test]
54    fn test_generated_code_works() {
55        assert_eq!(crate::run_some_generated_code(), 45);
56    }
57}
58