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

testutil: Export ParseTestCaseFile #336

Closed
wants to merge 4 commits into from
Closed

testutil: Export ParseTestCaseFile #336

wants to merge 4 commits into from

Conversation

abhinav
Copy link
Contributor

@abhinav abhinav commented Nov 11, 2022

This PR extracts functionality from DoTestCaseFile
responsible for parsing test case files
into a ParseTestCases function.

The function is able to read from any io.Reader,
instead of being limited to just files.
A ParseTestCaseFile function is included for convenience.

The functions do not panic on errors--instead, they return the error.

While there, this updates DoTestCaseFile
so that it also does not panic on error,
and instead aborts the entire test instead.

Minor note about tests:
The tests for the parser use reflect.DeepEqual and %#v.
It would make for better error messages to use go-cmp
but I elected to not use that because so far,
goldmark has no third-party dependencies.
If you're open to the new dependency (only for test util),
I can make a separate PR for that in the future.

@abhinav abhinav changed the title testutil: Export ParseTestCases testutil: Export ParseTestCaseFile Nov 11, 2022
This moves the logic for parsing a test case file
into a separate function named ParseTestCaseFile.
This will make it easier for extensions
to use the same format for test files,
even if they want a different strategy to run them.

The function does not do filtering like DoTestCaseFile;
that logic has been left inside DoTestCaseFile.

Minus that, this function does not modify any logic.
The next commits do.
Instead of panicking, ParseTestCaseFile now reports errors.
The errors take the form,

    line $line: $msg: $cause

For example,

    line 12: invalid case No: parse error

As a result of this change,
we no longer discard the error returned by strconv.Atoi or json.Marshal
when we reject the test file,
and include it in the error message instead.

Note that the errors do not include the file name
because the file name is always the same
so the caller can add that if necessary
(which it will, in the next commit).
Instead of panicking, report the error in the form,

    $file: $msg

So an error might look like,

    foo.txt: line 12: invalid case No: [..]

And then kill the test with FailNow.
This is the same as calling `t.Fatalf(...)`.
Move core logic to ParseTestCases,
which operates on an io.Reader,
but keep the file-based function around for convenience.
@stale
Copy link

stale bot commented Jan 7, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 7, 2023
@abhinav abhinav closed this by deleting the head repository Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant