11mod config;
22mod logger;
33pub mod rustc;
4+ pub mod rustdoc;
45
56use crate :: rustc:: CrateType ;
67use crate :: rustc:: Edition ;
78use crate :: rustc:: Rustc ;
9+ use crate :: rustdoc:: RustDoc ;
810use config:: Manifest ;
911use logger:: Logger ;
1012use std:: env;
@@ -23,7 +25,7 @@ fn lib_compile(
2325 lib_path : & Path ,
2426 out_dir : & Path ,
2527) -> Result < ( ) > {
26- logger. compiling_crate ( & manifest. crate_name ) ;
28+ logger. compiling_crate ( & manifest. crate_name ) ? ;
2729 Rustc :: builder ( )
2830 . edition ( manifest. edition )
2931 . crate_type ( CrateType :: Lib )
@@ -32,7 +34,6 @@ fn lib_compile(
3234 . lib_dir ( out_dir. clone ( ) )
3335 . done ( )
3436 . run ( lib_path. to_str ( ) . unwrap ( ) ) ?;
35- logger. done_compiling ( ) ;
3637 Ok ( ( ) )
3738}
3839
@@ -43,7 +44,7 @@ fn bin_compile(
4344 out_dir : & Path ,
4445 externs : & [ & str ] ,
4546) -> Result < ( ) > {
46- logger. compiling_bin ( & manifest. crate_name ) ;
47+ logger. compiling_bin ( & manifest. crate_name ) ? ;
4748 let mut builder = Rustc :: builder ( )
4849 . edition ( manifest. edition )
4950 . crate_type ( CrateType :: Bin )
@@ -56,18 +57,15 @@ fn bin_compile(
5657 }
5758
5859 builder. done ( ) . run ( bin_path. to_str ( ) . unwrap ( ) ) ?;
59- logger. done_compiling ( ) ;
6060 Ok ( ( ) )
6161}
6262
6363fn test_compile (
64- logger : & mut Logger ,
6564 manifest : & Manifest ,
6665 bin_path : & Path ,
6766 out_dir : & Path ,
6867 externs : & [ & str ] ,
6968) -> Result < ( ) > {
70- logger. compiling_bin ( & manifest. crate_name ) ;
7169 let mut builder = Rustc :: builder ( )
7270 . edition ( manifest. edition )
7371 . crate_type ( CrateType :: Bin )
@@ -85,7 +83,6 @@ fn test_compile(
8583 }
8684
8785 builder. done ( ) . run ( bin_path. to_str ( ) . unwrap ( ) ) ?;
88- logger. done_compiling ( ) ;
8986 Ok ( ( ) )
9087}
9188
@@ -136,42 +133,51 @@ pub fn build_tests() -> Result<()> {
136133
137134 match ( lib_rs. exists ( ) , main_rs. exists ( ) ) {
138135 ( true , true ) => {
139- test_compile ( & mut logger , & manifest, & lib_rs, & target_tests, & [ ] ) ?;
136+ test_compile ( & manifest, & lib_rs, & target_tests, & [ ] ) ?;
140137 lib_compile ( & mut logger, & manifest, & lib_rs, & target_tests) ?;
141- test_compile (
142- & mut logger,
143- & manifest,
144- & main_rs,
145- & target_tests,
146- & [ & manifest. crate_name ] ,
147- ) ?;
138+ test_compile ( & manifest, & main_rs, & target_tests, & [ & manifest. crate_name ] ) ?;
148139 }
149140 ( true , false ) => {
150- test_compile ( & mut logger , & manifest, & lib_rs, & target_tests, & [ ] ) ?;
141+ test_compile ( & manifest, & lib_rs, & target_tests, & [ ] ) ?;
151142 }
152143 ( false , true ) => {
153- test_compile ( & mut logger , & manifest, & main_rs, & target_tests, & [ ] ) ?;
144+ test_compile ( & manifest, & main_rs, & target_tests, & [ ] ) ?;
154145 }
155146 ( false , false ) => return Err ( "There is nothing to compile" . into ( ) ) ,
156147 }
157148
149+ logger. done_compiling ( ) ?;
158150 Ok ( ( ) )
159151}
160152
161153pub fn run_tests ( test_args : Vec < String > ) -> Result < ( ) > {
162- for item in root_dir ( ) ?
163- . join ( "target" )
164- . join ( "debug" )
165- . join ( "tests" )
166- . read_dir ( ) ?
167- {
154+ let mut logger = Logger :: new ( ) ;
155+ let root = root_dir ( ) ?;
156+ let manifest = Manifest :: parse_from_file ( root. join ( "Freight.toml" ) ) ?;
157+ for item in root. join ( "target" ) . join ( "debug" ) . join ( "tests" ) . read_dir ( ) ? {
168158 let item = item?;
169159 let path = item. path ( ) ;
170160 let is_test = path. extension ( ) . is_none ( ) ;
171161 if is_test {
162+ let file_name = path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
163+ if file_name == "test_freight_main" {
164+ logger. main_unit_test ( ) ?;
165+ } else if file_name == "test_freight_lib" {
166+ logger. lib_unit_test ( ) ?;
167+ }
172168 Command :: new ( path) . args ( & test_args) . spawn ( ) ?. wait ( ) ?;
173169 }
174170 }
171+ let lib = root. join ( "src" ) . join ( "lib.rs" ) ;
172+ if lib. exists ( ) {
173+ logger. doc_test ( & manifest. crate_name ) ?;
174+ RustDoc :: new (
175+ manifest. edition ,
176+ manifest. crate_name ,
177+ root. join ( "target" ) . join ( "debug" ) ,
178+ )
179+ . test ( lib) ?;
180+ }
175181 Ok ( ( ) )
176182}
177183
0 commit comments