Skip to content

Commit

Permalink
stop after one
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplanelad committed Oct 15, 2024
1 parent 9d7eb8b commit c31a5be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 40 deletions.
59 changes: 20 additions & 39 deletions xtask/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ enum FuzzyCommands {
Scaffold,
}

struct FuzzyResult {
seed: u64,
error: Option<crazy_train::Error>,
}
fn main() -> eyre::Result<()> {
let cli = Cli::parse();
let project_dir = env::current_dir()?;
Expand Down Expand Up @@ -92,48 +88,33 @@ fn main() -> eyre::Result<()> {
seed,
times,
} => {
let mut results: Vec<FuzzyResult> = (1..=times)
.map(|_| {
let randomizer = seed.map_or_else(crazy_train::Randomizer::default, |seed| {
crazy_train::Randomizer::with_seed(seed)
});
let seed = randomizer.seed;
let temp_dir = env::temp_dir().join("loco");

let runner = match command {
FuzzyCommands::GenerateTemplate => {
fuzzy_steps::generate_project::run(randomizer, temp_dir.as_path())
}
FuzzyCommands::Scaffold => {
fuzzy_steps::scaffold::run(randomizer, temp_dir.as_path())
}
};

let result: Result<(), crazy_train::Error> = runner.run();
for _ in 1..=times {
let randomizer = seed.map_or_else(crazy_train::Randomizer::default, |seed| {
crazy_train::Randomizer::with_seed(seed)
});
let seed = randomizer.seed;
let temp_dir = env::temp_dir().join("loco");

if temp_dir.exists() {
std::fs::remove_dir_all(temp_dir).expect("remove dir");
let runner = match command {
FuzzyCommands::GenerateTemplate => {
fuzzy_steps::generate_project::run(randomizer, temp_dir.as_path())
}
FuzzyResult {
seed,
error: result.err(),
FuzzyCommands::Scaffold => {
fuzzy_steps::scaffold::run(randomizer, temp_dir.as_path())
}
})
.collect();
};

results.sort_by(|a, b| a.error.is_some().cmp(&b.error.is_some()));
let result: Result<(), crazy_train::Error> = runner.run();

if temp_dir.exists() {
std::fs::remove_dir_all(temp_dir).expect("remove dir");
}

println!();
println!("====================================");
println!(" Results Summary ");
println!("====================================");
if let Err(err) = result {
println!("seed {seed}");
println!("{err}");

for result in results {
if let Some(err) = result.error {
println!("seed {}: error\n\n {}\n", result.seed, err);
xtask::CmdExit::error_with_message("failed").exit();
} else {
println!("seed {}: passed", result.seed);
}
}

Expand Down
5 changes: 4 additions & 1 deletion xtask/src/fuzzy_steps/generate_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ impl step::StepTrait for GenerateProjectStep {
&self,
execution_result: &executer::Output,
) -> std::result::Result<bool, &'static str> {
let re_invalid_project_name = Regex::new(r"Error: app name is invalid, illegal characters. keep names simple: myapp or my_app\n\nLocation:\n").unwrap();
let re_invalid_project_name = Regex::new(
r"(the first character must be a|characters must be Unicode XID characters|the name cannot start with a digit)",
)
.unwrap();
let re_folder_exists = Regex::new(r"🙀 The specified path '.*.' already exist\n").unwrap();
let re_successfully = Regex::new(r"\n🚂 Loco app generated successfully in:\n.*").unwrap();

Expand Down

0 comments on commit c31a5be

Please sign in to comment.