11use assert_cmd:: { Command as AssertCommand , cargo:: * } ;
22use predicates:: prelude:: * ;
3- use std:: { path:: Path , process:: Command } ;
3+ use std:: { path:: Path , process:: Command , sync:: OnceLock } ;
4+
5+ static LOGGER_INIT : OnceLock < ( ) > = OnceLock :: new ( ) ;
6+
7+ fn setup_logging ( ) {
8+ LOGGER_INIT . get_or_init ( || {
9+ env_logger:: builder ( ) . is_test ( true ) . init ( ) ;
10+ } ) ;
11+ }
412
513fn run_example_test (
614 example_name : & str ,
715 stdin : Option < & str > ,
816) -> Result < ( ) , Box < dyn std:: error:: Error > > {
17+ setup_logging ( ) ;
918 let manifest_dir = std:: env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ;
1019 let workspace_root = Path :: new ( & manifest_dir) . parent ( ) . unwrap ( ) ;
1120
1221 let examples_dir = Path :: new ( "examples" ) ;
1322 let example_file = examples_dir. join ( format ! ( "{}.kit" , example_name) ) ;
1423 let expected_file = examples_dir. join ( format ! ( "{}.kit.expected" , example_name) ) ;
1524
25+ log:: info!(
26+ "Running example {} in {} (path: {}). Expected file is at {}" ,
27+ example_name,
28+ workspace_root. display( ) ,
29+ example_file. display( ) ,
30+ expected_file. display( )
31+ ) ;
32+
1633 let source_path = workspace_root. join ( example_file) ;
1734 let c_path = source_path. with_extension ( "c" ) ;
1835 let executable_path = source_path. with_extension ( "" ) ;
1936
2037 // Compile the example
21- let mut cmd = AssertCommand :: from_std ( Command :: new ( cargo_bin ! ( "kitc" ) ) ) ;
38+ let kitc = cargo_bin ! ( "kitc" ) ;
39+ log:: info!( "kitc path: {}" , kitc. display( ) ) ;
40+ let mut cmd = AssertCommand :: from_std ( Command :: new ( kitc) ) ;
2241
2342 // Run from workspace root
2443 cmd. current_dir ( workspace_root) ;
@@ -31,7 +50,9 @@ fn run_example_test(
3150 compiled_cmd. write_stdin ( stdin_data) ;
3251 }
3352
34- let expected_output = std:: fs:: read_to_string ( workspace_root. join ( expected_file) ) ?;
53+ let asjdlksaj = workspace_root. join ( expected_file) ;
54+ log:: info!( "Expected output: {}" , asjdlksaj. display( ) ) ;
55+ let expected_output = std:: fs:: read_to_string ( asjdlksaj) ?;
3556
3657 // Assert the output
3758 compiled_cmd
@@ -40,12 +61,17 @@ fn run_example_test(
4061 . success ( ) ;
4162
4263 // Clean up the executable and .c file
43- std:: fs:: remove_file ( & executable_path) ?;
44- std:: fs:: remove_file ( & c_path) ?;
64+ if let Err ( err) = std:: fs:: remove_file ( & executable_path) {
65+ log:: error!( "Failed to remove executable: {err}" ) ;
66+ }
67+ if let Err ( err) = std:: fs:: remove_file ( & c_path) {
68+ log:: error!( "Failed to remove C source file: {err}" ) ;
69+ }
4570
4671 Ok ( ( ) )
4772}
4873
74+
4975#[ test]
5076fn test_helloworld ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
5177 run_example_test ( "helloworld" , None )
0 commit comments