Skip to content

Commit 7c0e5c4

Browse files
committed
.
1 parent fe63bcf commit 7c0e5c4

File tree

4 files changed

+387
-2
lines changed

4 files changed

+387
-2
lines changed

module/core/CROSS_CRATE_TESTING.md

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
# Cross-Crate Testing Documentation
2+
3+
## Overview
4+
5+
The `test.sh` script provides comprehensive cross-crate testing for the wTools test aggregation ecosystem. This documentation covers all aspects of the cross-crate testing architecture and the `the_module` alias pattern.
6+
7+
## Quick Reference
8+
9+
```bash
10+
# From /home/user1/pro/lib/wTools/module/core directory:
11+
./test.sh # Run all tests (full validation)
12+
./test.sh quick # Quick compilation check (~15 seconds)
13+
```
14+
15+
## Architecture
16+
17+
### Test Aggregation Ecosystem
18+
19+
The wTools ecosystem uses a sophisticated test aggregation pattern where:
20+
21+
1. **test_tools** serves as the aggregation layer
22+
2. **Individual crates** provide their own tests + use test_tools for infrastructure
23+
3. **Cross-dependencies** exist in both directions
24+
4. **The same test source code** works in multiple contexts
25+
26+
### Crates Tested by test.sh
27+
28+
| Crate | Role | Tests | Description |
29+
|-------|------|-------|-------------|
30+
| `error_tools` | Core | 18 (17 + aggregated runner) | Error handling, debug assertions |
31+
| `collection_tools` | Core | 37+ | Collection types, constructor macros |
32+
| `mem_tools` | Core | 4+ | Memory comparison utilities |
33+
| `diagnostics_tools` | Core | 17+ | Runtime/compile-time assertions |
34+
| `impls_index` | Core | 18+ | Implementation indexing, test macros |
35+
| `test_tools` | Aggregator | 175+ | Unified test suite aggregating all others |
36+
37+
**Total: ~269+ tests across individual + aggregated contexts**
38+
39+
## The `the_module` Alias Pattern
40+
41+
### What is `the_module`?
42+
43+
`the_module` is a **module identity alias** that enables the same test source code to work in two different contexts:
44+
45+
```rust
46+
// In error_tools/tests/tests.rs:
47+
use error_tools as the_module;
48+
49+
// In test_tools aggregation:
50+
use test_tools as the_module;
51+
52+
// Same test code works in both:
53+
the_module::debug_assert_id!(1, 1);
54+
```
55+
56+
### How It Works
57+
58+
**Individual Testing Context:**
59+
```rust
60+
use error_tools as the_module;
61+
// the_module::debug_assert_id!(1, 1) → error_tools::debug_assert_id!(1, 1)
62+
```
63+
64+
**Aggregated Testing Context:**
65+
```rust
66+
use test_tools as the_module;
67+
// the_module::debug_assert_id!(1, 1) → test_tools::debug_assert_id!(1, 1)
68+
```
69+
70+
### Documentation Template
71+
72+
Each crate using `the_module` includes this standardized documentation:
73+
74+
```rust
75+
// ================================================================================================
76+
// MODULE IDENTITY ALIAS: the_module
77+
// ================================================================================================
78+
//
79+
// This test module uses the `the_module` alias pattern for test aggregation compatibility.
80+
//
81+
// ## Module Identity:
82+
// - **Individual Testing**: `the_module` = `{crate_name}` (this crate)
83+
// - **Aggregated Testing**: `the_module` = `test_tools` (when included via path in test_tools)
84+
//
85+
// ## Purpose:
86+
// This allows the same test source code to work in both contexts:
87+
// 1. When running tests directly from {crate_name} directory
88+
// 2. When running aggregated tests from test_tools directory
89+
//
90+
// The alias ensures tests reference the correct implementation in each context.
91+
//
92+
// ================================================================================================
93+
94+
use {crate_name} as the_module;
95+
```
96+
97+
## Cross-Crate Impact Scenarios
98+
99+
### Why Cross-Crate Testing is Critical
100+
101+
Changes in one crate can break others through multiple pathways:
102+
103+
#### 1. Standalone Implementation Changes
104+
```
105+
test_tools/src/standalone.rs changes
106+
107+
Individual crate tests break (error_tools, collection_tools, etc.)
108+
```
109+
110+
**Example:** Changing `debug_assert_id!` macro in standalone mode breaks all crates that use it.
111+
112+
#### 2. Individual Crate Changes
113+
```
114+
error_tools/tests/inc/assert_test.rs changes
115+
116+
test_tools aggregation breaks
117+
```
118+
119+
**Example:** Adding new test functions that use features not supported in test_tools standalone.
120+
121+
#### 3. Macro Definition Changes
122+
```
123+
test_tools macro changes (tests_impls!, tests_index!)
124+
125+
All subcrates using these macros break
126+
```
127+
128+
**Example:** Changing the `tests_impls!` macro signature affects 26+ crates.
129+
130+
#### 4. Module Structure Changes
131+
```
132+
API namespace changes in test_tools
133+
134+
the_module alias resolution breaks across all crates
135+
```
136+
137+
**Example:** Moving `debug_assert_id` from `prelude` to `error::assert` breaks existing tests.
138+
139+
## Test.sh Implementation Details
140+
141+
### Script Architecture
142+
143+
```bash
144+
#!/bin/bash
145+
set -e # Exit on first failure
146+
147+
CORE_DIR="/home/user1/pro/lib/wTools/module/core"
148+
CRATES=(
149+
"error_tools"
150+
"collection_tools"
151+
"mem_tools"
152+
"diagnostics_tools"
153+
"impls_index"
154+
"test_tools" # Must be last - aggregates all others
155+
)
156+
157+
cd "$CORE_DIR"
158+
159+
# Test each crate in sequence
160+
for crate in "${CRATES[@]}"; do
161+
cd "$crate" && RUSTFLAGS="-D warnings" cargo nextest run --all-features && cd ..
162+
done
163+
```
164+
165+
### Failure Modes and Detection
166+
167+
#### Early Termination on Failure
168+
The script uses `set -e` to stop at the first failing crate, immediately revealing cross-crate issues.
169+
170+
#### Compilation vs Runtime Failures
171+
- **Quick mode:** Catches compilation issues (`cargo check`)
172+
- **Full mode:** Catches runtime test failures (`cargo nextest run`)
173+
174+
#### Warning-as-Error Policy
175+
`RUSTFLAGS="-D warnings"` ensures all warnings are treated as errors, catching:
176+
- Unused Result warnings
177+
- Type compatibility issues
178+
- Deprecated API usage
179+
- Dead code in cross-crate contexts
180+
181+
## Troubleshooting Common Issues
182+
183+
### Type Compatibility Issues
184+
185+
**Problem:** Different types with same names between crate and standalone
186+
```rust
187+
error[E0308]: mismatched types
188+
expected `HashMap<&str, &str>`, found `HashMap<_, _>`
189+
note: `collection_tools::HashMap<_, _>` and `test_tools::HashMap<&str, &str>`
190+
have similar names, but are actually distinct types
191+
```
192+
193+
**Solution:** Ensure standalone implementations provide exact type compatibility.
194+
195+
### Unused Result Warnings
196+
197+
**Problem:** Missing `let _ = ` for Result return values
198+
```rust
199+
error: unused `Result` that must be used
200+
::test_tools::test::smoke_test::smoke_test_for_local_run();
201+
```
202+
203+
**Solution:** Handle or explicitly ignore Result values:
204+
```rust
205+
let _ = ::test_tools::test::smoke_test::smoke_test_for_local_run();
206+
```
207+
208+
### Module Resolution Failures
209+
210+
**Problem:** `the_module` alias not resolving correctly
211+
```rust
212+
error[E0433]: failed to resolve: could not find `untyped` in `error`
213+
the_module::error::untyped::format_err!("err");
214+
```
215+
216+
**Solution:** Ensure test_tools provides compatible module structure:
217+
```rust
218+
pub mod error {
219+
pub mod untyped {
220+
pub use anyhow::{Error, format_err};
221+
}
222+
}
223+
```
224+
225+
## Historical Context
226+
227+
### Evolution of Cross-Crate Testing
228+
229+
1. **Initial State:** Individual crates tested separately, cross-crate issues discovered late
230+
2. **Aggregation Introduction:** test_tools began including tests via path references
231+
3. **the_module Pattern:** Alias system enabled dual-context testing
232+
4. **Standalone Compatibility:** test_tools provided standalone implementations
233+
5. **Cross-Validation:** test.sh script automated comprehensive validation
234+
235+
### Performance Characteristics
236+
237+
- **Full test suite:** ~2-3 minutes for all 269+ tests
238+
- **Quick check:** ~15 seconds for compilation verification
239+
- **Individual crate:** ~10-30 seconds per crate
240+
- **Aggregated runner:** ~15 seconds (runs within error_tools as single test)
241+
242+
## Integration with Development Workflow
243+
244+
### Recommended Usage
245+
246+
1. **During Development:** Use `./test.sh quick` for rapid feedback
247+
2. **Before Commits:** Use `./test.sh` for comprehensive validation
248+
3. **CI/CD Integration:** Include both modes in automated testing
249+
4. **Cross-Crate Changes:** Always run full suite when modifying:
250+
- `test_tools/src/standalone.rs`
251+
- Any `tests_impls!` or `tests_index!` usage
252+
- Module structure in test_tools
253+
- Macro definitions
254+
255+
### Integration with Existing Commands
256+
257+
The script complements existing test commands:
258+
259+
```bash
260+
# Single-crate testing (traditional):
261+
cargo nextest run --all-features # or alias: ctest1
262+
263+
# Cross-crate testing (comprehensive):
264+
./test.sh # All related crates
265+
./test.sh quick # Quick validation
266+
```
267+
268+
## Future Considerations
269+
270+
### Scalability
271+
272+
As more crates adopt the aggregation pattern:
273+
- Add new crates to the `CRATES` array in test.sh
274+
- Ensure proper `the_module` documentation in each crate
275+
- Update standalone implementations to support new APIs
276+
- Monitor test execution time and consider parallel execution
277+
278+
### Automation Opportunities
279+
280+
- **Dependency Detection:** Auto-discover crates using `the_module` pattern
281+
- **Parallel Execution:** Run independent crates concurrently
282+
- **Selective Testing:** Only test crates affected by changes
283+
- **Integration Testing:** Verify behavioral equivalence between native and standalone
284+
285+
## Conclusion
286+
287+
The `test.sh` script and associated cross-crate testing architecture provide:
288+
289+
1. **Early Detection** of cross-crate compatibility issues
290+
2. **Comprehensive Validation** of the test aggregation ecosystem
291+
3. **Documentation** of complex architectural patterns
292+
4. **Automation** of previously manual testing workflows
293+
294+
This system ensures that the sophisticated test aggregation architecture remains reliable as the ecosystem evolves, catching issues before they impact users or CI/CD pipelines.

