Skip to content

Commit

Permalink
metamorphic: use require.Equal in TestParserRandom
Browse files Browse the repository at this point in the history
Previously the TestParserRandom unit test used pretty.Diff, but the output for
versions with cyclic references has changed. This commit changes the test to
use require.Equal. This requires updating some generated operations to use nil
to represent empty slices rather than []T{}. This matches the ops the parser
creates, which alway use nil for empty slices.
  • Loading branch information
jbowens committed Oct 7, 2023
1 parent 470a93d commit d0ac26c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 7 additions & 1 deletion metamorphic/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ func (g *generator) randValue(min, max int) []byte {
if max > min {
n += g.rng.Intn(max - min)
}
if n == 0 {
return nil
}
buf := make([]byte, n)
g.fillRand(buf)
return buf
Expand Down Expand Up @@ -522,10 +525,13 @@ func (g *generator) dbCheckpoint() {
// 1/4 of the time we restrict to 1 span;
// 1/8 of the time we restrict to 2 spans; etc.
numSpans := 0
var spans []pebble.CheckpointSpan
for g.rng.Intn(2) == 0 {
numSpans++
}
spans := make([]pebble.CheckpointSpan, numSpans)
if numSpans > 0 {
spans = make([]pebble.CheckpointSpan, numSpans)
}
for i := range spans {
start := g.randKeyToRead(0.01)
end := g.randKeyToRead(0.01)
Expand Down
7 changes: 1 addition & 6 deletions metamorphic/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ package metamorphic

import (
"fmt"
"strings"
"testing"

"github.com/cockroachdb/datadriven"
"github.com/cockroachdb/pebble/internal/randvar"
"github.com/kr/pretty"
"github.com/stretchr/testify/require"
)

Expand All @@ -38,10 +36,7 @@ func TestParserRandom(t *testing.T) {
if err != nil {
t.Fatalf("%s\n%s", err, src)
}

if diff := pretty.Diff(ops, parsedOps); diff != nil {
t.Fatalf("%s\n%s", strings.Join(diff, "\n"), src)
}
require.Equal(t, ops, parsedOps)
}

func TestParserNilBounds(t *testing.T) {
Expand Down

0 comments on commit d0ac26c

Please sign in to comment.