Add --shuffle and --seed options for randomizing test execution order#531
Merged
Add --shuffle and --seed options for randomizing test execution order#531
Conversation
Implements issue #530: Add command-line options to randomize test execution order within each test suite to help detect hidden test dependencies. Changes: - Add --shuffle flag to enable random test ordering - Add --seed=N option to specify random seed (0=time-based, implies --shuffle) - Implement Fisher-Yates shuffle algorithm in TestSuite - Tests are shuffled within each suite, preserving suite boundaries - Add comprehensive unit tests (Test_TestSuite_Shuffle.F90) - Add integration tests (ShuffleIntegrationTests.pf, test_shuffle.sh) All tests pass, including reproducibility with same seed and verification that shuffle actually changes test order.
Extract helper subroutines to improve code readability: - initialize_random_seed(): Handles seed initialization logic - swap_tests(): Encapsulates test swapping with move_alloc This reduces maximum nesting level from 4 to 2 and makes each subroutine have a single, clear responsibility.
Replace complex array-based shuffling with simpler index-based approach: - Shuffle integer indices array instead of Test objects - Build new vector by accessing tests in shuffled index order - Eliminates TestReference type, temp array allocations, and swap_tests() This is cleaner, more efficient (no polymorphic object copying), and easier to understand.
- Use array constructor indices = [(i, i=1, n)] instead of explicit loop - Remove superfluous explicit deallocate() for allocatable arrays - Eliminate else clause by setting default seed_array first - Replace magic number 1000 with 997 (prime) and add explanatory comment
When user_seed==0, just use Fortran's default random_seed() initialization instead of manually constructing a time-based seed. The compiler's default is perfectly adequate for non-reproducible randomization.
mathomp4
approved these changes
Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #530: Add command-line options to randomize test execution order within each test suite to help detect hidden test dependencies.
Changes
Core Implementation:
--shuffleflag to enable random test ordering--seed=Noption to specify random seed (0=time-based, implies --shuffle)Modified Files:
src/funit/core/TestSuite.F90: Added shuffle functionality withset_shuffle()andshuffle_tests()methodssrc/funit/FUnit.F90: Added CLI argument parsing for --shuffle and --seed optionsNew Tests:
tests/funit-core/Test_TestSuite_Shuffle.F90: Comprehensive unit tests (6 test cases)tests/funit-core/ShuffleIntegrationTests.pf: Integration test suitetests/funit-core/test_shuffle.sh: Shell script for command-line testingTesting
All tests pass:
Usage Examples