File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ // +build gofuzz
2
+
3
+ package pb_fuzz_workshop
4
+
5
+ import (
6
+ "encoding/json"
7
+ "reflect"
8
+ )
9
+
10
+ func Fuzz (b []byte ) int {
11
+ var s []int
12
+ if err := json .Unmarshal (b , & s ); err != nil {
13
+ return 0
14
+ }
15
+
16
+ if reflect .DeepEqual (Reverse (s ), s ) {
17
+ return 0
18
+ }
19
+
20
+ if ! reflect .DeepEqual (Reverse (Reverse (s )), s ) {
21
+ panic ("not equal" )
22
+ }
23
+
24
+ return 1
25
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package pb_fuzz_workshop
2
2
3
3
import (
4
4
"encoding/json"
5
+ "reflect"
5
6
"testing"
6
7
7
8
"github.com/stretchr/testify/require"
@@ -12,6 +13,7 @@ func FuzzReverse(f *testing.F) {
12
13
nil ,
13
14
{},
14
15
{1 },
16
+ {1 , 1 },
15
17
{1 , 2 },
16
18
{1 , 2 , 3 },
17
19
} {
@@ -28,6 +30,10 @@ func FuzzReverse(f *testing.F) {
28
30
t .Skip (err )
29
31
}
30
32
33
+ if reflect .DeepEqual (Reverse (s ), s ) {
34
+ t .Skip ()
35
+ }
36
+
31
37
require .Equal (t , s , Reverse (Reverse (s )))
32
38
require .Equal (t , s , NotReverse (s ))
33
39
})
You can’t perform that action at this time.
0 commit comments