-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcache_test.go
68 lines (59 loc) · 1.5 KB
/
cache_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package compilers
import (
"bytes"
"fmt"
"os"
"os/exec"
"path"
"testing"
"github.com/eris-ltd/eris-compilers/Godeps/_workspace/src/github.com/eris-ltd/common/go/common"
)
func init() {
ClearCaches()
}
func copyFile(src, dst string) error {
cmd := exec.Command("cp", src, dst)
return cmd.Run()
}
func testCache(t *testing.T) {
ClearCaches()
resp := Compile("tests/test-inc1.lll", "")
code := resp.Objects[0].Bytecode
if resp.Error != "" {
t.Fatal(fmt.Errorf(resp.Error))
}
fmt.Printf("%x\n", code)
copyFile("tests/test-inc1.lll", path.Join(common.LllcScratchPath, "test-inc1.lll"))
copyFile("tests/test-inc2.lll", path.Join(common.LllcScratchPath, "test-inc2.lll"))
copyFile("tests/test-inc4.lll", path.Join(common.LllcScratchPath, "test-inc3.lll"))
cur, _ := os.Getwd()
os.Chdir(common.LllcScratchPath)
resp = Compile(path.Join(common.LllcScratchPath, "test-inc1.lll"), "")
code2 := resp.Objects[0].Bytecode
if resp.Error != "" {
t.Fatal(fmt.Errorf(resp.Error))
}
fmt.Printf("%x\n", code2)
if bytes.Compare(code, code2) == 0 {
t.Fatal("failed to update cached file")
}
os.Chdir(cur)
}
func TestCacheLocal(t *testing.T) {
SetLanguageNet("lll", false)
testCache(t)
}
func TestCacheRemote(t *testing.T) {
SetLanguageNet("lll", true)
testCache(t)
}
func TestSimple(t *testing.T) {
ClearCaches()
SetLanguageNet("lll", false)
resp := Compile("tests/test-inc1.lll", "")
code := resp.Objects[0].Bytecode
if resp.Error != "" {
t.Fatal(fmt.Errorf(resp.Error))
}
fmt.Printf("%x\n", code)
}