Skip to content

Add --shuffle option to PonyTest#5076

Open
SeanTAllen wants to merge 8 commits intomainfrom
add-shuffle-option-to-ponytest
Open

Add --shuffle option to PonyTest#5076
SeanTAllen wants to merge 8 commits intomainfrom
add-shuffle-option-to-ponytest

Conversation

@SeanTAllen
Copy link
Copy Markdown
Member

Implements RFC #82. PonyTest gets a --shuffle[=SEED] option that randomizes test dispatch order to catch hidden test coupling.

  • --shuffle generates a random seed from Time.cycles()
  • --shuffle=SEED uses a specific U64 seed for reproducibility
  • Seed is printed as Test seed: N before any test output
  • --list --shuffle=SEED previews the shuffled order without running tests
  • Works with all scheduling modes: concurrent, --sequential, and exclusion groups

Test dispatch is now always buffered (tests are collected during apply() and dispatched in _all_tests_applied()). Without --shuffle, dispatch order matches registration order. The ordering mode is represented as a _TestOrdering union type (_InOrder | _Shuffled) rather than boolean flags.

Adds 5 unit tests for shuffle behavior (determinism, order change, element preservation, seed differentiation, seed 0 validity) and aggregates them into the stdlib test suite.

Closes #5075

Randomizes test dispatch order to catch hidden dependencies between
tests. Without --shuffle, tests dispatch in registration order as
before (buffered dispatch is always used, but the order is preserved).

Uses a _TestOrdering union type (_InOrder | _Shuffled) to represent
the ordering mode, with the seed resolved at parse time. The shuffle
itself uses Rand.from_u64(seed) with Fisher-Yates via the stdlib
Random.shuffle method.

--list --shuffle=SEED shows the shuffled order so users can preview
what a given seed produces without running anything.

Closes #5075
@SeanTAllen SeanTAllen added the changelog - added Automatically add "Added" CHANGELOG entry on merge label Mar 27, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Mar 27, 2026
@SeanTAllen SeanTAllen added do not merge This PR should not be merged at this time and removed do not merge This PR should not be merged at this time labels Mar 27, 2026
Tests now exercise the actual _Shuffled.apply method that PonyTest
calls, rather than testing Rand.shuffle directly (which the random
package already covers).
The previous tests only exercised Rand.shuffle through a thin wrapper.
These tests create PonyTest instances with controlled args and a capture
OutStream, verifying that --list --shuffle=SEED produces the correct
shuffled output through the entire code path: argument parsing, buffered
name collection, shuffle application, and seed output formatting.
Matches the convention used by every other package in the stdlib
aggregator.
Both now start with (h, args, ...) so the shared prefix is the same.
Each test now passes its own TestList to _RunList/_RunListWith, so the
test input is visible at each call site and changing one test's input
doesn't break the others.
Each test now creates its own object literal implementing TestList,
so changing one test's input can't break the others.
Instead of testing individual hardcoded seeds, run 10 seeds through the
full PonyTest --list flow and verify that the resulting test orderings
vary across seeds. Each seed exercises the complete code path: argument
parsing, buffered name collection, shuffle, and output.

Keep the seed-zero and preserves-order tests as specific edge case and
baseline tests respectively.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - added Automatically add "Added" CHANGELOG entry on merge discuss during sync Should be discussed during an upcoming sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC #82: Add --shuffle option to PonyTest

2 participants