Calculate Version Script Test Suite
This directory contains comprehensive tests for the calculate_version.sh script.
Test Files
test_calculate_version.sh- Main test suite with comprehensive test casesrun_tests.sh- Test runner with different output modesREADME.md- This documentation
Running Tests
Quick Test Run
./tests/run_tests.sh
Verbose Test Run
./tests/run_tests.sh --verbose
CI Mode (minimal output)
./tests/run_tests.sh --ci
Direct Test Suite
./tests/test_calculate_version.sh
./tests/test_calculate_version.sh --verbose
Test Coverage
The test suite covers:
Branch Types
- Main Branch: Tests stable version handling, tag detection, RC conversion
- Develop Branch: Tests SNAPSHOT version management, release detection
- Release Branch: Tests RC version creation and incrementing
- Hotfix Branch: Tests patch version bumping
- Feature Branch: Tests version inheritance
Edge Cases
- Invalid branch formats
- Unknown branch types
- Missing tags on main branch
- Various version formats (stable, SNAPSHOT, RC)
Version Parsing
- Standard versions:
1.0.0 - SNAPSHOT versions:
1.0.0-SNAPSHOT - RC versions:
1.0.0-RC.1,1.0.0-RC.10 - Multi-digit versions:
10.20.30
Test Environment
The test suite:
- Creates a temporary test directory
- Initializes a test git repository
- Creates test pom.xml files with different versions
- Creates test branches and tags
- Runs the calculate_version.sh script
- Validates the output
- Cleans up test data
Integration with Make
The tests are integrated into the Makefile and can be run with:
make test-scripts
Test Results
The test suite provides:
- ✅ Pass/fail status for each test
- 📊 Summary statistics
- 🔍 Detailed output in verbose mode
- 🚫 Clean exit codes for CI integration
Adding New Tests
To add new test cases:
- Add a new test function in
test_calculate_version.sh - Call
run_testwith appropriate parameters:run_test "Test Name" "branch_name" "current_version" "expected_version" "tag_name" - Add the test function to the main execution flow
- Update this README if needed
Troubleshooting
Common Issues
-
Permission denied: Make sure test scripts are executable
chmod +x tests/*.sh -
Git not found: Ensure git is installed and available in PATH
-
Test failures: Run with
--verboseto see detailed output./tests/run_tests.sh --verbose
Debug Mode
For debugging, you can run individual test functions by modifying the main function in test_calculate_version.sh to call only specific test functions.