Skip to content

Commit ba61471

Browse files
committed
fix: make runall executable path resolution fallback more robust
1 parent 3c9b3b3 commit ba61471

1 file changed

Lines changed: 38 additions & 17 deletions

File tree

src/main.rs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,21 @@ fn run_all_tests() -> Result<()> {
811811
("multi", vec!["--multi", "src", "."])
812812
];
813813

814-
let mut report_file = File::create("output/codestate_runall_report.txt")?;
814+
let mut report_file = File::create("codestate_runall_report.txt")?;
815815
writeln!(report_file, "CodeState --runall Test Report\n")?;
816816

817-
let exe_path = env::current_exe()?;
817+
// Try to get the current executable path, fallback to "codestate"
818+
let exe_path = match env::current_exe() {
819+
Ok(path) => path.to_string_lossy().to_string(),
820+
Err(_) => {
821+
if cfg!(windows) {
822+
".\\codestate.exe".to_string()
823+
} else {
824+
"./codestate".to_string()
825+
}
826+
}
827+
};
828+
818829
let total_tests = flags.len();
819830
let mut success_count = 0;
820831
let mut fail_count = 0;
@@ -830,21 +841,31 @@ fn run_all_tests() -> Result<()> {
830841
let mut cmd = Command::new(&exe_path);
831842
cmd.args(flag_args);
832843

833-
let output = cmd.output()?;
834-
let stdout = String::from_utf8_lossy(&output.stdout);
835-
let stderr = String::from_utf8_lossy(&output.stderr);
836-
837-
writeln!(report_file, "{}", stdout)?;
838-
if !stderr.is_empty() {
839-
writeln!(report_file, "\n[STDERR]\n{}", stderr)?;
840-
}
841-
writeln!(report_file, "\n\n")?;
844+
match cmd.output() {
845+
Ok(output) => {
846+
let stdout = String::from_utf8_lossy(&output.stdout);
847+
let stderr = String::from_utf8_lossy(&output.stderr);
848+
849+
writeln!(report_file, "{}", stdout)?;
850+
if !stderr.is_empty() {
851+
writeln!(report_file, "\n[STDERR]\n{}", stderr)?;
852+
}
853+
writeln!(report_file, "\n\n")?;
842854

843-
if output.status.success() {
844-
success_count += 1;
845-
} else {
846-
fail_count += 1;
847-
failed_tests.push(flag_name);
855+
if output.status.success() {
856+
success_count += 1;
857+
} else {
858+
fail_count += 1;
859+
failed_tests.push(flag_name);
860+
}
861+
},
862+
Err(e) => {
863+
// If it fails to execute the process, don't crash, just log and continue
864+
let err_msg = format!("Failed to execute process: {}", e);
865+
writeln!(report_file, "{}\n\n", err_msg)?;
866+
fail_count += 1;
867+
failed_tests.push(flag_name);
868+
}
848869
}
849870
}
850871

@@ -857,7 +878,7 @@ fn run_all_tests() -> Result<()> {
857878
println!("Failed: {}", fail_count);
858879
println!("Success Rate: {:.2}%", success_rate);
859880
println!("Time taken: {:?}", test_elapsed);
860-
println!("Details saved to output/codestate_runall_report.txt");
881+
println!("Details saved to codestate_runall_report.txt");
861882

862883
if fail_count > 0 {
863884
println!("\nFailed Tests:");

0 commit comments

Comments
 (0)