diff --git a/testutil.go b/testutil.go index 43d2d56..9f3ba52 100644 --- a/testutil.go +++ b/testutil.go @@ -4,14 +4,22 @@ import ( "bufio" "bytes" "fmt" - "github.com/yuin/goldmark/util" "os" "runtime/debug" "strconv" "strings" - testing "testing" + + "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 +29,7 @@ type MarkdownTestCase struct { const attributeSeparator = "//- - - - - - - - -//" const caseSeparator = "//= = = = = = = = = = = = = = = = = = = = = = = =//" -func DoTestCaseFile(m Markdown, filename string, t *testing.T) { +func DoTestCaseFile(m Markdown, filename string, t TestingT) { fp, err := os.Open(filename) if err != nil { panic(err) @@ -77,13 +85,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 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 Markdown, testCase MarkdownTestCase, t TestingT) { var ok bool var out bytes.Buffer defer func() { diff --git a/testutil_test.go b/testutil_test.go new file mode 100644 index 0000000..2ab24a6 --- /dev/null +++ b/testutil_test.go @@ -0,0 +1,7 @@ +package goldmark + +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)