Skip to content

Commit d94de57

Browse files
authored
Merge pull request #937 from devlights/add-testing-be-library-examples
2 parents c0ce18a + 5e6908c commit d94de57

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# https://taskfile.dev
2+
3+
version: '3'
4+
5+
tasks:
6+
default:
7+
cmds:
8+
- go test -v
9+
ignore_error: true
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"testing"
7+
8+
"github.com/nalgeon/be"
9+
)
10+
11+
func sum(x ...int) int64 {
12+
var (
13+
total int64
14+
)
15+
for _, v := range x {
16+
total += int64(v)
17+
}
18+
19+
return total
20+
}
21+
22+
func errSometime(v int) error {
23+
switch {
24+
case v > 100:
25+
return fmt.Errorf("invalid value: %d", v)
26+
case v > 10:
27+
return errors.New("invalid value")
28+
default:
29+
return nil
30+
}
31+
}
32+
33+
func TestBeTrue(t *testing.T) {
34+
t.Run("ok", func(t *testing.T) {
35+
be.True(t, sum(1, 2, 3) == 6)
36+
})
37+
t.Run("ng", func(t *testing.T) {
38+
be.True(t, sum(1, 2, 3) != 6)
39+
})
40+
t.Run("ok2", func(t *testing.T) {
41+
be.True(t, errSometime(1) == nil)
42+
})
43+
t.Run("ng2", func(t *testing.T) {
44+
be.True(t, errSometime(111) == nil)
45+
})
46+
}

0 commit comments

Comments
 (0)