1.9 KiB
1.9 KiB
Test Conversion Guide: compile! { debug } to compile! { check }
Overview
The compile! { check ... } macro variant returns a CompilationCheckResult with both compilation errors and the compiled output. This allows tests to assert that no compilation errors occurred while also checking the output.
Pattern
Before (using debug):
#[test]
fn my_test() -> anyhow::Result<()> {
let compiled = compile! {
debug "
let x = 42;
"
};
assert_eq!(
compiled,
indoc! {
"
j main
main:
move r8 42
"
}
);
Ok(())
}
After (using check):
#[test]
fn my_test() -> anyhow::Result<()> {
let result = compile! {
check "
let x = 42;
"
};
assert!(result.errors.is_empty(), "Expected no errors, got: {:?}", result.errors);
assert_eq!(
result.output,
indoc! {
"
j main
main:
move r8 42
"
}
);
Ok(())
}
Key Changes
- Variable name: Change
let compiled =tolet result = - Macro variant: Change
debugtocheck - Add error assertion: Insert
assert!(result.errors.is_empty(), ...);after the compile block - Update assertion target: Change
compiledtoresult.outputin the assert_eq!
Multi-line format
When using multi-line source code in the macro:
let result = compile! {
check
"
let x = 10;
let y = 20;
"
};
assert!(result.errors.is_empty(), "Expected no errors, got: {:?}", result.errors);
assert_eq!(
result.output,
indoc! {
"
j main
main:
move r8 10
move r9 20
"
}
);
Status
- ✅
declaration_literal.rs- Fully converted (7 tests) - ⏳ Other files - Pending conversion
To convert a file, replace all occurrences following the pattern above.