From 2fbb269c0d88069bdb0bdde63038b32aa12911c8 Mon Sep 17 00:00:00 2001 From: Anthony De Meulemeester Date: Tue, 21 Aug 2018 14:51:16 +0200 Subject: [PATCH] added compiler to test all example files. (CityOfZion/neo-storm#9) Imported from CityOfZion/neo-storm (e756a91b292f525f2cd7e6d6c05b46df582c8ece). --- pkg/vm/compiler/compiler_test.go | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 pkg/vm/compiler/compiler_test.go diff --git a/pkg/vm/compiler/compiler_test.go b/pkg/vm/compiler/compiler_test.go new file mode 100644 index 000000000..ac17fcc25 --- /dev/null +++ b/pkg/vm/compiler/compiler_test.go @@ -0,0 +1,50 @@ +package compiler_test + +import ( + "io/ioutil" + "os" + "path" + "testing" + + "github.com/CityOfZion/neo-go/pkg/vm/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) > 1 { + t.Fatal("detected smart contract folder with more then 1 contract file") + } + if len(infos) == 0 { + t.Fatal("detected smart contract folder with no contract in it") + } + filename := infos[0].Name() + targetPath := path.Join(examplePath, info.Name(), filename) + if err := compileFile(targetPath); err != nil { + t.Fatal(err) + } + } +} + +func compileFile(src string) error { + o := compiler.Options{ + Outfile: "tmp/contract.avm", + } + + file, err := os.Open(src) + if err != nil { + return err + } + _, err = compiler.Compile(file, &o) + return err +}