@@ -5,7 +5,7 @@ you have to do is mark a function as a test and include some asserts like so:
5
5
``` rust,ignore
6
6
#[test]
7
7
fn my_test() {
8
- assert!(2+2 == 4);
8
+ assert!(2+2 == 4);
9
9
}
10
10
```
11
11
@@ -16,14 +16,15 @@ can even put tests inside private modules:
16
16
17
17
``` rust,ignore
18
18
mod my_priv_mod {
19
- fn my_priv_func() -> bool {}
19
+ fn my_priv_func() -> bool {}
20
20
21
- #[test]
22
- fn test_priv_func() {
23
- assert!(my_priv_func());
24
- }
21
+ #[test]
22
+ fn test_priv_func() {
23
+ assert!(my_priv_func());
24
+ }
25
25
}
26
26
```
27
+
27
28
Private items can thus be easily tested without worrying about how to expose
28
29
them to any sort of external testing apparatus. This is key to the
29
30
ergonomics of testing in Rust. Semantically, however, it's rather odd.
@@ -44,15 +45,15 @@ the above example into:
44
45
45
46
``` rust,ignore
46
47
mod my_priv_mod {
47
- fn my_priv_func() -> bool {}
48
+ fn my_priv_func() -> bool {}
48
49
49
- pub fn test_priv_func() {
50
- assert!(my_priv_func());
51
- }
50
+ pub fn test_priv_func() {
51
+ assert!(my_priv_func());
52
+ }
52
53
53
- pub mod __test_reexports {
54
- pub use super::test_priv_func;
55
- }
54
+ pub mod __test_reexports {
55
+ pub use super::test_priv_func;
56
+ }
56
57
}
57
58
```
58
59
@@ -83,8 +84,8 @@ something with them. `librustc_ast` generates a module like so:
83
84
``` rust,ignore
84
85
#[main]
85
86
pub fn main() {
86
- extern crate test;
87
- test::test_main_static(&[&path::to::test1, /*...*/]);
87
+ extern crate test;
88
+ test::test_main_static(&[&path::to::test1, /*...*/]);
88
89
}
89
90
```
90
91
@@ -108,7 +109,7 @@ looks something like this:
108
109
#[test]
109
110
#[should_panic]
110
111
fn foo() {
111
- panic!("intentional");
112
+ panic!("intentional");
112
113
}
113
114
```
114
115
0 commit comments