@@ -27,6 +27,8 @@ enum Commands {
2727 } ,
2828 /// Checks the Neotron OS source code using clippy
2929 Clippy ,
30+ /// Runs any tests
31+ Test ,
3032}
3133
3234/// A simple utility for building Neotron OS and a suitable ROMFS image
@@ -45,18 +47,21 @@ fn packages() -> Vec<nbuild::Package> {
4547 path: std:: path:: Path :: new( "./nbuild/Cargo.toml" ) ,
4648 output: std:: path:: Path :: new( "./nbuild/target/debug/nbuild{exe}" ) ,
4749 kind: nbuild:: PackageKind :: NBuild ,
50+ testable: true ,
4851 } ,
4952 nbuild:: Package {
5053 name: "flames utility" ,
5154 path: std:: path:: Path :: new( "./utilities/flames/Cargo.toml" ) ,
5255 output: std:: path:: Path :: new( "./target/{target}/{profile}/flames" ) ,
5356 kind: nbuild:: PackageKind :: Utility ,
57+ testable: false ,
5458 } ,
5559 nbuild:: Package {
5660 name: "Neotron OS" ,
5761 path: std:: path:: Path :: new( "./neotron-os/Cargo.toml" ) ,
5862 output: std:: path:: Path :: new( "./target/{target}/{profile}/neotron-os" ) ,
5963 kind: nbuild:: PackageKind :: Os ,
64+ testable: false ,
6065 } ,
6166 ]
6267}
@@ -80,6 +85,7 @@ fn main() {
8085 Some ( Commands :: Libraries { target } ) => library ( & packages, target. as_deref ( ) ) ,
8186 Some ( Commands :: Format { check } ) => format ( & packages, check) ,
8287 Some ( Commands :: Clippy ) => clippy ( & packages) ,
88+ Some ( Commands :: Test ) => test ( & packages) ,
8389 }
8490}
8591
@@ -191,4 +197,19 @@ fn clippy(packages: &[nbuild::Package]) {
191197 }
192198}
193199
200+ /// Runs `cargo test` over all the packages
201+ fn test ( packages : & [ nbuild:: Package ] ) {
202+ let mut is_error = false ;
203+ for package in packages. iter ( ) . filter ( |p| p. testable ) {
204+ println ! ( "Testing {}" , package. name) ;
205+ if let Err ( e) = nbuild:: cargo ( & [ "test" ] , None , package. path ) {
206+ eprintln ! ( "Test failed: {}" , e) ;
207+ is_error = true ;
208+ }
209+ }
210+ if is_error {
211+ std:: process:: exit ( 1 ) ;
212+ }
213+ }
214+
194215// End of file
0 commit comments