Skip to content

Commit

Permalink
added no file and new file logs for test-gen in meta crate
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca committed Oct 10, 2023
1 parent 229dea7 commit 806dab2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 9 additions & 2 deletions framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{
path::{Path, PathBuf},
};

use colored::Colorize;

Check failure on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Template tool test - released templates

unused import: `colored::Colorize`

Check failure on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Template tool test - current (unreleased) templates

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / Contracts / Rust tests

unused import: `colored::Colorize`

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs#L8

warning: unused import: `colored::Colorize` --> framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs:8:5 | 8 | use colored::Colorize; | ^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
Raw output
framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs:8:5:w:warning: unused import: `colored::Colorize`
 --> framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs:8:5
  |
8 | use colored::Colorize;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default


__END__

Check warning on line 8 in framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs#L8

warning: unused import: `colored::Colorize` --> framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs:8:5 | 8 | use colored::Colorize; | ^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
Raw output
framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs:8:5:w:warning: unused import: `colored::Colorize`
 --> framework/meta/src/cmd/standalone/scen_test_gen/stg_main.rs:8:5
  |
8 | use colored::Colorize;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default


__END__

use crate::folder_structure::{RelevantDirectories, RelevantDirectory};

use super::{
Expand All @@ -28,6 +30,7 @@ pub fn perform_test_gen_all(path: impl AsRef<Path>, 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);
Expand Down Expand Up @@ -88,9 +91,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;
}

Expand All @@ -113,8 +118,10 @@ 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.clone()).unwrap();
write!(file, "{new_code}").unwrap();
print_new_file(&file_path);
}

fn find_test_file(test_dir: &Path, suffix: &str) -> Option<PathBuf> {
Expand Down
16 changes: 16 additions & 0 deletions framework/meta/src/cmd/standalone/scen_test_gen/stg_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)
.bright_red()
);
}

pub fn print_new_file(file_path: &Path) {
println!(
"{}",
format!("File {} has been created", file_path.display()).green()
);
}

0 comments on commit 806dab2

Please sign in to comment.