File tree 4 files changed +78
-0
lines changed
4 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ load ("//cargo:cargo_build_script.bzl" , "cargo_build_script" )
2
+ load ("//rust:defs.bzl" , "rust_test_suite" )
3
+ load (
4
+ "//rust:rust.bzl" ,
5
+ "rust_library" ,
6
+ "rust_test" ,
7
+ )
8
+
9
+ cargo_build_script (
10
+ name = "build_script" ,
11
+ srcs = ["build.rs" ],
12
+ )
13
+
14
+ rust_library (
15
+ name = "demo_lib" ,
16
+ srcs = [
17
+ "src/lib.rs" ,
18
+ ],
19
+ deps = [":build_script" ],
20
+ )
21
+
22
+ rust_test (
23
+ name = "demo_lib_test" ,
24
+ crate = ":demo_lib" ,
25
+ )
26
+
27
+ rust_test_suite (
28
+ name = "suite" ,
29
+ srcs = glob (["tests/**" ]),
30
+ # Add the 'crate' argument, which will be passed as a kwarg
31
+ # to the underlying rust_test rules. This will make OUT_DIR
32
+ # available when compiling integration tests.
33
+ crate = ":demo_lib" ,
34
+ )
Original file line number Diff line number Diff line change
1
+ use std:: env;
2
+ use std:: fs:: File ;
3
+ use std:: io:: prelude:: * ;
4
+ use std:: path:: PathBuf ;
5
+
6
+ fn main ( ) -> std:: io:: Result < ( ) > {
7
+ let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
8
+ let mut file = File :: create ( out_path. join ( "test_content.txt" ) ) ?;
9
+ file. write_all ( b"Test content" ) ?;
10
+ Ok ( ( ) )
11
+ }
Original file line number Diff line number Diff line change
1
+ #[ cfg( test) ]
2
+ mod tests {
3
+ use std:: env;
4
+
5
+ #[ test]
6
+ fn can_find_the_out_dir_file ( ) {
7
+ // The file contents must be included via a macro.
8
+ let contents = include_str ! ( concat!( env!( "OUT_DIR" ) , "/test_content.txt" ) ) ;
9
+ assert_eq ! ( "Test content" , contents) ;
10
+ }
11
+
12
+ #[ test]
13
+ fn no_out_dir_at_runtime ( ) {
14
+ // Cargo seems to set this at runtime as well, although the documentation
15
+ // says it's only available at compile time.
16
+ assert ! ( env:: var( "OUT_DIR" ) . is_err( ) ) ;
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ use std:: env;
2
+
3
+ #[ test]
4
+ fn can_find_the_out_dir_file ( ) {
5
+ // The file contents must be included via a macro.
6
+ let contents = include_str ! ( concat!( env!( "OUT_DIR" ) , "/test_content.txt" ) ) ;
7
+ assert_eq ! ( "Test content" , contents) ;
8
+ }
9
+
10
+ #[ test]
11
+ fn no_out_dir_at_runtime ( ) {
12
+ // Cargo seems to set this at runtime as well, although the documentation
13
+ // says it's only available at compile time.
14
+ assert ! ( env:: var( "OUT_DIR" ) . is_err( ) ) ;
15
+ }
You can’t perform that action at this time.
0 commit comments