diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-03-31 17:45:50 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-03-31 17:45:50 +0800 |
commit | c2bbff6116891396b44092d27bd68a0fa6f22a6e (patch) | |
tree | 3dd26182549efa5df311300a93d24dc3d65fed82 /accounts/abi/bind | |
parent | 787d688c2ff4e272fb7d73fd8f3e611685fe957e (diff) | |
download | dexon-c2bbff6116891396b44092d27bd68a0fa6f22a6e.tar dexon-c2bbff6116891396b44092d27bd68a0fa6f22a6e.tar.gz dexon-c2bbff6116891396b44092d27bd68a0fa6f22a6e.tar.bz2 dexon-c2bbff6116891396b44092d27bd68a0fa6f22a6e.tar.lz dexon-c2bbff6116891396b44092d27bd68a0fa6f22a6e.tar.xz dexon-c2bbff6116891396b44092d27bd68a0fa6f22a6e.tar.zst dexon-c2bbff6116891396b44092d27bd68a0fa6f22a6e.zip |
accounts/abi/bind: merge all tests into a single suite
Diffstat (limited to 'accounts/abi/bind')
-rw-r--r-- | accounts/abi/bind/bind_test.go | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/accounts/abi/bind/bind_test.go b/accounts/abi/bind/bind_test.go index abe60b22c..37b8ef5a7 100644 --- a/accounts/abi/bind/bind_test.go +++ b/accounts/abi/bind/bind_test.go @@ -247,41 +247,41 @@ func TestBindings(t *testing.T) { if !strings.Contains(string(linkTestDeps), "go-ethereum") { t.Skip("symlinked environment doesn't support bind (https://github.com/golang/go/issues/14845)") } - // All is well, run the tests - for i, tt := range bindTests { - // Create a temporary workspace for this test - ws, err := ioutil.TempDir("", "") - if err != nil { - t.Fatalf("test %d: failed to create temporary workspace: %v", i, err) - } - defer os.RemoveAll(ws) + // Create a temporary workspace for the test suite + ws, err := ioutil.TempDir("", "") + if err != nil { + t.Fatalf("failed to create temporary workspace: %v", err) + } + defer os.RemoveAll(ws) - // Generate the binding and create a Go package in the workspace + pkg := filepath.Join(ws, "bindtest") + if err = os.MkdirAll(pkg, 0700); err != nil { + t.Fatalf("failed to create package: %v", err) + } + // Generate the test suite for all the contracts + for i, tt := range bindTests { + // Generate the binding and create a Go source file in the workspace bind, err := Bind([]string{tt.name}, []string{tt.abi}, []string{tt.bytecode}, "bindtest") if err != nil { t.Fatalf("test %d: failed to generate binding: %v", i, err) } - pkg := filepath.Join(ws, "bindtest") - if err = os.MkdirAll(pkg, 0700); err != nil { - t.Fatalf("test %d: failed to create package: %v", i, err) - } - if err = ioutil.WriteFile(filepath.Join(pkg, "main.go"), []byte(bind), 0600); err != nil { + if err = ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+".go"), []byte(bind), 0600); err != nil { t.Fatalf("test %d: failed to write binding: %v", i, err) } // Generate the test file with the injected test code - code := fmt.Sprintf("package bindtest\nimport \"testing\"\nfunc TestBinding%d(t *testing.T){\n%s\n}", i, tt.tester) + code := fmt.Sprintf("package bindtest\nimport \"testing\"\nfunc Test%s(t *testing.T){\n%s\n}", tt.name, tt.tester) blob, err := imports.Process("", []byte(code), nil) if err != nil { t.Fatalf("test %d: failed to generate tests: %v", i, err) } - if err := ioutil.WriteFile(filepath.Join(pkg, "main_test.go"), blob, 0600); err != nil { + if err := ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+"_test.go"), blob, 0600); err != nil { t.Fatalf("test %d: failed to write tests: %v", i, err) } - // Test the entire package and report any failures - cmd := exec.Command(gocmd, "test", "-v") - cmd.Dir = pkg - if out, err := cmd.CombinedOutput(); err != nil { - t.Fatalf("test %d: failed to run binding test: %v\n%s\n%s", i, err, out, bind) - } + } + // Test the entire package and report any failures + cmd := exec.Command(gocmd, "test", "-v") + cmd.Dir = pkg + if out, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("failed to run binding test: %v\n%s", err, out) } } |