diff --git a/framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs b/framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs index 521dd148fe..a6da013a00 100644 --- a/framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs +++ b/framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs @@ -28,6 +28,7 @@ pub fn perform_test_gen_all(path: impl AsRef, ignore: &[String], create: b fn perform_test_gen(contract_dir: &RelevantDirectory, create: bool) { let contract_dir_path = &contract_dir.path; + let scenarios_dir = contract_dir_path.join(SCENARIOS_DIR_NAME); if !scenarios_dir.is_dir() { print_no_folder(contract_dir_path, SCENARIOS_DIR_NAME); @@ -88,9 +89,11 @@ struct ProcessFileContext<'a> { } fn process_file(config: ProcessFileConfig, context: ProcessFileContext) { - let existing_file_path = find_test_file(context.test_dir, config.suffix); + let suffix = config.suffix; + let existing_file_path = find_test_file(context.test_dir, suffix); if existing_file_path.is_none() && !context.create_flag { + print_no_file(suffix); return; } @@ -113,8 +116,13 @@ fn process_file(config: ProcessFileConfig, context: ProcessFileContext) { let file_name = format!("{}_{}", context.crate_name, config.suffix); context.test_dir.join(file_name) }; - let mut file = File::create(file_path).unwrap(); + + let mut file = File::create(&file_path).unwrap(); write!(file, "{new_code}").unwrap(); + + if existing_file_path.is_none() && context.create_flag { + print_new_file(&file_path); + } } fn find_test_file(test_dir: &Path, suffix: &str) -> Option { diff --git a/framework/meta/src/cmd/standalone/scen_test_gen/stg_print.rs b/framework/meta/src/cmd/standalone/scen_test_gen/stg_print.rs index 0b14a15d23..23add8d3cd 100644 --- a/framework/meta/src/cmd/standalone/scen_test_gen/stg_print.rs +++ b/framework/meta/src/cmd/standalone/scen_test_gen/stg_print.rs @@ -23,3 +23,19 @@ pub fn print_processing(test_file_path: &Path) { .green() ); } + +pub fn print_no_file(suffix: &str) { + println!( + "{}", format!( + "No file ending in *_{suffix} found. Use the --create flag to create a new {suffix} file.", + ) + .yellow() + ); +} + +pub fn print_new_file(file_path: &Path) { + println!( + "{}", + format!("File {} has been created", file_path.display()).green() + ); +}