This document describes the comprehensive unit tests created for the --save and --auto-save-every CLI parameters in Conway's Game of Life.
Contains 14 unit tests integrated directly into the CLI module:
test "CLI validation - basic valid args"test "CLI validation - conflicting save and load"test "CLI validation - empty save file"test "CLI validation - empty load file"test "CLI validation - zero auto-save interval"test "CLI validation - save prefix without auto-save"test "CLI validation - description without save"test "CLI validation - valid save with description"test "CLI validation - valid auto-save with prefix and description"
test "CLI parsing - save parameter with equals"test "CLI parsing - save parameter with space"test "CLI parsing - auto-save-every parameter with equals"test "CLI parsing - auto-save-every parameter with space"test "CLI parsing - save with description and auto-save combination"test "CLI parsing - invalid auto-save-every value"test "CLI parsing - save file extension handling"test "CLI parsing - edge cases for save parameters"test "CLI parsing - comprehensive save/auto-save scenario validation"
Total: 18 inline unit tests
Contains 7 comprehensive integration tests:
-
CLI integration - parseArgs with save parameter- Tests complete CliArgs structure with save parameters
- Validates all field assignments and memory management
-
CLI integration - parseArgs with auto-save parameters- Tests auto-save configuration validation
- Verifies interval and prefix handling
-
CLI integration - complex save configuration- Tests combinations of manual save, auto-save, and pattern loading
- Validates complex parameter interactions
-
CLI integration - save parameter validation edge cases- Tests path separators in filenames
- Validates minimum and maximum auto-save intervals
- Handles special characters and edge cases
-
CLI integration - error scenarios for save parameters- Tests all validation error conditions
- Verifies proper error reporting and cleanup
-
CLI integration - realistic usage scenarios- Tests real-world usage patterns
- Validates development, research, and exploration workflows
-
CLI integration - memory management for save parameters- Tests proper memory allocation and deallocation
- Verifies no memory leaks in error conditions
Total: 7 integration tests
- ✅ Basic save file specification
- ✅ Save file with description
- ✅ Path validation (empty paths, long names, special characters)
- ✅ File extension handling (.cgol auto-detection)
- ✅ Memory management and cleanup
- ✅ Conflict detection with --load
- ✅ Numeric value parsing (equals and space syntax)
- ✅ Interval validation (minimum 1, maximum values)
- ✅ Integration with save prefix
- ✅ Error handling for invalid values (0, non-numeric)
- ✅ Memory management for prefix strings
- ✅ String allocation and validation
- ✅ Dependency validation (requires --auto-save-every)
- ✅ Integration with auto-save functionality
- ✅ Memory cleanup on error conditions
- ✅ String handling and validation
- ✅ Integration with both manual and auto-save
- ✅ Memory management and proper cleanup
- ✅ Validation of orphan descriptions
- ✅ Conflicting --save and --load parameters
- ✅ Empty save file paths
- ✅ Zero or invalid auto-save intervals
- ✅ Save prefix without auto-save configuration
- ✅ Description without save operation
- ✅ Invalid numeric values for auto-save-every
- ✅ Memory allocation failures
- ✅ Very long filenames
- ✅ Filenames with spaces and special characters
- ✅ Path separators and subdirectories
- ✅ Maximum reasonable auto-save intervals
- ✅ Minimum auto-save intervals (1 generation)
- ✅ Complex parameter combinations
# Run main test suite (includes CLI validation tests)
zig build test
# Run dedicated CLI save parameter tests
zig test test_cli_save_params.zig
# Run both test suites together
zig build test && zig test test_cli_save_params.zigMain test suite: 18/18 tests PASSED ✅
Integration tests: 7/7 tests PASSED ✅
Total coverage: 25/25 tests PASSED ✅
cgol --save dev_checkpoint.cgol --description "Development checkpoint"cgol --auto-save-every 500 --save-prefix "long_sim_" --generations 10000cgol --pattern patterns/glider.rle --auto-save-every 50 --save-prefix "exploration_"cgol --save research_session_1.cgol \
--description "Oscillator behavior study" \
--auto-save-every 200 \
--save-prefix "research_backup_" \
--pattern patterns/beacon.rle \
--generations 2000All tests include proper memory management validation:
- ✅ String allocation using
allocator.dupe() - ✅ Proper cleanup with
args.deinit(allocator) - ✅ No memory leaks in error conditions
- ✅ Safe handling of optional string parameters
These tests validate the CLI parameter parsing layer that integrates with:
- Save/Load System: Tests validate parameters that will be used by
saveload.zig - Main Loop: Tests ensure parameters are ready for Phase 2 integration
- Error Handling: Tests verify user-friendly error messages and graceful failures
- Memory Management: Tests ensure no leaks in long-running simulations
The test framework is designed to easily accommodate:
- Additional save/load parameters
- New validation rules
- Extended error conditions
- Performance testing for large parameter sets
- Integration with actual file I/O operations
Status: ✅ Complete - All CLI save parameter tests implemented and passing
Coverage: 25 comprehensive unit and integration tests
Quality: Memory-safe, error-handling, and edge-case validated