()
| 25 | #[test] |
| 26 | fn execute_compiler_test_suite() { |
| 27 | let root = suite_root(); |
| 28 | let mut hll_files = Vec::new(); |
| 29 | collect_hll_files(&root, &mut hll_files); |
| 30 | |
| 31 | // Sort for consistent test execution order |
| 32 | hll_files.sort(); |
| 33 | |
| 34 | let mut tests_run = 0; |
| 35 | let mut pipeline = CompilationPipeline::new(); |
| 36 | pipeline.set_write_artifacts(false); |
| 37 | |
| 38 | pipeline.set_write_artifacts(false); // Don't create gigabytes of files during tests |
| 39 | let update_goldens = golden_support::should_update_goldens("UPDATE_GOLDENS"); |
| 40 | |
| 41 | for path in hll_files { |
| 42 | if path.extension().and_then(|e| e.to_str()) == Some("hll") { |
| 43 | let source = fs::read_to_string(&path) |
| 44 | .unwrap_or_else(|err| panic!("failed to read fixture {path:?}: {err}")); |
| 45 | |
| 46 | // Compile using shared pipeline |
| 47 | let result = pipeline.compile(&source).unwrap_or_else(|e| { |
| 48 | panic!( |
| 49 | "Compilation error in {:?}: {}", |
| 50 | path.file_name().unwrap(), |
| 51 | e |
| 52 | ) |
| 53 | }); |
| 54 | |
| 55 | let actual_ir = format!("{}", result.ir_program) |
| 56 | .replace("\r\n", "\n") |
| 57 | .trim() |
| 58 | .to_string(); |
| 59 | |
| 60 | let ir_path = path.with_extension("ir"); |
| 61 | if update_goldens { |
| 62 | fs::write(&ir_path, &actual_ir).expect("Failed to write golden ir file"); |
| 63 | println!("Updated golden IR file for {:?}", path.file_name().unwrap()); |
| 64 | tests_run += 1; |
| 65 | } else if ir_path.exists() { |
| 66 | let expected_ir = fs::read_to_string(&ir_path) |
| 67 | .unwrap() |
| 68 | .replace("\r\n", "\n") |
| 69 | .trim() |
| 70 | .to_string(); |
| 71 | assert_eq!( |
| 72 | actual_ir, |
| 73 | expected_ir, |
| 74 | "\n=== IR MISMATCH in {:?} ===\nEXPECTED:\n{}\n\nGOT:\n{}\n================\n", |
| 75 | path.file_name().unwrap(), |
| 76 | expected_ir, |
| 77 | actual_ir |
| 78 | ); |
| 79 | tests_run += 1; |
| 80 | } else { |
| 81 | panic!( |
| 82 | "Missing golden IR file for {:?}; rerun with UPDATE_GOLDENS=1 to bootstrap it", |
| 83 | path.file_name().unwrap() |
| 84 | ); |
nothing calls this directly
no test coverage detected