github.com/yanyiwu/go@v0.0.0-20150106053140-03d6637dbb7f/src/cmd/link/link_test.go (about)

     1  // Copyright 2014 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"bytes"
     9  	"cmd/internal/goobj"
    10  	"io/ioutil"
    11  	"testing"
    12  )
    13  
    14  func TestLinkHello(t *testing.T) {
    15  	p := &Prog{
    16  		GOOS:     "darwin",
    17  		GOARCH:   "amd64",
    18  		Error:    func(s string) { t.Error(s) },
    19  		StartSym: "_rt0_go",
    20  	}
    21  	var buf bytes.Buffer
    22  	p.link(&buf, "testdata/hello.6")
    23  	if p.NumError > 0 {
    24  		return
    25  	}
    26  	if p.Syms[goobj.SymID{"_rt0_go", 0}] == nil || p.Syms[goobj.SymID{"hello", 1}] == nil {
    27  		t.Errorf("Syms = %v, want at least [_rt0_go hello<1>]", p.Syms)
    28  	}
    29  
    30  	// uncomment to leave file behind for execution:
    31  	if false {
    32  		ioutil.WriteFile("a.out", buf.Bytes(), 0777)
    33  	}
    34  	checkGolden(t, buf.Bytes(), "testdata/link.hello.darwin.amd64")
    35  }