Repository navigation
refactor(test): read and parse the shared vector file once per run - #107
Merged
Merged
Conversation
test_vectors.cpp carried two byte-for-byte identical loading prologues:
loadVectors() and loadNegVectors() each opened SOFAB_TEST_VECTORS_PATH,
read it whole and JSON-parsed it, then walked their own top-level group
("vectors" / "invalid_utf8") and freed the root. main() called both, so
the ~55 KB file was opened, read and parsed twice on every ctest run and
the prologue plus the "requires"-tag loop had to be kept in step by hand.
Parse once, walk twice: a VectorFile holder owns the text and the parsed
root (freeing it on scope exit), loadVectorFile() fills it, and both
walkers now take the parsed root instead of a path. The duplicated
capability-tag loop becomes reqMask().
The duplication also hid a failure mode: a walker whose top-level key has
been renamed or dropped upstream just walked nothing and returned
success, which reads as "nothing to test" while the suite stays green.
Both walkers now pull their group through group(), which demands a
present, non-empty array and reports "vector file has no non-empty
"<key>" array" otherwise.
Guards for both halves run in the normal suite: vector-file-read-once
asserts the file was read exactly once, and five envelope cases feed
doctored envelopes (both groups, each group alone, empty groups, renamed
keys) to the walkers in memory and require the verdict AND the vector
count to match — a rejected group must be rejected, not silently empty.
The vector set is unchanged: 81 vectors, 11 invalid_utf8, 723 checks
before and the same 723 plus the 6 new guard checks after.
Closes #100
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.
test/test_vectors.cppdecoded the shared vector envelope in two independent,byte-for-byte duplicated loaders:
loadVectors()andloadNegVectors()eachopened
SOFAB_TEST_VECTORS_PATH, read it whole, JSON-parsed it, walked their owntop-level group (
vectors/invalid_utf8) and freed the root.main()calledboth, so the ~55 KB file was opened, read and fully parsed twice per
ctestrun, and the prologue plus the
requires-tag loop had to be kept in step by hand.Fix
Parse once, walk twice:
VectorFileowns the text and the parsed root and frees it on scope exit;loadVectorFile()fills it.loadVectors()/loadNegVectors()takeconst sofab_json_t *rootinstead ofa path — no open/read/parse/free prologue, no
sofab_json_free(root)on theirerror paths (the holder owns it).
reqMask().The duplication also hid a failure mode the issue calls out: a walker whose
top-level key upstream renames or drops just walked nothing and returned
success, which reads as "nothing to test" while the suite stays green. Both
walkers now pull their group through
group(), which demands a present,non-empty array and otherwise reports
vector file has no non-empty "<key>" array.Regression tests (in the normal suite)
vector-file-read-once— the file was read exactly once this run.envelope-both-groups,envelope-no-invalid_utf8,envelope-no-vectors,envelope-empty-groups,envelope-renamed-keys— doctored envelopes areparsed in memory and fed to both walkers; each case requires the walker's
verdict and its vector count to match, so a rejected group has to be
rejected rather than silently empty (the two are indistinguishable if only the
count is checked).
Verified against the pre-fix code: both loaders accept a
{"vectors_v2":…, "invalid_utf8_v2":…}envelope withok=1, count=0. Verified by mutation on thefixed code: reintroducing a second
loadVectorFile()failsvector-file-read-once; looseninggroup()back to a silent empty walk failsenvelope-empty-groups; renaming a walker's key fails the run with the newmessage.
Unchanged behaviour
Same failure text on a missing (
cannot open vector file) or unparsable(
json parse: …) file, same vector set: 81 vectors, 11invalid_utf8, 723checks before and the same 723 + 6 new guard checks (729) after. Docs: README's
test_vectorsbullet andtest/shared/README.md§"Keep in sync" now state thesingle-parse rule and what an envelope reshape looks like after a re-sync.
Closes #100