github.com/llir/llvm@v0.3.6/ir/types/asm_test.go (about)

     1  package types_test
     2  
     3  import (
     4  	"io/ioutil"
     5  	"log"
     6  	"testing"
     7  
     8  	"github.com/google/go-cmp/cmp"
     9  	"github.com/llir/llvm/asm"
    10  	"github.com/llir/llvm/internal/osutil"
    11  )
    12  
    13  func TestModule(t *testing.T) {
    14  	golden := []struct {
    15  		path string
    16  	}{
    17  		// LLVM IR types.
    18  		{path: "testdata/types.ll"},
    19  	}
    20  	for _, g := range golden {
    21  		log.Printf("=== [ %s ] ===", g.path)
    22  		m, err := asm.ParseFile(g.path)
    23  		if err != nil {
    24  			t.Errorf("unable to parse %q into AST; %+v", g.path, err)
    25  			continue
    26  		}
    27  		path := g.path
    28  		if osutil.Exists(g.path + ".golden") {
    29  			path = g.path + ".golden"
    30  		}
    31  		buf, err := ioutil.ReadFile(path)
    32  		if err != nil {
    33  			t.Errorf("unable to read %q; %+v", path, err)
    34  			continue
    35  		}
    36  		want := string(buf)
    37  		got := m.String()
    38  		if diff := cmp.Diff(want, got); diff != "" {
    39  			t.Errorf("module %q mismatch (-want +got):\n%s", path, diff)
    40  			continue
    41  		}
    42  	}
    43  }