Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make tests run in parallel #1312

Merged
merged 11 commits into from
Nov 9, 2023
5 changes: 5 additions & 0 deletions gno.land/cmd/gnoland/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
)

func TestStartInitialize(t *testing.T) {
t.Parallel()

cases := []struct {
args []string
}{
Expand All @@ -23,8 +25,11 @@ func TestStartInitialize(t *testing.T) {
os.Chdir(filepath.Join("..", "..")) // go to repo's root dir

for _, tc := range cases {
tc := tc
name := strings.Join(tc.args, " ")
t.Run(name, func(t *testing.T) {
t.Parallel()

mockOut := bytes.NewBufferString("")
mockErr := bytes.NewBufferString("")
io := commands.NewTestIO()
Expand Down
2 changes: 2 additions & 0 deletions gno.land/pkg/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ import (
)

func TestTestdata(t *testing.T) {
t.Parallel()

testscript.Run(t, SetupGnolandTestScript(t, "testdata"))
}
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/alloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestAllocSizes(t *testing.T) {
t.Parallel()

// go elemental
println("_allocPointer", unsafe.Sizeof(&StructValue{}))
println("_allocSlice", unsafe.Sizeof([]byte("12345678901234567890123456789012345678901234567890")))
Expand Down
32 changes: 32 additions & 0 deletions gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

// run empty main().
func TestRunEmptyMain(t *testing.T) {
t.Parallel()

m := NewMachine("test", nil)
main := FuncD("main", nil, nil, nil)
m.RunDeclaration(main)
Expand All @@ -21,6 +23,8 @@ func TestRunEmptyMain(t *testing.T) {

// run main() with a for loop.
func TestRunLoopyMain(t *testing.T) {
t.Parallel()

m := NewMachine("test", nil)
c := `package test
func main() {
Expand All @@ -36,6 +40,8 @@ func main() {
}

func TestEval(t *testing.T) {
t.Parallel()

m := NewMachine("test", nil)
c := `package test
func next(i int) int {
Expand Down Expand Up @@ -64,6 +70,8 @@ func assertOutput(t *testing.T, input string, output string) {
}

func TestRunMakeStruct(t *testing.T) {
t.Parallel()

assertOutput(t, `package test
type Outfit struct {
Scarf string
Expand All @@ -90,6 +98,8 @@ func main() {
}

func TestRunReturnStruct(t *testing.T) {
t.Parallel()

assertOutput(t, `package test
type MyStruct struct {
FieldA string
Expand Down Expand Up @@ -160,6 +170,8 @@ type Struct1 struct {
}

func TestModifyTypeAsserted(t *testing.T) {
t.Parallel()

x := Struct1{1, 1}
var v interface{} = x
x2 := v.(Struct1)
Expand All @@ -176,6 +188,8 @@ type Interface1 interface {
}

func TestTypeConversion(t *testing.T) {
t.Parallel()

x := 1
var v interface{} = x
if _, ok := v.(Interface1); ok {
Expand All @@ -193,6 +207,8 @@ func TestTypeConversion(t *testing.T) {
}

func TestSomething(t *testing.T) {
t.Parallel()

type Foo struct {
X interface{}
}
Expand All @@ -210,6 +226,8 @@ func TestSomething(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestDeferOrder(t *testing.T) {
t.Parallel()

a := func() func(int, int) int {
fmt.Println("a constructed")
return func(x int, y int) int {
Expand Down Expand Up @@ -238,6 +256,8 @@ func TestDeferOrder(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestCallOrder(t *testing.T) {
t.Parallel()

a := func() func(int, int) int {
fmt.Println("a constructed")
return func(x int, y int) int {
Expand All @@ -264,6 +284,8 @@ func TestCallOrder(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestBinaryShortCircuit(t *testing.T) {
t.Parallel()

tr := func() bool {
fmt.Println("t called")
return true
Expand All @@ -281,6 +303,8 @@ func TestBinaryShortCircuit(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestSwitchDefine(t *testing.T) {
t.Parallel()

var x interface{} = 1
switch y := x.(type) {
case int:
Expand All @@ -292,6 +316,8 @@ func TestSwitchDefine(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestBinaryCircuit(t *testing.T) {
t.Parallel()

tr := func() bool {
fmt.Println("tr() called")
return true
Expand All @@ -316,6 +342,8 @@ func TestBinaryCircuit(t *testing.T) {
}

func TestMultiAssignment(t *testing.T) {
t.Parallel()

buf := make([]int, 4)
ref := func(i int) *int {
fmt.Printf("ref(%v) called\n", i)
Expand All @@ -342,6 +370,8 @@ func TestMultiAssignment(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestCallLHS(t *testing.T) {
t.Parallel()

x := 1
xptr := func() *int {
return &x
Expand All @@ -352,6 +382,8 @@ func TestCallLHS(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestCallFieldLHS(t *testing.T) {
t.Parallel()

type str struct {
X int
}
Expand Down
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/go2gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

func TestParseForLoop(t *testing.T) {
t.Parallel()

gocode := `package main
func main(){
for i:=0; i<10; i++ {
Expand Down
4 changes: 4 additions & 0 deletions gnovm/pkg/gnolang/gonative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ D:
}

func TestGoNativeDefine3(t *testing.T) {
t.Parallel()

// Create package foo and define Foo.
out := new(bytes.Buffer)
pkg := NewPackageNode("foo", "test.foo", nil)
Expand Down Expand Up @@ -135,6 +137,8 @@ D:
}

func TestCrypto(t *testing.T) {
t.Parallel()

addr := crypto.Address{}
store := gonativeTestStore()
tv := Go2GnoValue(nilAllocator, store, reflect.ValueOf(addr))
Expand Down
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

// Tries to reproduce the bug #1036 on all registered types
func TestAminoJSONRegisteredTypes(t *testing.T) {
t.Parallel()

for _, typ := range Package.Types {
// Instantiate registered type
x := reflect.New(typ.Type).Interface()
Expand Down
4 changes: 4 additions & 0 deletions gnovm/pkg/gnolang/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
)

func TestPrecompile(t *testing.T) {
t.Parallel()

cases := []struct {
name string
source string
Expand Down Expand Up @@ -56,6 +58,8 @@ func TestPrecompile(t *testing.T) {
for _, c := range cases {
c := c // scopelint
t.Run(c.name, func(t *testing.T) {
t.Parallel()

// parse gno
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "foo.go", c.source, parser.ParseComments)
Expand Down
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/values_conversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestConvertUntypedBigdecToFloat(t *testing.T) {
t.Parallel()

dst := &TypedValue{}

dec, err := apd.New(-math.MaxInt64, -4).SetFloat64(math.SmallestNonzeroFloat64 / 2)
Expand Down
4 changes: 4 additions & 0 deletions gnovm/pkg/repl/repl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ func TestRepl(t *testing.T) {
}

func TestReplOpts(t *testing.T) {
t.Parallel()

require := require.New(t)

r := NewRepl(WithStd(nil, nil, nil), WithStore(nil))
Expand All @@ -212,6 +214,8 @@ func TestReplOpts(t *testing.T) {
}

func TestReplReset(t *testing.T) {
t.Parallel()

require := require.New(t)

r := NewRepl()
Expand Down
2 changes: 2 additions & 0 deletions gnovm/tests/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func _printValue(x interface{}) {
}

func TestSelectors(t *testing.T) {
t.Parallel()

x0 := struct{ F0 int }{1}
_printValue(x0.F0) // *ST.F0
// F:0
Expand Down
2 changes: 2 additions & 0 deletions misc/docker-integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
)

func TestDockerIntegration(t *testing.T) {
t.Parallel()

tmpdir, err := os.MkdirTemp(os.TempDir(), "*-gnoland-integration")
require.NoError(t, err)

Expand Down
14 changes: 14 additions & 0 deletions tm2/pkg/amino/amino_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func TestMarshal(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()

type SimpleStruct struct {
Expand All @@ -35,6 +37,8 @@ func TestMarshal(t *testing.T) {
}

func TestUnmarshalReader(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()

type SimpleStruct struct {
Expand Down Expand Up @@ -65,6 +69,8 @@ type stringWrapper struct {
}

func TestUnmarshalReaderSize(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()

s1 := stringWrapper{"foo"}
Expand All @@ -82,6 +88,8 @@ func TestUnmarshalReaderSize(t *testing.T) {
}

func TestUnmarshalReaderSizeLimit(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()

s1 := stringWrapper{"foo"}
Expand All @@ -101,6 +109,8 @@ func TestUnmarshalReaderSizeLimit(t *testing.T) {
}

func TestUnmarshalReaderTooLong(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()

type SimpleStruct struct {
Expand All @@ -125,6 +135,8 @@ func TestUnmarshalReaderTooLong(t *testing.T) {
}

func TestUnmarshalBufferedWritesReads(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()
buf := bytes.NewBuffer(nil)

Expand Down Expand Up @@ -155,6 +167,8 @@ func TestUnmarshalBufferedWritesReads(t *testing.T) {
}

func TestBoolPointers(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()
type SimpleStruct struct {
BoolPtrTrue *bool
Expand Down
4 changes: 4 additions & 0 deletions tm2/pkg/amino/binary_encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import (
)

func TestEncodeFieldNumberAndTyp3_1(t *testing.T) {
t.Parallel()

buf := new(bytes.Buffer)
err := encodeFieldNumberAndTyp3(buf, 1, Typ3ByteLength)
assert.Nil(t, err)
assert.Equal(t, []byte{byte(0x01<<3 | Typ3ByteLength)}, buf.Bytes())
}

func TestEncodeFieldNumberAndTyp3_2(t *testing.T) {
t.Parallel()

buf := new(bytes.Buffer)
err := encodeFieldNumberAndTyp3(buf, 2, Typ3ByteLength)
assert.Nil(t, err)
Expand Down
Loading
Loading