compiler: move it up from vm
It really deserves it, I think. Especially given that it doesn't have any direct usage of `vm` package now.
This commit is contained in:
parent
31add423a8
commit
852e6a335b
12 changed files with 7 additions and 12 deletions
53
pkg/compiler/compiler_test.go
Normal file
53
pkg/compiler/compiler_test.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package compiler_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/compiler"
|
||||
)
|
||||
|
||||
const examplePath = "../../examples"
|
||||
|
||||
func TestExamplesFolder(t *testing.T) {
|
||||
infos, err := ioutil.ReadDir(examplePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, info := range infos {
|
||||
infos, err := ioutil.ReadDir(path.Join(examplePath, info.Name()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(infos) == 0 {
|
||||
t.Fatal("detected smart contract folder with no contract in it")
|
||||
}
|
||||
|
||||
filename := filterFilename(infos)
|
||||
targetPath := path.Join(examplePath, info.Name(), filename)
|
||||
if err := compileFile(targetPath); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func filterFilename(infos []os.FileInfo) string {
|
||||
for _, info := range infos {
|
||||
if !info.IsDir() {
|
||||
return info.Name()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func compileFile(src string) error {
|
||||
file, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = compiler.Compile(file)
|
||||
return err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue