diff --git a/commonmark_test.go b/commonmark_test.go index 64d5e3d..4e15daa 100644 --- a/commonmark_test.go +++ b/commonmark_test.go @@ -1,10 +1,12 @@ -package goldmark +package goldmark_test import ( "encoding/json" "io/ioutil" "testing" + . "github.com/yuin/goldmark" + "github.com/yuin/goldmark/testutil" "github.com/yuin/goldmark/renderer/html" ) @@ -26,9 +28,9 @@ func TestSpec(t *testing.T) { if err := json.Unmarshal(bs, &testCases); err != nil { panic(err) } - cases := []MarkdownTestCase{} + cases := []testutil.MarkdownTestCase{} for _, c := range testCases { - cases = append(cases, MarkdownTestCase{ + cases = append(cases, testutil.MarkdownTestCase{ No: c.Example, Markdown: c.Markdown, Expected: c.HTML, @@ -38,5 +40,5 @@ func TestSpec(t *testing.T) { html.WithXHTML(), html.WithUnsafe(), )) - DoTestCases(markdown, cases, t) + testutil.DoTestCases(markdown, cases, t) } diff --git a/extension/definition_list_test.go b/extension/definition_list_test.go index 1cbf167..2ee3c61 100644 --- a/extension/definition_list_test.go +++ b/extension/definition_list_test.go @@ -1,9 +1,11 @@ package extension import ( - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/renderer/html" "testing" + + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/testutil" + "github.com/yuin/goldmark/renderer/html" ) func TestDefinitionList(t *testing.T) { @@ -15,5 +17,5 @@ func TestDefinitionList(t *testing.T) { DefinitionList, ), ) - goldmark.DoTestCaseFile(markdown, "_test/definition_list.txt", t) + testutil.DoTestCaseFile(markdown, "_test/definition_list.txt", t) } diff --git a/extension/footnote_test.go b/extension/footnote_test.go index b5ce90c..0f2e0b5 100644 --- a/extension/footnote_test.go +++ b/extension/footnote_test.go @@ -1,9 +1,11 @@ package extension import ( - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/renderer/html" "testing" + + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/testutil" + "github.com/yuin/goldmark/renderer/html" ) func TestFootnote(t *testing.T) { @@ -15,5 +17,5 @@ func TestFootnote(t *testing.T) { Footnote, ), ) - goldmark.DoTestCaseFile(markdown, "_test/footnote.txt", t) + testutil.DoTestCaseFile(markdown, "_test/footnote.txt", t) } diff --git a/extension/linkify_test.go b/extension/linkify_test.go index 5a80b95..040d1ab 100644 --- a/extension/linkify_test.go +++ b/extension/linkify_test.go @@ -1,9 +1,11 @@ package extension import ( - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/renderer/html" "testing" + + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/testutil" + "github.com/yuin/goldmark/renderer/html" ) func TestLinkify(t *testing.T) { @@ -15,5 +17,5 @@ func TestLinkify(t *testing.T) { Linkify, ), ) - goldmark.DoTestCaseFile(markdown, "_test/linkify.txt", t) + testutil.DoTestCaseFile(markdown, "_test/linkify.txt", t) } diff --git a/extension/strikethrough_test.go b/extension/strikethrough_test.go index 891409e..05660ee 100644 --- a/extension/strikethrough_test.go +++ b/extension/strikethrough_test.go @@ -1,9 +1,11 @@ package extension import ( - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/renderer/html" "testing" + + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/testutil" + "github.com/yuin/goldmark/renderer/html" ) func TestStrikethrough(t *testing.T) { @@ -15,5 +17,5 @@ func TestStrikethrough(t *testing.T) { Strikethrough, ), ) - goldmark.DoTestCaseFile(markdown, "_test/strikethrough.txt", t) + testutil.DoTestCaseFile(markdown, "_test/strikethrough.txt", t) } diff --git a/extension/table_test.go b/extension/table_test.go index 7e38896..655f3fc 100644 --- a/extension/table_test.go +++ b/extension/table_test.go @@ -1,9 +1,11 @@ package extension import ( - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/renderer/html" "testing" + + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/testutil" + "github.com/yuin/goldmark/renderer/html" ) func TestTable(t *testing.T) { @@ -15,5 +17,5 @@ func TestTable(t *testing.T) { Table, ), ) - goldmark.DoTestCaseFile(markdown, "_test/table.txt", t) + testutil.DoTestCaseFile(markdown, "_test/table.txt", t) } diff --git a/extension/tasklist_test.go b/extension/tasklist_test.go index 6fc74d5..594471f 100644 --- a/extension/tasklist_test.go +++ b/extension/tasklist_test.go @@ -1,9 +1,11 @@ package extension import ( - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/renderer/html" "testing" + + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/testutil" + "github.com/yuin/goldmark/renderer/html" ) func TestTaskList(t *testing.T) { @@ -15,5 +17,5 @@ func TestTaskList(t *testing.T) { TaskList, ), ) - goldmark.DoTestCaseFile(markdown, "_test/tasklist.txt", t) + testutil.DoTestCaseFile(markdown, "_test/tasklist.txt", t) } diff --git a/extension/typographer_test.go b/extension/typographer_test.go index 6646314..bc1b21f 100644 --- a/extension/typographer_test.go +++ b/extension/typographer_test.go @@ -1,9 +1,11 @@ package extension import ( - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/renderer/html" "testing" + + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/testutil" + "github.com/yuin/goldmark/renderer/html" ) func TestTypographer(t *testing.T) { @@ -15,5 +17,5 @@ func TestTypographer(t *testing.T) { Typographer, ), ) - goldmark.DoTestCaseFile(markdown, "_test/typographer.txt", t) + testutil.DoTestCaseFile(markdown, "_test/typographer.txt", t) } diff --git a/extra_test.go b/extra_test.go index e2548b2..23d3506 100644 --- a/extra_test.go +++ b/extra_test.go @@ -1,8 +1,10 @@ -package goldmark +package goldmark_test import ( "testing" + . "github.com/yuin/goldmark" + "github.com/yuin/goldmark/testutil" "github.com/yuin/goldmark/renderer/html" ) @@ -11,5 +13,5 @@ func TestDefinitionList(t *testing.T) { html.WithXHTML(), html.WithUnsafe(), )) - DoTestCaseFile(markdown, "_test/extra.txt", t) + testutil.DoTestCaseFile(markdown, "_test/extra.txt", t) } diff --git a/options_test.go b/options_test.go index 2018bd1..d024a52 100644 --- a/options_test.go +++ b/options_test.go @@ -1,8 +1,11 @@ -package goldmark +package goldmark_test import ( - "github.com/yuin/goldmark/parser" "testing" + + . "github.com/yuin/goldmark" + "github.com/yuin/goldmark/testutil" + "github.com/yuin/goldmark/parser" ) func TestAttributeAndAutoHeadingID(t *testing.T) { @@ -12,5 +15,5 @@ func TestAttributeAndAutoHeadingID(t *testing.T) { parser.WithAutoHeadingID(), ), ) - DoTestCaseFile(markdown, "_test/options.txt", t) + testutil.DoTestCaseFile(markdown, "_test/options.txt", t) } diff --git a/testutil.go b/testutil/testutil.go similarity index 82% rename from testutil.go rename to testutil/testutil.go index 43d2d56..4a83a03 100644 --- a/testutil.go +++ b/testutil/testutil.go @@ -1,17 +1,26 @@ -package goldmark +package testutil import ( "bufio" "bytes" "fmt" - "github.com/yuin/goldmark/util" "os" "runtime/debug" "strconv" "strings" - testing "testing" + + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/util" ) +// TestingT is a subset of the functionality provided by testing.T. +type TestingT interface { + Logf(string, ...interface{}) + Skipf(string, ...interface{}) + Errorf(string, ...interface{}) + FailNow() +} + type MarkdownTestCase struct { No int Markdown string @@ -21,7 +30,7 @@ type MarkdownTestCase struct { const attributeSeparator = "//- - - - - - - - -//" const caseSeparator = "//= = = = = = = = = = = = = = = = = = = = = = = =//" -func DoTestCaseFile(m Markdown, filename string, t *testing.T) { +func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) { fp, err := os.Open(filename) if err != nil { panic(err) @@ -77,13 +86,13 @@ func DoTestCaseFile(m Markdown, filename string, t *testing.T) { DoTestCases(m, cases, t) } -func DoTestCases(m Markdown, cases []MarkdownTestCase, t *testing.T) { +func DoTestCases(m goldmark.Markdown, cases []MarkdownTestCase, t TestingT) { for _, testCase := range cases { DoTestCase(m, testCase, t) } } -func DoTestCase(m Markdown, testCase MarkdownTestCase, t *testing.T) { +func DoTestCase(m goldmark.Markdown, testCase MarkdownTestCase, t TestingT) { var ok bool var out bytes.Buffer defer func() { diff --git a/testutil/testutil_test.go b/testutil/testutil_test.go new file mode 100644 index 0000000..2000a00 --- /dev/null +++ b/testutil/testutil_test.go @@ -0,0 +1,7 @@ +package testutil + +import "testing" + +// This will fail to compile if the TestingT interface is changed in a way +// that doesn't conform to testing.T. +var _ TestingT = (*testing.T)(nil)