module/core/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# wTools Core Modules
2+
3+
This directory contains the core modules of the wTools ecosystem.
4+
5+
## Cross-Crate Testing
6+
7+
The modules in this directory use a sophisticated test aggregation system. Use the cross-crate testing script to ensure compatibility across all related modules:
8+
9+
```bash
10+
./test.sh # Run all tests (recommended before commits)
11+
./test.sh quick # Quick compilation check
12+
```
13+
14+
This script tests 6 interconnected crates (~269+ tests total) and catches cross-crate compatibility issues that individual testing would miss.
15+
16+
📖 **For detailed documentation:** See [`CROSS_CRATE_TESTING.md`](CROSS_CRATE_TESTING.md)
17+
18+
## Key Modules
19+
20+
- **`test_tools`** - Testing infrastructure and aggregation layer (175+ tests)
21+
- **`error_tools`** - Error handling and debug assertions (18 tests)
22+
- **`collection_tools`** - Collection types and constructor macros (37+ tests)
23+
- **`mem_tools`** - Memory comparison utilities (4+ tests)
24+
- **`diagnostics_tools`** - Runtime/compile-time assertions (17+ tests)
25+
- **`impls_index`** - Implementation indexing and test organization (18+ tests)
26+
27+
## Architecture
28+
29+
Many modules use the `the_module` alias pattern for dual-context testing:
30+
- Individual testing: `the_module = crate_name`
31+
- Aggregated testing: `the_module = test_tools`
32+
33+
This enables the same test source code to work in both individual crate directories and the aggregated test_tools context.

