compiler: add test for compile and save

This commit is contained in:
Vsevolod Brekelov 2020-01-14 17:33:04 +03:00
parent d576aa2753
commit 7084925e4b
2 changed files with 58 additions and 18 deletions

View file

@ -7,21 +7,28 @@ import (
"testing"
"github.com/CityOfZion/neo-go/pkg/compiler"
"github.com/stretchr/testify/require"
)
const examplePath = "../../examples"
const exampleCompilePath = "testdata/compile"
const exampleSavePath = exampleCompilePath + "/save"
func TestExamplesFolder(t *testing.T) {
type compilerTestCase struct {
name string
function func()
}
func TestCompiler(t *testing.T) {
testCases := []compilerTestCase{
{
name: "TestCompile",
function: func() {
infos, err := ioutil.ReadDir(examplePath)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
for _, info := range infos {
infos, err := ioutil.ReadDir(path.Join(examplePath, info.Name()))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
if len(infos) == 0 {
t.Fatal("detected smart contract folder with no contract in it")
}
@ -32,6 +39,32 @@ func TestExamplesFolder(t *testing.T) {
t.Fatal(err)
}
}
},
},
{
name: "TestCompileAndSave",
function: func() {
infos, err := ioutil.ReadDir(exampleCompilePath)
require.NoError(t, err)
err = os.MkdirAll(exampleSavePath, os.ModePerm)
require.NoError(t, err)
outfile := exampleSavePath + "/test.avm"
if _, err := compiler.CompileAndSave(exampleCompilePath+"/"+infos[0].Name(), &compiler.Options{Outfile: outfile}); err != nil {
t.Fatal(err)
}
defer func() {
err := os.RemoveAll(exampleSavePath)
require.NoError(t, err)
}()
},
},
}
for _, tcase := range testCases {
t.Run(tcase.name, func(t *testing.T) {
tcase.function()
})
}
}
func filterFilename(infos []os.FileInfo) string {

7
pkg/compiler/testdata/compile/test.go vendored Normal file
View file

@ -0,0 +1,7 @@
package compile
import "github.com/CityOfZion/neo-go/pkg/interop/runtime"
func Main() {
runtime.Notify("Hello world!")
}