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(...)`.
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).
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.
This moves the following functions meant for use from tests into a
testutil subpackage.
func DoTestCase(m Markdown, testCase MarkdownTestCase, t TestingT)
func DoTestCaseFile(m Markdown, filename string, t TestingT)
func DoTestCases(m goldmark.Markdown, cases []MarkdownTestCase, t TestingT)
This will help keep the top-level goldmark package clean and limited to
core functionality.
(Note that tests in the top-level goldmark package that make use of
these functions must now use the package name `goldmark_test` so that
they're considered separate from the main `goldmark` package, otherwise
you'll see an import cycle: goldmark imports testutil imports goldmark.)