@@ -685,7 +685,7 @@ impl TestData {
685685 fs_err:: create_dir_all ( & application_src_dir) . context (
686686 "Failed to create the runtime directory for the generated application when setting up the test runtime environment" ,
687687 ) ?;
688- persist_if_changed ( & application_src_dir. join ( "lib.rs" ) , b"" ) ?;
688+ create_file_if_missing ( & application_src_dir. join ( "lib.rs" ) , b"" ) ?;
689689
690690 let mut cargo_toml = toml ! {
691691 [ package]
@@ -700,8 +700,8 @@ impl TestData {
700700 cargo_toml[ "package" ] [ "name" ] = format ! ( "application_{}" , self . name_hash) . into ( ) ;
701701 cargo_toml[ "package" ] [ "metadata" ] [ "px" ] [ "generate" ] [ "generator_name" ] =
702702 format ! ( "app_{}" , self . name_hash) . into ( ) ;
703- persist_if_changed (
704- & application_dir . join ( "Cargo.toml" ) ,
703+ create_file_if_missing (
704+ & application_src_dir . join ( "Cargo.toml" ) ,
705705 toml:: to_string ( & cargo_toml) ?. as_bytes ( ) ,
706706 ) ?;
707707 }
@@ -1024,3 +1024,16 @@ fn enrich_failure_message(config: &TestConfig, error: impl AsRef<str>) -> String
10241024 style( "What went wrong:" ) . red( ) . bold( ) ,
10251025 )
10261026}
1027+
1028+ fn create_file_if_missing ( path : & Path , content : & [ u8 ] ) -> Result < ( ) , anyhow:: Error > {
1029+ if !path. exists ( ) {
1030+ if let Some ( parent) = path. parent ( ) {
1031+ fs_err:: create_dir_all ( parent) . with_context ( || {
1032+ format ! ( "Failed to create parent directories for {}" , path. display( ) )
1033+ } ) ?;
1034+ }
1035+ fs_err:: write ( path, content)
1036+ . with_context ( || format ! ( "Failed to create file at {}" , path. display( ) ) ) ?;
1037+ }
1038+ Ok ( ( ) )
1039+ }
0 commit comments