@@ -34,32 +34,28 @@ fn generate_code_test_utils() -> Result<(), Box<dyn Error>> {
34
34
fs:: create_dir ( & out_dir) ?;
35
35
}
36
36
37
- let input = fs :: read_to_string ( "src/test_utils/common.rs" ) ?;
37
+ let input = read_code ( "src/test_utils/common.rs" ) ?;
38
38
39
- write_generated_code (
39
+ fs :: write (
40
40
out_dir. join ( "common_for_doc_test.rs" ) ,
41
41
format ! ( "mod test_utils {{\n {}\n }}" , input)
42
42
. lines ( )
43
43
. map ( |line| format ! ( "# {}\n " , line) )
44
44
. collect :: < String > ( ) ,
45
45
) ?;
46
- write_generated_code (
46
+ fs :: write (
47
47
out_dir. join ( "common_for_integration_test.rs" ) ,
48
48
format ! ( "#[allow(dead_code)]\n mod test_utils {{\n {}\n }}" , input) ,
49
49
) ?;
50
- write_generated_code (
50
+ fs :: write (
51
51
out_dir. join ( "common_for_unit_test.rs" ) ,
52
52
input. replace ( "spdlog::" , "crate::" ) ,
53
53
) ?;
54
54
55
55
Ok ( ( ) )
56
56
}
57
57
58
- fn write_generated_code (
59
- path : impl AsRef < Path > ,
60
- contents : impl AsRef < [ u8 ] > ,
61
- ) -> Result < ( ) , Box < dyn Error > > {
58
+ fn read_code ( path : impl AsRef < Path > ) -> Result < String , Box < dyn Error > > {
62
59
println ! ( "cargo:rerun-if-changed={}" , path. as_ref( ) . display( ) ) ;
63
- fs:: write ( path, contents) ?;
64
- Ok ( ( ) )
60
+ Ok ( fs:: read_to_string ( path) ?)
65
61
}
0 commit comments