Test discovery overloads the 'test-' prefix and conflicts with user word names #435
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq#435
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Observation
The test runner appears to treat any word whose name starts with
test-as a test entry point, attempting to invoke it with an empty stack. That collides with user code that wants to use the natural English prefixtest-for non-test words (predicates liketest-mode-active?, validators liketest-input, helpers liketest-config-loaded?).Reproducer
A user defines a helper called
test-flagwith stack effect( Int Int -- Bool )in a non-test context, then runs the file through the test runner:Result:
The runner is generating a synthetic
mainthat callstest-flagas if it were a( -- )test entry point. Renamingtest-flagtoflag-set?makes the file compile.Why this is more than a documentation issue
The
test-prefix is one of the most natural English prefixes for predicates, validators, and harness helpers. A language imposing a convention that this prefix is "magic" forces users to invent unnatural vocabulary (flag-set?instead oftest-flag,is-mode-activeinstead oftest-mode-active?). It also breaks silently in a way that's hard to diagnose without prior knowledge — the error talks aboutmainand stack underflow, not about test discovery.The closer analogue in other ecosystems isn't
test_*(Rust's#[test]is explicit; Python's pytest discovers bytest_but only inside files that match a pattern, not in arbitrary user code). The current Seq behavior is closer to "any function namedtest_*in any file is a test," which Rust deliberately moved away from.Possible directions (non-prescriptive)
@testannotation or atest-exportform. Test discovery only finds words explicitly marked. Most invasive, most precise.( -- )word in a file invoked withseqc test. No name-based magic; users withtest-predicates just keep them. Thetest.init/test.finishframing already gives the runner enough handle to count results.test-*.seqonly). Inside a test file,test-words are tests. Outside, they're plain words. This is pytest's model and the conventionseqlingsalready uses (it copies exercise files totest-<name>.seqbefore running).seqtest-ort/namespace. Freestest-for user code.Option 3 is probably least disruptive — most existing tests already live in
test-*.seqfiles, so the discovery rule could be tightened to "only words namedtest-*in files namedtest-*.seqare entry points" without breaking anything.Surfacing context
This came up while building the seqlings chapter 18 (bitwise ops). The natural name for a "is this bit set?" predicate was
test-flag, since it parallels Unixtest/statetc. Had to rename it toflag-set?to dodge the test runner — a reasonable rename in this case, but the next user who hits this on a non-renamable word (or a public API) will be more annoyed.What does NOT need to change
test.init/test.finish/test.assert*words are fine — those are the framework, not the discovery mechanism.test-*.seqand contain only test entry points keep working under any of the proposed designs.#450