1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#![ 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
}
}