test_tools 0.19.1

Tools for writing and running tests.
Documentation
#![ cfg( feature = "standalone_build" ) ]
//! Tests for standalone build mode functionality (Task 038)
//!
//! These tests verify that `standalone_build` mode removes circular dependencies 
//! for foundational modules (US-4).
//!
//! ## TDD Approach
//! These tests are written FIRST and will initially FAIL where there are gaps
//! in the standalone build functionality, demonstrating the need for enhanced
//! implementation in Task 039.

#[ cfg(test) ]
mod standalone_build_tests 
{
  /// Test that `standalone_build` feature disables normal Cargo dependencies
  /// This test verifies US-4 requirement for dependency cycle breaking
  #[ test ]
  fn test_standalone_build_disables_normal_dependencies()
  {
  // In standalone build mode, normal dependencies should be disabled
  // This test verifies that when standalone_build is enabled and normal_build is not,
  // the crate uses direct source inclusion instead of Cargo dependencies
  
  #[ cfg(all(feature = "standalone_build", not(feature = "normal_build"))) ]
  {
   // In standalone mode, we should NOT have access to normal dependency re-exports
   // Instead we should have access to the standalone module inclusions
   
   // Test that standalone modules are available
   let _standalone_available = true;
   
   // Test basic functionality is available through standalone mode
   // This should work even without normal Cargo dependencies
   let test_data = std ::vec![1, 2, 3, 4, 5];
   let _same_data_test = test_tools ::same_data(&test_data, &test_data);
   
   // Test passed - functionality verified
 }
  
  #[ cfg(not(all(feature = "standalone_build", not(feature = "normal_build")))) ]
  {
   // In normal mode, we should have access to regular dependency re-exports
   let test_data = std ::vec![1, 2, 3, 4, 5];
   let _same_data_test = test_tools ::same_data(&test_data, &test_data);
   
   // Test passed - functionality verified
 }
 }

  /// Test that #[ path ] attributes work for direct source inclusion
  /// This test verifies US-4 requirement for source-level dependency resolution
  #[ test ]
  fn test_path_attributes_for_direct_source_inclusion()
  {
  // Test that standalone/ module successfully includes source files via #[ path ] attributes
  // This is the core mechanism for breaking circular dependencies
  
  #[ cfg(all(feature = "standalone_build", not(feature = "normal_build"))) ]
  {
   // Test that error tools are available through direct inclusion
   // This should work without depending on error_tools crate
   let _error_msg = format!("Test error message");
   
   // Test that collection tools are available through direct inclusion  
   // This should work without depending on collection_tools crate
   let _test_vec: test_tools ::Vec< i32 > = test_tools ::Vec ::new();
   
   // Test that memory tools are available through direct inclusion
   // This should work without depending on mem_tools crate  
   let data1 = std ::vec![1, 2, 3];
   let data2 = std ::vec![1, 2, 3];
   let _same_data = test_tools ::same_data(&data1, &data2);
   
   // Test passed - functionality verified
 }
  
  #[ cfg(not(all(feature = "standalone_build", not(feature = "normal_build")))) ]
  {
   // In normal mode, test the same functionality to ensure equivalence
   let _error_msg = "Test error message".to_string();
   let _test_vec: test_tools ::Vec< i32 > = test_tools ::Vec ::new();
   let data1 = std ::vec![1, 2, 3];
   let data2 = std ::vec![1, 2, 3];
   let _same_data = test_tools ::same_data(&data1, &data2);
   
   // Test passed - functionality verified
 }
 }

  /// Test that circular dependency resolution works correctly
  /// This test verifies US-4 requirement for foundational module support
  #[ test ]
  fn test_circular_dependency_resolution()
  {
  // Test that test_tools can be used by foundational modules without creating
  // circular dependencies when standalone_build is enabled
  
  #[ cfg(all(feature = "standalone_build", not(feature = "normal_build"))) ]
  {
   // Simulate a foundational module that needs to use test_tools
   // In standalone mode, this should work without circular dependencies
   
   // Test basic assertion functionality
   test_tools ::debug_assert_identical!(42, 42);
   
   // Test memory comparison functionality  
   let slice1 = &[ 1, 2, 3, 4, 5];
   let slice2 = &[ 1, 2, 3, 4, 5];
   let _same_data = test_tools ::same_data(slice1, slice2);
   
   // Test collection functionality
   let mut test_map = test_tools ::HashMap ::new();
   test_map.insert("key", "value");
   assert_eq!(test_map.get("key"), Some(&"value"));
   
   // Test passed - functionality verified
 }
  
  #[ cfg(not(all(feature = "standalone_build", not(feature = "normal_build")))) ]
  {
   // Test the same functionality in normal mode to ensure behavioral equivalence
   test_tools ::debug_assert_identical!(42, 42);
   
   let slice1 = &[ 1, 2, 3, 4, 5];
   let slice2 = &[ 1, 2, 3, 4, 5];
   let _same_data = test_tools ::same_data(slice1, slice2);
   
   let mut test_map = test_tools ::HashMap ::new();
   test_map.insert("key", "value");
   assert_eq!(test_map.get("key"), Some(&"value"));
   
   // Test passed - functionality verified
 }
 }

