github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/tests/machine_test.go (about) 1 package tests 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 10 gno "github.com/gnolang/gno/gnovm/pkg/gnolang" 11 ) 12 13 func TestMachineTestMemPackage(t *testing.T) { 14 matchFunc := func(pat, str string) (bool, error) { return true, nil } 15 16 tests := []struct { 17 name string 18 path string 19 shouldSucceed bool 20 }{ 21 { 22 name: "TestSuccess", 23 path: "testdata/TestMemPackage/success", 24 shouldSucceed: true, 25 }, 26 { 27 name: "TestFail", 28 path: "testdata/TestMemPackage/fail", 29 shouldSucceed: false, 30 }, 31 } 32 for _, tt := range tests { 33 t.Run(tt.name, func(t *testing.T) { 34 // NOTE: Because the purpose of this test is to ensure testing.T.Failed() 35 // returns true if a gno test is failing, and because we don't want this 36 // to affect the current testing.T, we are creating an other one thanks 37 // to testing.RunTests() function. 38 testing.RunTests(matchFunc, []testing.InternalTest{ 39 { 40 Name: tt.name, 41 F: func(t2 *testing.T) { //nolint:thelper 42 rootDir := filepath.Join("..", "..") 43 store := TestStore(rootDir, "test", os.Stdin, os.Stdout, os.Stderr, ImportModeStdlibsOnly) 44 store.SetLogStoreOps(true) 45 m := gno.NewMachineWithOptions(gno.MachineOptions{ 46 PkgPath: "test", 47 Output: os.Stdout, 48 Store: store, 49 Context: nil, 50 }) 51 memPkg := gno.ReadMemPackage(tt.path, "test") 52 53 m.TestMemPackage(t2, memPkg) 54 55 if tt.shouldSucceed { 56 assert.False(t, t2.Failed(), "test %q should have succeed", tt.name) 57 } else { 58 assert.True(t, t2.Failed(), "test %q should have failed", tt.name) 59 } 60 }, 61 }, 62 }) 63 }) 64 } 65 }