diff --git a/TEST_CONVERSION_GUIDE.md b/TEST_CONVERSION_GUIDE.md deleted file mode 100644 index ef3c8cb..0000000 --- a/TEST_CONVERSION_GUIDE.md +++ /dev/null @@ -1,103 +0,0 @@ -# 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`): - -```rust -#[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`): - -```rust -#[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 - -1. **Variable name**: Change `let compiled =` to `let result =` -2. **Macro variant**: Change `debug` to `check` -3. **Add error assertion**: Insert `assert!(result.errors.is_empty(), ...);` after the compile block -4. **Update assertion target**: Change `compiled` to `result.output` in the assert_eq! - -## Multi-line format - -When using multi-line source code in the macro: - -```rust -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. diff --git a/rust_compiler/libs/compiler/src/test/declaration_literal.rs b/rust_compiler/libs/compiler/src/test/declaration_literal.rs index 96078f9..ee48945 100644 --- a/rust_compiler/libs/compiler/src/test/declaration_literal.rs +++ b/rust_compiler/libs/compiler/src/test/declaration_literal.rs @@ -9,8 +9,14 @@ fn variable_declaration_numeric_literal() -> anyhow::Result<()> { "# }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -40,8 +46,14 @@ fn variable_declaration_numeric_literal_stack_spillover() -> anyhow::Result<()> let j = 9; "#}; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -73,8 +85,14 @@ fn variable_declaration_negative() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -97,8 +115,14 @@ fn test_boolean_declaration() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -125,8 +149,14 @@ fn test_boolean_return() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -149,15 +179,21 @@ fn test_boolean_return() -> anyhow::Result<()> { #[test] fn test_const_hash_expr() -> anyhow::Result<()> { - let compiled = compile!(debug r#" + let compiled = compile!(check r#" const nameHash = hash("AccessCard"); device self = "db"; self.Setting = nameHash; "#); + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -180,8 +216,14 @@ fn test_declaration_is_const() -> anyhow::Result<()> { "# }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main diff --git a/rust_compiler/libs/compiler/src/test/device_access.rs b/rust_compiler/libs/compiler/src/test/device_access.rs index 06ae636..b539a49 100644 --- a/rust_compiler/libs/compiler/src/test/device_access.rs +++ b/rust_compiler/libs/compiler/src/test/device_access.rs @@ -24,8 +24,14 @@ fn device_property_read() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -48,8 +54,14 @@ fn device_property_write() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -72,6 +84,12 @@ fn multiple_device_declarations() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + // Declarations only emit the header when unused assert_eq!(compiled.output, "j main\n"); @@ -89,8 +107,14 @@ fn device_with_variable_interaction() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -116,9 +140,15 @@ fn device_property_in_arithmetic() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + // Verify that we load property, add 100, and move to result assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -147,8 +177,14 @@ fn device_used_in_function() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -182,8 +218,14 @@ fn device_in_conditional() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -208,8 +250,14 @@ fn device_property_with_underscore_name() -> anyhow::Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main diff --git a/rust_compiler/libs/compiler/src/test/edge_cases.rs b/rust_compiler/libs/compiler/src/test/edge_cases.rs index af1d004..2cff613 100644 --- a/rust_compiler/libs/compiler/src/test/edge_cases.rs +++ b/rust_compiler/libs/compiler/src/test/edge_cases.rs @@ -447,8 +447,8 @@ fn modulo_operation() -> anyhow::Result<()> { fn exponentiation() -> anyhow::Result<()> { let compiled = compile! { check " - let x = 2 ^ 8; - let y = 3 ^ 3; + let x = 2 ** 8; + let y = 3 ** 3; " }; @@ -464,8 +464,10 @@ fn exponentiation() -> anyhow::Result<()> { " j main main: - move r0 3 - move r1 3 + pow r1 2 8 + move r8 r1 + pow r2 3 3 + move r9 r2 " } ); diff --git a/rust_compiler/libs/compiler/src/test/math_syscall.rs b/rust_compiler/libs/compiler/src/test/math_syscall.rs index 5edc9c0..f43545b 100644 --- a/rust_compiler/libs/compiler/src/test/math_syscall.rs +++ b/rust_compiler/libs/compiler/src/test/math_syscall.rs @@ -41,8 +41,14 @@ fn test_asin() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -65,8 +71,14 @@ fn test_atan() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -89,8 +101,14 @@ fn test_atan2() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -113,8 +131,14 @@ fn test_abs() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -137,8 +161,14 @@ fn test_ceil() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -161,8 +191,14 @@ fn test_cos() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -185,8 +221,14 @@ fn test_floor() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -209,8 +251,14 @@ fn test_log() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -233,8 +281,14 @@ fn test_max() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -258,8 +312,14 @@ fn test_max_from_game() -> Result<()> { "# }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -283,8 +343,14 @@ fn test_min() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -307,8 +373,14 @@ fn test_rand() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -331,8 +403,14 @@ fn test_sin() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -355,8 +433,14 @@ fn test_sqrt() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -379,8 +463,14 @@ fn test_tan() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main @@ -403,8 +493,14 @@ fn test_trunc() -> Result<()> { " }; + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + assert_eq!( - compiled, + compiled.output, indoc! { " j main