  /// Test that foundational modules can use `test_tools`
  /// This test verifies US-4 requirement for foundational module access
  #[ test ]
  fn test_foundational_modules_can_use_test_tools()
  {
  // Test that a foundational module (like error_tools, mem_tools, etc.) 
  // can successfully import and use test_tools functionality
  
  #[ cfg(all(feature = "standalone_build", not(feature = "normal_build"))) ]
  {
   // Test comprehensive functionality that a foundational module might need
   
   // Error handling functionality
   #[ cfg(feature = "error_untyped") ]
   {
  let _result: Result< (), Box<dyn core ::error ::Error >> = Ok(());
 }
   
   // Collection functionality
   let _test_vec = test_tools ::Vec ::from([1, 2, 3, 4, 5]);
   let mut _test_map: test_tools ::HashMap< &str, &str > = test_tools ::HashMap ::new();
   
   // Memory utilities
   let data = std ::vec![42u32; 1000];
   let _same_size = test_tools ::same_size(&data, &data);
   let _same_ptr = test_tools ::same_ptr(&data, &data);
   
   // Assertion utilities
   test_tools ::debug_assert_identical!(100, 100);
   
   // Test passed - functionality verified
 }
  
  #[ cfg(not(all(feature = "standalone_build", not(feature = "normal_build")))) ]
  {
   // Test equivalent functionality in normal mode
   #[ cfg(feature = "error_untyped") ]
   {
  let _result: Result< (), Box<dyn core ::error ::Error >> = Ok(());
 }
   
   let _test_vec = test_tools ::Vec ::from([1, 2, 3, 4, 5]);
   let mut _test_map: test_tools ::HashMap< &str, &str > = test_tools ::HashMap ::new();
   
   let data = std ::vec![42u32; 1000];
   let _same_size = test_tools ::same_size(&data, &data);
   let _same_ptr = test_tools ::same_ptr(&data, &data);
   
   test_tools ::debug_assert_identical!(100, 100);
   
   // Test passed - functionality verified
 }
 }

  /// Test behavior equivalence between normal and standalone builds
  /// This test verifies US-4 requirement for functional equivalence
  #[ test ]
  fn test_behavior_equivalence_normal_vs_standalone()
  {
  // Test that the same operations produce identical results in both modes
  // This ensures that switching to standalone mode doesn't change functionality
  
  // Test memory utilities equivalence
  // For same_data, we need to test with the same memory reference or equivalent data
  let test_data = std ::vec![1, 2, 3, 4, 5];
  let same_ref_result = test_tools ::same_data(&test_data, &test_data);
  
  // Test with array data (safe implementation only compares memory locations)
  let array1 = [1, 2, 3, 4, 5];
  let array2 = [6, 7, 8, 9, 10];
  let same_array_data = test_tools ::same_data(&array1, &array1);  // Same reference
  let different_array_data = test_tools ::same_data(&array1, &array2);
  
  assert!(same_ref_result, "same_data should return true for identical reference in both modes");
  assert!(same_array_data, "same_data should return true for same memory location in both modes");
  assert!(!different_array_data, "same_data should return false for different memory locations in both modes");
  
  // Test collection utilities equivalence
  let test_vec = [42, 100];
  
  assert_eq!(test_vec.len(), 2, "Vec operations should work identically in both modes");
  assert_eq!(test_vec[0], 42, "Vec indexing should work identically in both modes");
  
  // Test HashMap operations
  let mut test_map = test_tools ::HashMap ::new();
  test_map.insert("test_key", "test_value");
  
  assert_eq!(test_map.get("test_key"), Some(&"test_value"), "HashMap operations should work identically in both modes");
  assert_eq!(test_map.len(), 1, "HashMap size should be consistent in both modes");
  
  // Test assertion utilities (these should not panic)
  test_tools ::debug_assert_identical!(42, 42);
  
  // Test passed - functionality verified
 }

