Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance testing capabilities #2509

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Adam724
Copy link
Contributor

@Adam724 Adam724 commented Feb 16, 2024

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!

};

const optionMap: Record<string, TestOptions> = {
"test/inputs/json/misc/227e2.in.json": {
Copy link
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