summaryrefslogtreecommitdiff
path: root/src/cmd/link/link_test.go
blob: b5ae15fc7108a008fd44096895ef3e7e053eef2c (plain)
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
// Copyright 2014 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"bytes"
	"cmd/internal/goobj"
	"io/ioutil"
	"testing"
)

func TestLinkHello(t *testing.T) {
	p := &Prog{
		GOOS:     "darwin",
		GOARCH:   "amd64",
		Error:    func(s string) { t.Error(s) },
		StartSym: "_rt0_go",
	}
	var buf bytes.Buffer
	p.link(&buf, "testdata/hello.6")
	if p.NumError > 0 {
		return
	}
	if p.Syms[goobj.SymID{"_rt0_go", 0}] == nil || p.Syms[goobj.SymID{"hello", 1}] == nil {
		t.Errorf("Syms = %v, want at least [_rt0_go hello<1>]", p.Syms)
	}

	// uncomment to leave file behind for execution:
	if false {
		ioutil.WriteFile("a.out", buf.Bytes(), 0777)
	}
	checkGolden(t, buf.Bytes(), "testdata/link.hello.darwin.amd64")
}