flyingmutant / rapid

Rapid is a modern Go property-based testing library
https://pkg.go.dev/pgregory.net/rapid
Mozilla Public License 2.0
579 stars 25 forks source link

group did not use any data from bitstream #54

Closed Rasphino closed 1 year ago

Rasphino commented 1 year ago

Hi @flyingmutant, thanks for your excellent PBT library!

I am trying to write some demo with rapid to show the power of PBT to my colleagues, but I encountered an error: [rapid] panic after 0 tests: group did not use any data from bitstream; this is likely a result of Custom generator not calling any of the built-in generators

Here is a minimal case:

package main

import (
    "pgregory.net/rapid"
    "testing"
)

type AddRequest struct {
    A, B int
}

func Add(r AddRequest) int {
    return r.A + r.B
}

func TestAdd(t *testing.T) {
    // property test
    comm := func(t *rapid.T) {
        gen := rapid.Custom(func(t *rapid.T) AddRequest {
            return AddRequest{
                A: rapid.Int().Draw(t, "A"),
                B: rapid.Int().Draw(t, "B"),
            }
        })
        //req := rapid.Make[AddRequest]().Draw(t, "request")
        req := gen.Draw(t, "request")
        if Add(req) != req.A+req.B {
            t.Errorf("wrong!")
        }
    }
    rapid.Check(t, comm)
}

Both rapid.Custom and rapid.Make will return this error.

My environment: go 1.19.6 rapid v1.0 arm64 macOS

flyingmutant commented 1 year ago

Thanks for the kind words!

The code you've posted should work, and it does work in the playground: Custom version and Make version. Maybe you are running a slightly different code?

Rasphino commented 1 year ago

hmm, yes it works on my x86-64 linux environment, but doesn't work in arm64 darwin... Let me try to find another example. Thanks!

flyingmutant commented 1 year ago

That is really strange considering that rapid has no platform-dependent code at all. Is there a chance that rapid tries to re-run one of the previously saved failfiles in testdata/rapid and that produces the error?

Rasphino commented 1 year ago

Yes, it is the previous failfiles that make this error 👍 Thanks for your help!