| 1 | // Copyright ©2011-2013 The bíogo Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package errors |
| 6 | |
| 7 | import ( |
| 8 | "testing" |
| 9 | |
| 10 | "gopkg.in/check.v1" |
| 11 | ) |
| 12 | |
| 13 | func Test(t *testing.T) { check.TestingT(t) } |
| 14 | |
| 15 | type S struct{} |
| 16 | |
| 17 | var _ = check.Suite(&S{}) |
| 18 | |
| 19 | // Helpers |
| 20 | func f(i int) error { |
| 21 | if i == 0 { |
| 22 | return Make("message", 0, 10) |
| 23 | } |
| 24 | |
| 25 | i-- |
| 26 | return f(i) |
| 27 | } |
| 28 | |
| 29 | var traceRE = `Trace: message: |
| 30 | |
| 31 | github.com/biogo/biogo/errors.f: |
| 32 | (?:[A-Z]:)?/.*/github.com/biogo/biogo/errors/errors_test.go#L=22 |
| 33 | (?:[A-Z]:)?/.*/github.com/biogo/biogo/errors/errors_test.go#L=26 |
| 34 | (?:[A-Z]:)?/.*/github.com/biogo/biogo/errors/errors_test.go#L=26 |
| 35 | (?:[A-Z]:)?/.*/github.com/biogo/biogo/errors/errors_test.go#L=26 |
| 36 | (?:[A-Z]:)?/.*/github.com/biogo/biogo/errors/errors_test.go#L=26 |
| 37 | (?:[A-Z]:)?/.*/github.com/biogo/biogo/errors/errors_test.go#L=26 |
| 38 | |
| 39 | github.com/biogo/biogo/errors.\(\*S\).TestCaller: |
| 40 | (?:[A-Z]:)?/.*/github.com/biogo/biogo/errors/errors_test.go#L=52 |
| 41 | ` |
| 42 | |
| 43 | // Tests |
| 44 | func (s *S) TestCaller(c *check.C) { |
| 45 | c.Skip("This fails after Go1.15.") |
| 46 | err := Make("message", 0, 10, "item") |
| 47 | c.Check(err.Error(), check.Equals, "message") |
| 48 | fn, ln := err.FileLine() |
| 49 | c.Check(fn, check.Matches, "(?:[A-Z]:)?/.*/biogo/errors/errors_test.go") |
| 50 | c.Check(ln, check.Equals, 45) |
| 51 | c.Check(err.Package(), check.Equals, "github.com/biogo/biogo/errors.(*S)") |
| 52 | c.Check(err.Function(), check.Equals, "TestCaller") |
| 53 | err = f(5).(Error) |
| 54 | c.Check(err.Tracef(7), check.Matches, traceRE) |
| 55 | } |
| 56 | |
| 57 | func (s *S) TestMakeFail(c *check.C) { |
| 58 | c.Check(func() { Make("message", 0, 0) }, check.Panics, "errors: zero trace depth") |
| 59 | } |