github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/link/internal/ld/issue33808_test.go (about)

     1  // Copyright 2019 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 ld
     6  
     7  import (
     8  	"github.com/gagliardetto/golang-go/not-internal/testenv"
     9  	"io/ioutil"
    10  	"os"
    11  	"runtime"
    12  	"strings"
    13  	"testing"
    14  )
    15  
    16  const prog = `
    17  package main
    18  
    19  import "log"
    20  
    21  func main() {
    22  	log.Fatalf("HERE")
    23  }
    24  `
    25  
    26  func TestIssue33808(t *testing.T) {
    27  	if runtime.GOOS != "darwin" {
    28  		return
    29  	}
    30  	testenv.MustHaveGoBuild(t)
    31  	testenv.MustHaveCGO(t)
    32  
    33  	dir, err := ioutil.TempDir("", "TestIssue33808")
    34  	if err != nil {
    35  		t.Fatalf("could not create directory: %v", err)
    36  	}
    37  	defer os.RemoveAll(dir)
    38  
    39  	f := gobuild(t, dir, prog, "-ldflags=-linkmode=external")
    40  	f.Close()
    41  
    42  	syms, err := f.Symbols()
    43  	if err != nil {
    44  		t.Fatalf("Error reading symbols: %v", err)
    45  	}
    46  
    47  	name := "log.Fatalf"
    48  	for _, sym := range syms {
    49  		if strings.Contains(sym.Name, name) {
    50  			return
    51  		}
    52  	}
    53  	t.Fatalf("Didn't find %v", name)
    54  }