test: expected-output fixtures for JSON inputs (salvaged from #2509)#2961
Merged
Conversation
The JSON fixture harness asserts round-trip output ~ input, with unconditional leniency: extra null properties in the output are always allowed, and allowMissingNull languages may drop nulls. Correct behaviors where the output legitimately differs from the input were therefore untestable -- concretely, that Go's omitempty drops null fields. Port the JSON Schema fixtures' `.out.<feature>.json` convention to JSON inputs: an input `foo.json` may come with an expected-output file `foo.out.<key>.json`, which applies to a run when `<key>` is one of the language's `features` or the name of a renderer option that the particular run sets (via a pinned `quickTestRendererOptions` entry). When it applies, the output must match strictly, without the null leniency; when absent, behavior is unchanged. `.out.` files are excluded from test-input enumeration. Use it to assert the omit-empty behavior from #2509: a pinned Go run of priority/omit-empty.json with omit-empty enabled must drop the null field, per omit-empty.out.omit-empty.json. The input is in priority/ (not misc/) so it also runs under QUICKTEST in CI. Salvaged from #2509; the test case is Adam724's. Co-authored-by: Adam724 <alaspina6@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
This salvages the surviving half of #2509 by @Adam724: the ability to assert what a fixture's output should be when it legitimately differs from the input.
Problem
The JSON fixture harness asserts round-trip output ≈ input, with unconditional leniency: extra
nullproperties in the output are always allowed, andallowMissingNulllanguages may drop nulls. That makes correct behaviors where the output should differ from the input untestable. The concrete case from #2509: Go'somitemptyshould drop null/empty fields, and nothing could assert that it does.Mechanism
This ports the JSON Schema fixtures' existing
.out.<feature>.jsonconvention to JSON inputs, instead of #2509's parallel path-keyed option map:foo.jsonmay come with an expected-output filefoo.out.<key>.jsonnext to it.<key>is one of the language'sfeatures, or the name of a renderer option that this particular run sets (via a pinnedquickTestRendererOptionsentry)..out.files are excluded from test-input enumeration.Test case
test/inputs/json/priority/omit-empty.jsonis #2509's test input (a null field thatomitemptydrops):{ "results": [ { "age": 52, "name": null }, { "age": 27 } ] }A pinned
quickTestRendererOptionsentry runs it for Go withomit-empty, andomit-empty.out.omit-empty.jsonasserts the null field is actually dropped:{ "results": [ { "age": 52 }, { "age": 27 } ] }The plain (no-option) runs of this input still use the ordinary lenient round-trip comparison in every language, including Go: by default the Go renderer only tags non-null/union/any optionals with
,omitempty, so the null survives the round trip there.The input lives in
priority/, notmisc/, so it runs in CI —QUICKTESTskipsmisc/, which is why #2509's version of this test never actually ran in CI.Relation to #2509
test/lib/optionMap.ts) has since been covered byquickTestRendererOptionsintest/languages.ts, so it is not ported.*.in.json/*.out.json) idea, redesigned onto the existing.out.<feature>.jsonconvention. The test input and expected output are @Adam724's, credited as co-author.Testing
FIXTURE=golang script/test(full),FIXTURE=python script/test,FIXTURE=typescript script/test,FIXTURE=schema-golang script/testall green.🤖 Generated with Claude Code