github.com/llir/llvm@v0.3.6/ir/asm_test.go (about) 1 package ir_test 2 3 import ( 4 "io/ioutil" 5 "log" 6 "path/filepath" 7 "testing" 8 9 "github.com/google/go-cmp/cmp" 10 "github.com/llir/llvm/asm" 11 "github.com/llir/llvm/internal/osutil" 12 ) 13 14 func TestModule(t *testing.T) { 15 golden := []struct { 16 path string 17 }{ 18 // LLVM IR compatibility. 19 {path: "../testdata/llvm/test/Bitcode/compatibility.ll"}, 20 // Coreutils. 21 {path: "../testdata/coreutils/test/cat.ll"}, 22 } 23 hasTestdata := osutil.Exists("../testdata/llvm") 24 for _, g := range golden { 25 if filepath.HasPrefix(g.path, "../testdata") && !hasTestdata { 26 // Skip test cases from the llir/testdata submodule if not downloaded. 27 // Users may add this submodule using git clone --recursive. 28 continue 29 } 30 log.Printf("=== [ %s ] ===", g.path) 31 m, err := asm.ParseFile(g.path) 32 if err != nil { 33 t.Errorf("unable to parse %q into AST; %+v", g.path, err) 34 continue 35 } 36 path := g.path 37 if osutil.Exists(g.path + ".golden") { 38 path = g.path + ".golden" 39 } 40 buf, err := ioutil.ReadFile(path) 41 if err != nil { 42 t.Errorf("unable to read %q; %+v", path, err) 43 continue 44 } 45 want := string(buf) 46 got := m.String() 47 if diff := cmp.Diff(want, got); diff != "" { 48 t.Errorf("module %q mismatch (-want +got):\n%s", path, diff) 49 continue 50 } 51 } 52 }