From 175c5ecd0c07bb07e1a7b030b81c1c85414ba839 Mon Sep 17 00:00:00 2001 From: yuin Date: Sat, 6 Aug 2022 19:59:30 +0900 Subject: [PATCH] Drop go 1.17 support --- .github/workflows/test.yaml | 2 +- Makefile | 8 +---- README.md | 2 +- fuzz/fuzz.go | 39 --------------------- fuzz/fuzz_test.go | 68 ++++++++++++++++++++----------------- 5 files changed, 39 insertions(+), 80 deletions(-) delete mode 100644 fuzz/fuzz.go diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index eb1f033..dc623fe 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -5,7 +5,7 @@ jobs: strategy: fail-fast: false matrix: - go-version: [1.17.x, 1.18.x] + go-version: [1.18.x, 1.19.x] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: diff --git a/Makefile b/Makefile index d0b99cf..e34fe86 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,4 @@ cov: test go tool cover -html=profile.out fuzz: - which go-fuzz > /dev/null 2>&1 || (GO111MODULE=off go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build; GO111MODULE=off go get -d github.com/dvyukov/go-fuzz-corpus; true) - rm -rf ./fuzz/corpus - rm -rf ./fuzz/crashers - rm -rf ./fuzz/suppressions - rm -f ./fuzz/fuzz-fuzz.zip - cd ./fuzz && GO111MODULE=off go-fuzz-build - cd ./fuzz && go-fuzz + cd ./fuzz && go test -fuzz=Fuzz diff --git a/README.md b/README.md index e3d6918..3b0c59a 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Features renderers. - **Performance.** goldmark's performance is on par with that of cmark, the CommonMark reference implementation written in C. -- **Robust.** goldmark is tested with [go-fuzz](https://github.com/dvyukov/go-fuzz), a fuzz testing tool. +- **Robust.** goldmark is tested with `go test --fuzz`. - **Built-in extensions.** goldmark ships with common extensions like tables, strikethrough, task lists, and definition lists. - **Depends only on standard libraries.** diff --git a/fuzz/fuzz.go b/fuzz/fuzz.go deleted file mode 100644 index 5e72d16..0000000 --- a/fuzz/fuzz.go +++ /dev/null @@ -1,39 +0,0 @@ -package fuzz - -import ( - "bytes" - - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/extension" - "github.com/yuin/goldmark/parser" - "github.com/yuin/goldmark/renderer/html" -) - -// Fuzz runs automated fuzzing against goldmark. -func Fuzz(data []byte) int { - markdown := goldmark.New( - goldmark.WithParserOptions( - parser.WithAutoHeadingID(), - parser.WithAttribute(), - ), - goldmark.WithRendererOptions( - html.WithUnsafe(), - html.WithXHTML(), - ), - goldmark.WithExtensions( - extension.DefinitionList, - extension.Footnote, - extension.GFM, - extension.Linkify, - extension.Table, - extension.TaskList, - extension.Typographer, - ), - ) - var b bytes.Buffer - if err := markdown.Convert(data, &b); err != nil { - return 0 - } - - return 1 -} diff --git a/fuzz/fuzz_test.go b/fuzz/fuzz_test.go index c7bfada..9c9483a 100644 --- a/fuzz/fuzz_test.go +++ b/fuzz/fuzz_test.go @@ -2,7 +2,7 @@ package fuzz import ( "bytes" - "fmt" + "encoding/json" "io/ioutil" "testing" @@ -13,38 +13,42 @@ import ( "github.com/yuin/goldmark/util" ) -var _ = fmt.Printf - -func TestFuzz(t *testing.T) { - crasher := "6dff3d03167cb144d4e2891edac76ee740a77bc7" - data, err := ioutil.ReadFile("crashers/" + crasher) +func Fuzz(f *testing.F) { + bs, err := ioutil.ReadFile("../_test/spec.json") if err != nil { - return - } - fmt.Printf("%s\n", util.VisualizeSpaces(data)) - fmt.Println("||||||||||||||||||||||") - markdown := goldmark.New( - goldmark.WithParserOptions( - parser.WithAutoHeadingID(), - parser.WithAttribute(), - ), - goldmark.WithRendererOptions( - html.WithUnsafe(), - html.WithXHTML(), - ), - goldmark.WithExtensions( - extension.DefinitionList, - extension.Footnote, - extension.GFM, - extension.Typographer, - extension.Linkify, - extension.Table, - extension.TaskList, - ), - ) - var b bytes.Buffer - if err := markdown.Convert(data, &b); err != nil { panic(err) } - fmt.Println(b.String()) + var testCases []map[string]interface{} + if err := json.Unmarshal(bs, &testCases); err != nil { + panic(err) + } + for _, c := range testCases { + f.Add(c["markdown"]) + } + + f.Fuzz(func(t *testing.T, orig string) { + markdown := goldmark.New( + goldmark.WithParserOptions( + parser.WithAutoHeadingID(), + parser.WithAttribute(), + ), + goldmark.WithRendererOptions( + html.WithUnsafe(), + html.WithXHTML(), + ), + goldmark.WithExtensions( + extension.DefinitionList, + extension.Footnote, + extension.GFM, + extension.Typographer, + extension.Linkify, + extension.Table, + extension.TaskList, + ), + ) + var b bytes.Buffer + if err := markdown.Convert(util.StringToReadOnlyBytes(orig), &b); err != nil { + panic(err) + } + }) }