Skip to content

Commit 450f87f

Browse files
committed
Add examples/testing/be_library/equal
1 parent bea3209 commit 450f87f

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# beとは?
2+
3+
[nalgeon/be](https://github.com/nalgeon/be)は、シンプルでとても使いやすいテスト用アサートライブラリです。
4+
5+
作者のブログ記事は以下です。
6+
7+
- Expressive tests without testify/assert
8+
- https://antonz.org/do-not-testify/
9+
10+
関数は3つしか存在しない。
11+
12+
- Equal
13+
- Err
14+
- True
15+
16+
それぞれがジェネリック対応となっているため、どのような型でもアサート出来るようになっている。
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/nalgeon/be"
7+
)
8+
9+
func sum(x ...int) int64 {
10+
var (
11+
total int64
12+
)
13+
for _, v := range x {
14+
total += int64(v)
15+
}
16+
17+
return total
18+
}
19+
20+
func TestBeEqual(t *testing.T) {
21+
t.Run("ok", func(t *testing.T) {
22+
be.Equal(t, sum(1, 2, 3), int64(6))
23+
})
24+
t.Run("ng", func(t *testing.T) {
25+
be.Equal(t, sum(1, 2, 3), int64(10))
26+
})
27+
t.Run("ok2", func(t *testing.T) {
28+
// wantsには複数指定できる。複数していした場合はどれかが合致すればOKとなる。
29+
be.Equal(t, sum(1, 2, 3), int64(10), int64(6), int64(99))
30+
})
31+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/ebitengine/purego v0.8.2 // indirect
3131
github.com/go-ole/go-ole v1.2.6 // indirect
3232
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
33+
github.com/nalgeon/be v0.2.0
3334
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
3435
github.com/tklauser/go-sysconf v0.3.12 // indirect
3536
github.com/tklauser/numcpus v0.6.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ
1717
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
1818
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
1919
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
20+
github.com/nalgeon/be v0.2.0 h1:i1Rsh0F+aNnHdbgph5Cy8Xm5uMVeWrUpm1olgzlPsMo=
21+
github.com/nalgeon/be v0.2.0/go.mod h1:PMwMuBLopwKJkSHnr2qHyLcZYUTqNejN7A8RAqNWO3E=
2022
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
2123
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
2224
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)