Skip to content

Commit

Permalink
Refactor test framework code.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdwalters committed Dec 16, 2024
1 parent b71bda7 commit e11415f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,14 @@ fn extract_output(code: impl Into<String>) -> String {
pub fn script_test(input: &str, target: TestOutcomeTarget) {
let code = fs::read_to_string(input)
.unwrap_or_else(|_| panic!("Failed to open {input} test file"));

// Extract output from script comment.
let mut output = extract_output(&code);

// If output is not in comment, try to read from .output.txt file.
if output.is_empty() {
let output_path = PathBuf::from(input.replace(".ab", ".output.txt"));
output = if output_path.exists() {
fs::read_to_string(output_path)
.unwrap_or_else(|_| panic!("Failed to open {input}.output.txt file"))
let path = PathBuf::from(input.replace(".ab", ".output.txt"));
output = if path.exists() {
fs::read_to_string(&path)
.unwrap_or_else(|_| panic!("Failed to open {} test file", path.display()))
} else {
SUCCEEDED.to_string()
};
Expand Down

0 comments on commit e11415f

Please sign in to comment.