//! TDD tests for error conversion implementations //! //! RED phase: These tests will fail until we implement proper error conversions #[cfg(test)] mod error_conversion_tests { use crate::error::{FlashError, FlashResult}; use rtx_runtime::RuntimeError; use rtx_tensor::TensorError; /// Test: FlashError should convert from RuntimeError #[test] fn test_runtime_error_conversion() { // RED: This will fail until we implement From let runtime_error = RuntimeError::InvalidOperation("test error".to_string()); let flash_error: FlashError = runtime_error.into(); match flash_error { FlashError::Cuda { message } => { assert!(message.contains("test error")); } _ => panic!("Expected Cuda variant"), } } /// Test: FlashError should convert from TensorError #[test] fn test_tensor_error_conversion() { // This should already work, but let's verify let tensor_error = TensorError::shape("invalid shape"); let flash_error: FlashError = tensor_error.into(); match flash_error { FlashError::Tensor { message: msg } => { assert!(msg.contains("invalid shape")); } _ => panic!("Expected Tensor variant"), } } /// Test: Error conversion preserves context #[ignore] // TODO: Fix when RuntimeError::Memory variant is available #[test] fn test_error_context_preservation() { // RED: Test that error conversions preserve important context // let runtime_error = RuntimeError::Memory { // requested: 1024, // available: 512, // device_id: 0, // }; // let flash_error: FlashError = runtime_error.into(); // match flash_error { // FlashError::Cuda { message: msg } => { // assert!(msg.contains("1024")); // assert!(msg.contains("512")); // assert!(msg.contains("device_id")); // } // _ => panic!("Expected Cuda variant with memory info"), // } } /// Test: Error chain operations work correctly #[test] fn test_error_chain_operations() { // Test that we can use ? operator with conversions fn runtime_operation() -> Result<(), RuntimeError> { Err(RuntimeError::InvalidOperation("chain test".to_string())) } fn flash_operation() -> FlashResult<()> { runtime_operation()?; // This should auto-convert Ok(()) } let result = flash_operation(); assert!(result.is_err()); if let Err(FlashError::Cuda { message: msg }) = result { assert!(msg.contains("chain test")); } else { panic!("Expected converted error"); } } }