• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 //! rust unittest build
16 
17 /// pub add
add(a: i32, b: i32) -> i3218 pub fn add(a: i32, b: i32) -> i32 {
19     a + b
20 }
21 
22 // This is a really bad adding function, its purpose is to fail in this
23 // example.
24 #[allow(dead_code)]
bad_add(a: i32, b: i32) -> i3225 fn bad_add(a: i32, b: i32) -> i32 {
26     a - b
27 }
28 
29 #[cfg(test)]
30 mod tests {
31     // Note this useful idiom: importing names from outer (for mod tests) scope.
32     use super::*;
33 
34     #[test]
test_add()35     fn test_add() {
36         assert_eq!(add(1, 2), 3);
37     }
38 
39     #[test]
test_bad_add()40     fn test_bad_add() {
41         // This assert would fire and test will fail.
42         // Please note, that private functions can be tested too!
43         assert_eq!(bad_add(1, 2), 3);
44     }
45 }
46