New upstream snapshot.
Debian Janitor
1 year, 3 months ago
0 | # Compiled Object files, Static and Dynamic libs (Shared Objects) | |
1 | *.o | |
2 | *.a | |
3 | *.so | |
4 | ||
5 | # Folders | |
6 | _obj | |
7 | _test | |
8 | ||
9 | # Architecture specific extensions/prefixes | |
10 | *.[568vq] | |
11 | [568vq].out | |
12 | ||
13 | *.cgo1.go | |
14 | *.cgo2.c | |
15 | _cgo_defun.c | |
16 | _cgo_gotypes.go | |
17 | _cgo_export.* | |
18 | ||
19 | _testmain.go | |
20 | ||
21 | *.exe | |
22 | *.test | |
23 | *.prof |
1 | 1 | Professional lightweight testing mini-framework for Go. |
2 | 2 | |
3 | 3 | * Easy to write and read |
4 | * [Beautifully simple API](https://godoc.org/github.com/matryer/is) with everything you need: `is.Equal`, `is.True`, `is.NoErr`, and `is.Fail` | |
4 | * [Beautifully simple API](https://pkg.go.dev/github.com/matryer/is) with everything you need: `is.Equal`, `is.True`, `is.NoErr`, and `is.Fail` | |
5 | 5 | * Use comments to add descriptions (which show up when tests fail) |
6 | 6 | |
7 | 7 | Failures are very easy to read: |
17 | 17 | func Test(t *testing.T) { |
18 | 18 | |
19 | 19 | is := is.New(t) |
20 | ||
20 | ||
21 | 21 | signedin, err := isSignedIn(ctx) |
22 | 22 | is.NoErr(err) // isSignedIn error |
23 | 23 | is.Equal(signedin, true) // must be signed in |
24 | ||
24 | ||
25 | 25 | body := readBody(r) |
26 | 26 | is.True(strings.Contains(body, "Hi there")) |
27 | ||
27 | ||
28 | 28 | } |
29 | 29 | ``` |
30 | 30 | |
31 | 31 | ## Color |
32 | 32 | |
33 | To turn off the colors, run `go test` with the `-nocolor` flag, or with the env var `IS_NO_COLOR=true`. | |
33 | To turn off the colors, run `go test` with the `-nocolor` flag, | |
34 | or with the env var [`NO_COLOR` (with any value)](https://no-color.org). | |
34 | 35 | |
35 | 36 | ``` |
36 | 37 | go test -nocolor |
37 | 38 | ``` |
38 | 39 | |
39 | 40 | ``` |
40 | IS_NO_COLOR=true go test | |
41 | NO_COLOR=1 go test | |
41 | 42 | ``` |
0 | golang-github-matryer-is (1.4.0-2) UNRELEASED; urgency=medium | |
0 | golang-github-matryer-is (1.4.0+git20220516.1.02e4121-1) UNRELEASED; urgency=medium | |
1 | 1 | |
2 | 2 | * Set upstream metadata fields: Bug-Database, Bug-Submit, Repository, |
3 | 3 | Repository-Browse. |
4 | 4 | * Update standards version to 4.6.0, no changes needed. |
5 | * New upstream snapshot. | |
5 | 6 | |
6 | -- Debian Janitor <janitor@jelmer.uk> Fri, 01 Oct 2021 05:27:48 -0000 | |
7 | -- Debian Janitor <janitor@jelmer.uk> Thu, 19 Jan 2023 16:25:35 -0000 | |
7 | 8 | |
8 | 9 | golang-github-matryer-is (1.4.0-1) unstable; urgency=medium |
9 | 10 |
32 | 32 | // the purpose of decorating log messages. |
33 | 33 | const maxStackLen = 50 |
34 | 34 | |
35 | var reIsSourceFile = regexp.MustCompile("is(-1.7)?\\.go$") | |
35 | var reIsSourceFile = regexp.MustCompile(`is(-1.7)?\.go$`) | |
36 | 36 | |
37 | 37 | func (is *I) callerinfo() (path string, line int, ok bool) { |
38 | 38 | var pc [maxStackLen]uintptr |
21 | 21 | // the helper methods: |
22 | 22 | // |
23 | 23 | // func Test(t *testing.T) { |
24 | // | |
25 | 24 | // // always start tests with this |
26 | 25 | // is := is.New(t) |
27 | 26 | // |
31 | 30 | // |
32 | 31 | // body := readBody(r) |
33 | 32 | // is.True(strings.Contains(body, "Hi there")) |
34 | // | |
35 | 33 | // } |
36 | 34 | package is |
37 | 35 | |
44 | 42 | "os" |
45 | 43 | "path/filepath" |
46 | 44 | "reflect" |
45 | "strconv" | |
47 | 46 | "strings" |
48 | "testing" | |
49 | 47 | ) |
50 | 48 | |
51 | 49 | // T reports when failures occur. |
74 | 72 | var noColorFlag bool |
75 | 73 | |
76 | 74 | func init() { |
77 | envNoColor := os.Getenv("IS_NO_COLOR") == "true" | |
75 | var envNoColor bool | |
76 | ||
77 | // prefer https://no-color.org (with any value) | |
78 | if _, ok := os.LookupEnv("NO_COLOR"); ok { | |
79 | envNoColor = true | |
80 | } | |
81 | ||
82 | if v, ok := os.LookupEnv("IS_NO_COLOR"); ok { | |
83 | if b, err := strconv.ParseBool(v); err == nil { | |
84 | envNoColor = b | |
85 | } | |
86 | } | |
87 | ||
78 | 88 | flag.BoolVar(&noColorFlag, "nocolor", envNoColor, "turns off colors") |
79 | 89 | } |
80 | 90 | |
170 | 180 | // // TODO: test |
171 | 181 | // }) |
172 | 182 | // } |
173 | func (is *I) New(t *testing.T) *I { | |
183 | func (is *I) New(t T) *I { | |
174 | 184 | return New(t) |
175 | 185 | } |
176 | 186 | |
185 | 195 | // // TODO: test |
186 | 196 | // }) |
187 | 197 | // } |
188 | func (is *I) NewRelaxed(t *testing.T) *I { | |
198 | func (is *I) NewRelaxed(t T) *I { | |
189 | 199 | return NewRelaxed(t) |
190 | 200 | } |
191 | 201 | |
257 | 267 | s := bufio.NewScanner(f) |
258 | 268 | i := 1 |
259 | 269 | for s.Scan() { |
260 | if i == line { | |
261 | text := s.Text() | |
262 | commentI := strings.Index(text, "// ") | |
263 | if commentI == -1 { | |
264 | return "", false // no comment | |
265 | } | |
266 | text = text[commentI+2:] | |
267 | text = strings.TrimSpace(text) | |
268 | return text, true | |
269 | } | |
270 | i++ | |
270 | if i != line { | |
271 | i++ | |
272 | continue | |
273 | } | |
274 | ||
275 | text := s.Text() | |
276 | commentI := strings.Index(text, "// ") | |
277 | if commentI == -1 { | |
278 | return "", false // no comment | |
279 | } | |
280 | text = text[commentI+2:] | |
281 | text = strings.TrimSpace(text) | |
282 | return text, true | |
271 | 283 | } |
272 | 284 | return "", false |
273 | 285 | } |
283 | 295 | s := bufio.NewScanner(f) |
284 | 296 | i := 1 |
285 | 297 | for s.Scan() { |
286 | if i == line { | |
287 | text := s.Text() | |
288 | braceI := strings.Index(text, "(") | |
289 | if braceI == -1 { | |
290 | return "", false | |
298 | if i != line { | |
299 | i++ | |
300 | continue | |
301 | } | |
302 | text := s.Text() | |
303 | braceI := strings.Index(text, "(") | |
304 | if braceI == -1 { | |
305 | return "", false | |
306 | } | |
307 | text = text[braceI+1:] | |
308 | cs := bufio.NewScanner(strings.NewReader(text)) | |
309 | cs.Split(bufio.ScanBytes) | |
310 | j := 0 | |
311 | c := 1 | |
312 | for cs.Scan() { | |
313 | switch cs.Text() { | |
314 | case ")": | |
315 | c-- | |
316 | case "(": | |
317 | c++ | |
291 | 318 | } |
292 | text = text[braceI+1:] | |
293 | cs := bufio.NewScanner(strings.NewReader(text)) | |
294 | cs.Split(bufio.ScanBytes) | |
295 | j := 0 | |
296 | c := 1 | |
297 | for cs.Scan() { | |
298 | switch cs.Text() { | |
299 | case ")": | |
300 | c-- | |
301 | case "(": | |
302 | c++ | |
303 | } | |
304 | if c == 0 { | |
305 | break | |
306 | } | |
307 | j++ | |
319 | if c == 0 { | |
320 | break | |
308 | 321 | } |
309 | text = text[:j] | |
310 | return text, true | |
311 | } | |
312 | i++ | |
322 | j++ | |
323 | } | |
324 | text = text[:j] | |
325 | return text, true | |
313 | 326 | } |
314 | 327 | return "", false |
315 | 328 | } |
27 | 27 | { |
28 | 28 | N: "Equal(1, 1)", |
29 | 29 | F: func(is *I) { |
30 | is.Equal(1, 1) // 1 doesn't equal 2 | |
30 | is.Equal(1, 1) // 1 doesn't equal 1 | |
31 | 31 | }, |
32 | 32 | Fail: ``, |
33 | 33 | }, |
56 | 56 | { |
57 | 57 | N: "Equal(false, false)", |
58 | 58 | F: func(is *I) { |
59 | is.Equal(false, false) // nil doesn't equal 2 | |
59 | is.Equal(false, false) // false doesn't equal false | |
60 | 60 | }, |
61 | 61 | Fail: ``, |
62 | 62 | }, |
77 | 77 | Fail: `map[value:1] != map[value:2] // maps`, |
78 | 78 | }, |
79 | 79 | { |
80 | N: "Equal(true, map2)", | |
81 | F: func(is *I) { | |
82 | m1 := map[string]interface{}{"value": 1} | |
83 | m2 := map[string]interface{}{"value": 2} | |
84 | is.Equal(m1, m2) // maps | |
85 | }, | |
86 | Fail: `map[value:1] != map[value:2] // maps`, | |
80 | N: "Equal(true, map)", | |
81 | F: func(is *I) { | |
82 | m := map[string]interface{}{"value": 2} | |
83 | is.Equal(true, m) // maps | |
84 | }, | |
85 | Fail: `bool(true) != map[string]interface {}(map[value:2]) // maps`, | |
87 | 86 | }, |
88 | 87 | { |
89 | 88 | N: "Equal(slice1, slice2)", |
110 | 109 | s2 := []string{"one", "two", "three", "four"} |
111 | 110 | is.Equal(s1, s2) // nil slice |
112 | 111 | }, |
113 | Fail: ` // nil slice`, | |
112 | Fail: `<nil> != []string([one two three four]) // nil slice`, | |
114 | 113 | }, |
115 | 114 | { |
116 | 115 | N: "Equal(nil, nil)", |
128 | 127 | m2 := map[string]string{} |
129 | 128 | is.Equal(m1, m2) // nil map |
130 | 129 | }, |
131 | Fail: ` // nil map`, | |
130 | Fail: `<nil> != map[string]string(map[]) // nil map`, | |
132 | 131 | }, |
133 | 132 | { |
134 | 133 | N: "Equal(nil, nil)", |
146 | 145 | s2 := "0.2 VAT" |
147 | 146 | is.Equal(s1, s2) // strings |
148 | 147 | }, |
149 | Fail: ` // strings`, | |
148 | Fail: `20% VAT != 0.2 VAT // strings`, | |
150 | 149 | }, |
151 | 150 | |
152 | 151 | // Fail |
176 | 175 | Fail: "err: nope // method shouldn't return error", |
177 | 176 | }, |
178 | 177 | |
179 | // OK | |
178 | // True | |
180 | 179 | { |
181 | 180 | N: "True(1 == 2)", |
182 | 181 | F: func(is *I) { |