Skip to content

Enhance testing capabilities#2509

Closed
Adam724 wants to merge 10 commits into
glideapps:masterfrom
Adam724:allow-cli-options-in-tests
Closed

Enhance testing capabilities#2509
Adam724 wants to merge 10 commits into
glideapps:masterfrom
Adam724:allow-cli-options-in-tests

Conversation

@Adam724

@Adam724 Adam724 commented Feb 16, 2024

Copy link
Copy Markdown
Contributor

Currently, there is no way to pass cliOptions in the automated tests, making it difficult to test these flags. This PR aims to solve that with the following:

  1. Adds a test configuration object in test/lib/optionMap.ts. This allows you to specify a test file path as key, and a configuration object as the value to customize the cliOptions, comparisonArgs, and target language for that test.
  2. If the current test language does not match that specified in optionMap, the test is skipped. This is necessary since different languages support different CLI options.
  3. Allows you to specify an input and expected output JSON file for tests. This is necessary since some cliOptions (such as omit-empty) are expected to produce a different JSON as output in some cases. I've adopted a standard file naming for input files matching this regex: /^(.*)\.in\.(.*)$/, and output files matching this regex: /^\1\.out\.\2$/. For example myCustomTest.in.json and myCustomTest.out.json. If an input file is found with no matching output, an error is thrown with a message indicating the issue.

No changes are necessary for any existing tests, this just adds the ability to write more customizable additional tests. Unsure if there is a better way to do this, any feedback is welcome!

Comment thread test/lib/optionMap.ts
};

const optionMap: Record<string, TestOptions> = {
"test/inputs/json/misc/227e2.in.json": {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means, for 227e2.in.json, the test will be run with omit-empty set to true, strict comparison of input and expected output, and will only run for Golang language.

@schani

schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Thanks @Adam724 — this PR pointed at a real gap, and both of its ideas ended up in the codebase in some form.

The per-test CLI options half has since been superseded: quickTestRendererOptions in test/languages.ts now covers running specific inputs with specific renderer options, so the optionMap mechanism isn't needed anymore.

The other half — expected-output files so a test can assert output that legitimately differs from the input (your Go omit-empty case) — was still missing, and lives on in #2961, rebuilt on the JSON Schema fixtures' existing .out.<feature>.json convention and using your test input, with credit as co-author. Leaving this PR open for reference until that lands.

schani added a commit that referenced this pull request Jul 20, 2026
test: expected-output fixtures for JSON inputs (salvaged from #2509)
@schani schani closed this Jul 20, 2026
schani added a commit to tolbon/quicktype that referenced this pull request Jul 20, 2026
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 glideapps#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 glideapps#2509; the test case is Adam724's.

Co-authored-by: Adam724 <alaspina6@gmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants