Skip to content

Enhance testing capabilities#2509

Open
Adam724 wants to merge 9 commits into
glideapps:masterfrom
Adam724:allow-cli-options-in-tests
Open

Enhance testing capabilities#2509
Adam724 wants to merge 9 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.

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.

2 participants