module/core/test.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
#!/bin/bash
22

3-
# Run tests for test_tools and all its aggregated subcrates
4-
# Usage: ./test.sh [quick]
3+
# ================================================================================================
4+
# CROSS-CRATE TESTING SCRIPT
5+
# ================================================================================================
6+
#
7+
# Run tests for test_tools and all its aggregated subcrates to detect cross-crate compatibility
8+
# issues. Changes in one crate can break others through the test aggregation system.
9+
#
10+
# USAGE:
11+
# ./test.sh # Full test suite (~2-3 minutes, ~269+ tests)
12+
# ./test.sh quick # Compilation check only (~15 seconds)
13+
#
14+
# TESTED CRATES:
15+
# error_tools - 18 tests (17 + aggregated runner)
16+
# collection_tools - 37+ tests (collection types, macros)
17+
# mem_tools - 4+ tests (memory utilities)
18+
# diagnostics_tools - 17+ tests (assertions)
19+
# impls_index - 18+ tests (implementation indexing)
20+
# test_tools - 175+ tests (aggregated test suite)
21+
#
22+
# WHY CROSS-CRATE TESTING:
23+
# - test_tools provides standalone implementations of functionality from other crates
24+
# - Individual crates use test_tools for testing infrastructure
25+
# - the_module alias pattern enables dual-context testing
26+
# - Changes in standalone.rs can break individual crate tests
27+
# - Changes in individual crates can break test_tools aggregation
28+
#
29+
# DOCUMENTATION:
30+
# See CROSS_CRATE_TESTING.md for comprehensive architecture and troubleshooting guide
31+
#
32+
# ================================================================================================
533

634
set -e
735

0 commit comments

Comments
 (0)