  /// Test standalone mode compilation success
  /// This test verifies US-4 requirement for successful standalone compilation
  #[ test ]
  fn test_standalone_mode_compilation()
  {
  // This test verifies that the standalone mode actually compiles successfully
  // and that all the #[ path ] attributes resolve to valid source files
  
  #[ cfg(all(feature = "standalone_build", not(feature = "normal_build"))) ]
  {
   // Test that basic standalone functionality compiles and works
   // If this test runs, it means the standalone mode compiled successfully
   
   // Test that all major standalone components are accessible
   let _error_available = cfg!(feature = "standalone_error_tools");
   let _collection_available = cfg!(feature = "standalone_collection_tools");
   let _mem_available = cfg!(feature = "standalone_mem_tools");
   let _typing_available = cfg!(feature = "standalone_typing_tools");
   let _diag_available = cfg!(feature = "standalone_diagnostics_tools");
   
   // Test passed - functionality verified
 }
  
  #[ cfg(not(all(feature = "standalone_build", not(feature = "normal_build")))) ]
  {
   // In normal mode, verify normal dependencies are working
   // Normal mode working - verified through successful compilation
   
   // Test passed - functionality verified
 }
 }

  /// Test feature flag isolation
  /// This test verifies US-4 requirement for proper feature isolation
  #[ test ]
  fn test_feature_flag_isolation()
  {
  // Test that standalone_build and normal_build features are properly isolated
  // and don't interfere with each other
  
  // Test that we're in exactly one mode
  let standalone_mode = cfg!(all(feature = "standalone_build", not(feature = "normal_build")));
  let normal_mode = cfg!(feature = "normal_build");
  
  // We should be in exactly one mode, not both or neither
  assert!(
   (standalone_mode && !normal_mode) || (!standalone_mode && normal_mode),
   "Should be in exactly one build mode: standalone_build XOR normal_build"
 );
  
  #[ cfg(all(feature = "standalone_build", not(feature = "normal_build"))) ]
  {
   // In standalone mode, verify standalone features are enabled
   assert!(cfg!(feature = "standalone_build"), "standalone_build feature should be enabled");
   assert!(!cfg!(feature = "normal_build"), "normal_build feature should be disabled in standalone mode");
   
   // Test that standalone sub-features can be enabled
   let _error_tools_standalone = cfg!(feature = "standalone_error_tools");
   let _collection_tools_standalone = cfg!(feature = "standalone_collection_tools");
   
   // Test passed - functionality verified
 }
  
  #[ cfg(not(all(feature = "standalone_build", not(feature = "normal_build")))) ]
  {
   // In normal mode, verify normal features work
   const { assert!(cfg!(feature = "normal_build"), "normal_build feature should be enabled"); }

   // Test passed - functionality verified
 }
 }

  /// Test API surface consistency
  /// This test verifies US-4 requirement for consistent API between modes
  #[ test ]
  fn test_api_surface_consistency()
  {
  // Test that the same APIs are available in both standalone and normal modes
  // This ensures that switching modes doesn't break user code
  
  // Test that key APIs are available in both modes
  
  // Memory utilities API
  let data1 = std ::vec![1, 2, 3];
  let data2 = std ::vec![1, 2, 3];
  let _same_data_api = test_tools ::same_data(&data1, &data2);
  let _same_size_api = test_tools ::same_size(&data1, &data2);
  let _same_ptr_api = test_tools ::same_ptr(&data1, &data1);
  
  // Collection types API
  let _vec_api: test_tools ::Vec< i32 > = test_tools ::Vec ::new();
  let _hashmap_api: test_tools ::HashMap< &str, i32 > = test_tools ::HashMap ::new();
  let _hashset_api: test_tools ::HashSet< i32 > = test_tools ::HashSet ::new();
  
  // Assertion APIs
  test_tools ::debug_assert_identical!(1, 1);
  
  // Error handling API (if available)
  #[ cfg(feature = "error_untyped") ]
  {
   let _error_api: Result< (), Box<dyn core ::error ::Error >> = Ok(());
 }
  
  // Test passed - functionality verified
 }
}