From 80c626455521fc53e98842b2b93a78841a474f3c Mon Sep 17 00:00:00 2001 From: Spiegel Date: Sat, 2 Mar 2019 17:36:17 +0900 Subject: [PATCH] Add new error handler --- .travis.yml | 2 +- README.md | 20 ---- cli/mklink/facade/facade.go | 4 +- cli/mklink/facade/facade_test.go | 14 +++ cli/mklink/facade/interactive.go | 14 ++- cli/mklink/makelink/makelink.go | 8 +- cli/mklink/makelink/makelink_test.go | 12 ++- errs/cause.go | 30 ++++++ errs/cause_test.go | 38 ++++++++ errs/errs.go | 38 ++++++++ errs/errs_test.go | 136 +++++++++++++++++++++++++++ errs/wrapper.go | 67 +++++++++++++ go.mod | 6 +- mklink.go | 8 +- mklink_test.go | 2 +- style.go | 32 ++----- style_test.go | 21 +++-- 17 files changed, 373 insertions(+), 79 deletions(-) create mode 100644 errs/cause.go create mode 100644 errs/cause_test.go create mode 100644 errs/errs.go create mode 100644 errs/errs_test.go create mode 100644 errs/wrapper.go diff --git a/.travis.yml b/.travis.yml index c426266..8cc132c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: -- "1.11.x" +- "1.12" env: global: diff --git a/README.md b/README.md index de59341..3490b59 100644 --- a/README.md +++ b/README.md @@ -8,26 +8,6 @@ See [go.mod](https://github.com/spiegel-im-spiegel/mklink/blob/master/go.mod) file. -### Module Requirement Graph - -``` -$ go mod graph -github.com/spiegel-im-spiegel/mklink github.com/PuerkitoBio/goquery@v1.5.0 -github.com/spiegel-im-spiegel/mklink github.com/atotto/clipboard@v0.1.1 -github.com/spiegel-im-spiegel/mklink github.com/inconshreveable/mousetrap@v1.0.0 -github.com/spiegel-im-spiegel/mklink github.com/mattn/go-encoding@v0.0.2 -github.com/spiegel-im-spiegel/mklink github.com/pkg/errors@v0.8.1 -github.com/spiegel-im-spiegel/mklink github.com/spf13/cobra@v0.0.3 -github.com/spiegel-im-spiegel/mklink github.com/spf13/pflag@v1.0.3 -github.com/spiegel-im-spiegel/mklink github.com/spiegel-im-spiegel/gocli@v0.9.1 -github.com/spiegel-im-spiegel/mklink golang.org/x/net@v0.0.0-20190206173232-65e2d4e15006 -github.com/spiegel-im-spiegel/mklink golang.org/x/text@v0.3.0 -github.com/spiegel-im-spiegel/gocli@v0.9.1 github.com/mattn/go-isatty@v0.0.4 -github.com/PuerkitoBio/goquery@v1.5.0 github.com/andybalholm/cascadia@v1.0.0 -github.com/PuerkitoBio/goquery@v1.5.0 golang.org/x/net@v0.0.0-20181114220301-adae6a3d119a -github.com/andybalholm/cascadia@v1.0.0 golang.org/x/net@v0.0.0-20180218175443-cbe0f9307d01 -``` - ## Usage ```go diff --git a/cli/mklink/facade/facade.go b/cli/mklink/facade/facade.go index b126fd0..56c9386 100644 --- a/cli/mklink/facade/facade.go +++ b/cli/mklink/facade/facade.go @@ -89,9 +89,7 @@ func newRootCmd(ui *rwi.RWI, args []string) *cobra.Command { } _ = ui.Outputln() } - if err := scanner.Err(); err != nil { - return err - } + return scanner.Err() } return nil }, diff --git a/cli/mklink/facade/facade_test.go b/cli/mklink/facade/facade_test.go index b5c57e9..633c548 100644 --- a/cli/mklink/facade/facade_test.go +++ b/cli/mklink/facade/facade_test.go @@ -2,12 +2,26 @@ package facade import ( "bytes" + "fmt" "testing" "github.com/spiegel-im-spiegel/gocli/exitcode" "github.com/spiegel-im-spiegel/gocli/rwi" ) +func TestInteractiveError(t *testing.T) { + outBuf := new(bytes.Buffer) + outErrBuf := new(bytes.Buffer) + ui := rwi.New(rwi.WithWriter(outBuf), rwi.WithErrorWriter(outErrBuf)) + args := []string{"-i"} + + exit := Execute(ui, args) + if exit == exitcode.Normal { + t.Errorf("Execute(markdown) = \"%v\", want \"%v\".", exit, exitcode.Abnormal) + } + fmt.Printf("Info: %v", outErrBuf.String()) +} + func TestStyleMarkdown(t *testing.T) { outBuf := new(bytes.Buffer) outErrBuf := new(bytes.Buffer) diff --git a/cli/mklink/facade/interactive.go b/cli/mklink/facade/interactive.go index 3815492..f6bca08 100644 --- a/cli/mklink/facade/interactive.go +++ b/cli/mklink/facade/interactive.go @@ -5,10 +5,11 @@ import ( "io" "github.com/atotto/clipboard" - "github.com/pkg/errors" "github.com/spiegel-im-spiegel/gocli/prompt" "github.com/spiegel-im-spiegel/gocli/rwi" "github.com/spiegel-im-spiegel/mklink/cli/mklink/makelink" + "github.com/spiegel-im-spiegel/mklink/errs" + errors "golang.org/x/xerrors" ) func interactiveMode(ui *rwi.RWI, cxt *makelink.Context) error { @@ -23,14 +24,14 @@ func interactiveMode(ui *rwi.RWI, cxt *makelink.Context) error { } r, err := cxt.MakeLink(url) if err != nil { - return err.Error(), nil + return errs.Cause(err).Error(), nil } buf := &bytes.Buffer{} if _, err := io.Copy(buf, r); err != nil { - return "", err + return "", errs.Wrap(err, "error when output result") } res := buf.String() - return res, clipboard.WriteAll(res) + return res, errs.Wrap(clipboard.WriteAll(res), "error when output result") }, prompt.WithPromptString("mklink> "), prompt.WithHeaderMessage("Input 'q' or 'quit' to stop"), @@ -38,10 +39,7 @@ func interactiveMode(ui *rwi.RWI, cxt *makelink.Context) error { if !p.IsTerminal() { return errors.New("not terminal (or pipe?)") } - if err := p.Run(); err != nil { - return err - } - return nil + return errs.Wrap(p.Run(), "error in interactive mode") } /* Copyright 2019 Spiegel diff --git a/cli/mklink/makelink/makelink.go b/cli/mklink/makelink/makelink.go index 29cc36c..d21227e 100644 --- a/cli/mklink/makelink/makelink.go +++ b/cli/mklink/makelink/makelink.go @@ -5,8 +5,8 @@ import ( "fmt" "io" - "github.com/pkg/errors" "github.com/spiegel-im-spiegel/mklink" + "github.com/spiegel-im-spiegel/mklink/errs" ) //Context class is context for making link @@ -23,11 +23,11 @@ func New(s mklink.Style, log io.Writer) *Context { //MakeLink is making link func (c *Context) MakeLink(url string) (io.Reader, error) { if c == nil { - return nil, errors.New("nil pointer in makelink.Context.MakeLink() function") + return nil, errs.Wrap(errs.ErrNullPointer, "reference error") } lnk, err := mklink.New(url) if err != nil { - return nil, err + return nil, errs.Wrap(err, "error in constructor") } rRes := lnk.Encode(c.linkStyle) @@ -36,7 +36,7 @@ func (c *Context) MakeLink(url string) (io.Reader, error) { } buf := new(bytes.Buffer) if _, err := io.Copy(c.log, io.TeeReader(rRes, buf)); err != nil { - return buf, err + return buf, errs.Wrap(err, "error in logging") } fmt.Fprintln(c.log) //new line in logfile return buf, nil diff --git a/cli/mklink/makelink/makelink_test.go b/cli/mklink/makelink/makelink_test.go index 725bb43..376d12f 100644 --- a/cli/mklink/makelink/makelink_test.go +++ b/cli/mklink/makelink/makelink_test.go @@ -2,7 +2,9 @@ package makelink import ( "bytes" + "fmt" "io" + "os" "testing" "github.com/spiegel-im-spiegel/mklink" @@ -12,11 +14,11 @@ func TestMakeLink(t *testing.T) { logBuf := new(bytes.Buffer) rRes, err := New(mklink.StyleMarkdown, logBuf).MakeLink("https://git.io/vFR5M") if err != nil { - t.Errorf("Error of Context.MakeLink() = %v, want nil.", err) + t.Errorf("Error in Context.MakeLink(): %+v", err) } outBuf := new(bytes.Buffer) if _, err := io.Copy(outBuf, rRes); err != nil { - t.Errorf("Error of io.Copy() = %v, want nil.", err) + t.Errorf("Error in io.Copy(): %+v", err) } res := "[GitHub - spiegel-im-spiegel/mklink: Make Link with Markdown Format](https://github.com/spiegel-im-spiegel/mklink)" @@ -33,11 +35,11 @@ func TestMakeLink(t *testing.T) { func TestMakeLinkNil(t *testing.T) { rRes, err := New(mklink.StyleMarkdown, nil).MakeLink("https://git.io/vFR5M") if err != nil { - t.Errorf("Context.MakeLink() = \"%v\", want nil error.", err) + t.Errorf("Error in Context.MakeLink(): %+v", err) } outBuf := new(bytes.Buffer) if _, err := io.Copy(outBuf, rRes); err != nil { - t.Errorf("Error of io.Copy() = %v, want nil.", err) + t.Errorf("Error in io.Copy(): %+v", err) } res := "[GitHub - spiegel-im-spiegel/mklink: Make Link with Markdown Format](https://github.com/spiegel-im-spiegel/mklink)" @@ -51,6 +53,8 @@ func TestMakeLinkErr(t *testing.T) { _, err := New(mklink.StyleMarkdown, nil).MakeLink("https://foo.bar") if err == nil { t.Error("Context.MakeLink() = nil error, not want nil error.") + } else { + fmt.Fprintf(os.Stderr, "info: %+v\n", err) } } diff --git a/errs/cause.go b/errs/cause.go new file mode 100644 index 0000000..9809682 --- /dev/null +++ b/errs/cause.go @@ -0,0 +1,30 @@ +package errs + +import ( + errors "golang.org/x/xerrors" +) + +func Cause(err error) error { + for { + unwrap := errors.Unwrap(err) + if unwrap == nil { + return err + } + err = unwrap + } +} + +/* Copyright 2019 Spiegel +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. + */ diff --git a/errs/cause_test.go b/errs/cause_test.go new file mode 100644 index 0000000..6008da8 --- /dev/null +++ b/errs/cause_test.go @@ -0,0 +1,38 @@ +package errs + +import ( + "testing" +) + +func TestCause(t *testing.T) { + testCases := []struct { + err error + cause error + }{ + {err: nil, cause: nil}, + {err: ErrNoImplement, cause: ErrNoImplement}, + {err: Wrap(ErrNoImplement, "wrapping error"), cause: ErrNoImplement}, + } + + for _, tc := range testCases { + res := Cause(tc.err) + if res != tc.cause { + t.Errorf("Cause in \"%v\" == \"%v\", want \"%v\"", tc.err, res, tc.cause) + } + } +} + +/* Copyright 2019 Spiegel +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. + */ diff --git a/errs/errs.go b/errs/errs.go new file mode 100644 index 0000000..88c148f --- /dev/null +++ b/errs/errs.go @@ -0,0 +1,38 @@ +package errs + +import "fmt" + +//Num is error number for CVSS +type Num int + +const ( + ErrNullPointer Num = iota + 1 + ErrNoImplement +) + +var errMessage = map[Num]string{ + ErrNullPointer: "Null reference instance", + ErrNoImplement: "This style is not implementation", +} + +func (n Num) Error() string { + if s, ok := errMessage[n]; ok { + return s + } + return fmt.Sprintf("unknown error (%d)", int(n)) +} + +/* Copyright 2019 Spiegel +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. + */ diff --git a/errs/errs_test.go b/errs/errs_test.go new file mode 100644 index 0000000..436eed2 --- /dev/null +++ b/errs/errs_test.go @@ -0,0 +1,136 @@ +package errs + +import ( + "fmt" + "testing" + + errors "golang.org/x/xerrors" +) + +func TestNumError(t *testing.T) { + testCases := []struct { + err error + str string + }{ + {err: Num(0), str: "unknown error (0)"}, + {err: ErrNoImplement, str: "This style is not implementation"}, + {err: ErrNullPointer, str: "Null reference instance"}, + {err: Num(3), str: "unknown error (3)"}, + } + + for _, tc := range testCases { + errStr := tc.err.Error() + if errStr != tc.str { + t.Errorf("\"%v\" != \"%v\"", errStr, tc.str) + } + fmt.Printf("Info(TestNumError): %+v\n", tc.err) + } +} + +func TestNumErrorEquality(t *testing.T) { + testCases := []struct { + err1 error + err2 error + res bool + }{ + {err1: ErrNullPointer, err2: ErrNullPointer, res: true}, + {err1: ErrNoImplement, err2: ErrNoImplement, res: true}, + {err1: ErrNullPointer, err2: Wrap(ErrNullPointer, "wrapping error"), res: false}, + {err1: ErrNoImplement, err2: Wrap(ErrNoImplement, "wrapping error"), res: false}, + {err1: ErrNullPointer, err2: nil, res: false}, + {err1: ErrNullPointer, err2: Num(0), res: false}, + } + + for _, tc := range testCases { + res := errors.Is(tc.err1, tc.err2) + if res != tc.res { + t.Errorf("\"%v\" == \"%v\" ? %v, want %v", tc.err1, tc.err2, res, tc.res) + } + } +} + +func TestWrapError(t *testing.T) { + testCases := []struct { + err error + msg string + str string + }{ + {err: ErrNullPointer, msg: "wrapping error", str: "wrapping error: Null reference instance"}, + {err: ErrNoImplement, msg: "wrapping error", str: "wrapping error: This style is not implementation"}, + } + + for _, tc := range testCases { + we := Wrap(tc.err, tc.msg) + if we.Error() != tc.str { + t.Errorf("wrapError.Error() == \"%v\", want \"%v\"", we.Error(), tc.str) + } + fmt.Printf("Info(TestWrapError): %+v\n", we) + } +} + +func TestWrapNilError(t *testing.T) { + if we := Wrap(nil, "null error"); we != nil { + t.Errorf("Wrap(nil) == \"%v\", want nil.", we) + } +} + +func TestWrapfError(t *testing.T) { + testCases := []struct { + err error + msg string + str string + }{ + {err: ErrNoImplement, msg: "wrapping error", str: "wrapping error: This style is not implementation"}, + {err: ErrNullPointer, msg: "wrapping error", str: "wrapping error: Null reference instance"}, + } + + for _, tc := range testCases { + we := Wrapf(tc.err, "%v", tc.msg) + if we.Error() != tc.str { + t.Errorf("wrapError.Error() == \"%v\", want \"%v\"", we.Error(), tc.str) + } + fmt.Printf("Info(TestWrapfError): %+v\n", we) + } +} + +func TestWrapfNilError(t *testing.T) { + if we := Wrapf(nil, "%v", "null error"); we != nil { + t.Errorf("Wrapf(nil) == \"%v\", want nil.", we) + } +} + +func TestWrapErrorEquality(t *testing.T) { + testCases := []struct { + err1 error + err2 error + res bool + }{ + {err1: Wrap(ErrNoImplement, "wrapping error"), err2: ErrNoImplement, res: true}, + {err1: Wrap(ErrNullPointer, "wrapping error"), err2: ErrNullPointer, res: true}, + {err1: Wrap(ErrNoImplement, "wrapping error"), err2: nil, res: false}, + {err1: Wrap(ErrNoImplement, "wrapping error"), err2: Num(0), res: false}, + {err1: Wrap(ErrNoImplement, "wrapping error"), err2: Wrap(Num(0), "wrapping error"), res: false}, + } + + for _, tc := range testCases { + res := errors.Is(tc.err1, tc.err2) + if res != tc.res { + t.Errorf("\"%v\" == \"%v\" ? %v, want %v", tc.err1, tc.err2, res, tc.res) + } + } +} + +/* Copyright 2019 Spiegel +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. + */ diff --git a/errs/wrapper.go b/errs/wrapper.go new file mode 100644 index 0000000..14af44b --- /dev/null +++ b/errs/wrapper.go @@ -0,0 +1,67 @@ +package errs + +import ( + "fmt" + + errors "golang.org/x/xerrors" +) + +//wrapError is wrapper for error instance +type wrapError struct { + msg string + cause error + frame errors.Frame +} + +//Wrap returns wraped error instance +func Wrap(err error, msg string) error { + if err == nil { + return nil + } + return &wrapError{msg: msg, cause: err, frame: errors.Caller(1)} +} + +//Wrapf returns wraped error instance +func Wrapf(err error, format string, args ...interface{}) error { + if err == nil { + return nil + } + return &wrapError{msg: fmt.Sprintf(format, args...), cause: err, frame: errors.Caller(1)} +} + +//Error method for error interface +func (we *wrapError) Error() string { + return fmt.Sprintf("%v: %v", we.msg, we.cause) +} + +//Unwrap method for errors.Wrapper interface +func (e *wrapError) Unwrap() error { + return e.cause +} + +//Format method for fmt.Formatter interface +func (we *wrapError) Format(s fmt.State, v rune) { + errors.FormatError(we, s, v) +} + +//FormatError method for errors.Formatter interface +func (we *wrapError) FormatError(p errors.Printer) error { + p.Print(we.msg) + we.frame.Format(p) + return we.cause +} + +/* Copyright 2019 Spiegel +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. + */ diff --git a/go.mod b/go.mod index e0f7ddd..50f37c4 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,10 @@ require ( github.com/atotto/clipboard v0.1.1 github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/mattn/go-encoding v0.0.2 - github.com/pkg/errors v0.8.1 github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.3 // indirect - github.com/spiegel-im-spiegel/gocli v0.9.1 - golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 + github.com/spiegel-im-spiegel/gocli v0.9.2 + golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95 golang.org/x/text v0.3.0 // indirect + golang.org/x/xerrors v0.0.0-20190212162355-a5947ffaace3 ) diff --git a/mklink.go b/mklink.go index f80b668..12171ca 100644 --- a/mklink.go +++ b/mklink.go @@ -12,7 +12,7 @@ import ( "github.com/PuerkitoBio/goquery" encoding "github.com/mattn/go-encoding" - "github.com/pkg/errors" + "github.com/spiegel-im-spiegel/mklink/errs" "golang.org/x/net/html/charset" ) @@ -29,7 +29,7 @@ func New(url string) (*Link, error) { link := &Link{URL: trimString(url)} resp, err := http.Get(url) if err != nil { - return link, err + return link, errs.Wrap(err, "Create mklink.Link instance") } defer resp.Body.Close() @@ -49,7 +49,7 @@ func New(url string) (*Link, error) { } doc, err := goquery.NewDocumentFromReader(r) if err != nil { - return link, err + return link, errs.Wrap(err, "Create mklink.Link instance") } doc.Find("head").Each(func(_ int, s *goquery.Selection) { @@ -90,7 +90,7 @@ func (lnk *Link) JSON() (io.Reader, error) { encoder := json.NewEncoder(buf) encoder.SetIndent("", " ") if err := encoder.Encode(lnk); err != nil { - return ioutil.NopCloser(bytes.NewReader(nil)), errors.Wrap(err, "error in mklink.Link.JSON() function") + return ioutil.NopCloser(bytes.NewReader(nil)), errs.Wrap(err, "error in encoding JSON") } return buf, nil } diff --git a/mklink_test.go b/mklink_test.go index 9be8903..16c13db 100644 --- a/mklink_test.go +++ b/mklink_test.go @@ -74,7 +74,7 @@ func TestNewErr(t *testing.T) { if err == nil { t.Error("New() = nil error, not want nil error.") } else { - fmt.Fprintf(os.Stderr, "info: %v\n", err) + fmt.Fprintf(os.Stderr, "info: %+v\n", err) } } diff --git a/style.go b/style.go index 6fb214b..7fcd22d 100644 --- a/style.go +++ b/style.go @@ -1,16 +1,9 @@ package mklink import ( - "bytes" - "io" "strings" - "github.com/pkg/errors" -) - -var ( - //ErrNoImplement is error "no implementation" - ErrNoImplement = errors.New("no implementation") + "github.com/spiegel-im-spiegel/mklink/errs" ) //Style as link style @@ -36,26 +29,17 @@ var ( StyleHTML: "html", StyleCSV: "csv", } - styleList = []Style{ - StyleMarkdown, - StyleWiki, - StyleHTML, - StyleCSV, + styleList = []string{ + styleMap[StyleMarkdown], + styleMap[StyleWiki], + styleMap[StyleHTML], + styleMap[StyleCSV], } ) //StyleList returns string Style list func StyleList() string { - buf := new(bytes.Buffer) - sep := "" - for _, t := range styleList { - if name, ok := styleMap[t]; ok { - io.WriteString(buf, sep) - io.WriteString(buf, name) - sep = " " - } - } - return buf.String() + return strings.Join(styleList, " ") } //GetStyle returns Style from string @@ -66,7 +50,7 @@ func GetStyle(s string) (Style, error) { return t, nil } } - return StyleUnknown, errors.Wrap(ErrNoImplement, "error "+s) + return StyleUnknown, errs.Wrapf(errs.ErrNoImplement, "error in \"%v\" style", s) } func (t Style) String() string { diff --git a/style_test.go b/style_test.go index 81ff763..9cd21bb 100644 --- a/style_test.go +++ b/style_test.go @@ -1,6 +1,12 @@ package mklink -import "testing" +import ( + "fmt" + "testing" + + "github.com/spiegel-im-spiegel/mklink/errs" + errors "golang.org/x/xerrors" +) type typesTestCase struct { name string @@ -18,19 +24,20 @@ func TestGetStyle(t *testing.T) { for _, tst := range typesTests { tps, err := GetStyle(tst.name) if err != nil { - t.Errorf("GetStyles() = \"%v\", want nil error.", err) + t.Errorf("GetStyles() = \"%+v\".", err) } else if tps.String() != tst.t.String() { - t.Errorf("GetStyles() = \"%v\", want \"%v\".", tps, tst.t) + t.Errorf("GetStyles() = \"%v\", want \"%v\".", tps, tst.t) } } } func TestGetStyleErr(t *testing.T) { tps, err := GetStyle("foobar") - if err == nil { - t.Error("GetStyles(foobar) = nil error, not want nil error.") + fmt.Printf("Info(TestGetStyleErr): %+v\n", err) + if !errors.Is(err, errs.ErrNoImplement) { + t.Errorf("GetStyles(foobar) error = \"%v\", want \"%v\".", err, errs.ErrNoImplement) } else if tps.String() != "unknown" { - t.Errorf("GetStyles(foobar) = \"%v\", want \"unknown\".", tps) + t.Errorf("GetStyles(foobar) = \"%v\", want \"unknown\".", tps) } } @@ -38,7 +45,7 @@ func TestStyleList(t *testing.T) { str := StyleList() res := "markdown wiki html csv" if str != res { - t.Errorf("StylesList() = \"%v\", want \"%v\".", str, res) + t.Errorf("StylesList() = \"%v\", want \"%v\".", str, res) } }