github.com/yanyiwu/go@v0.0.0-20150106053140-03d6637dbb7f/test/linkx_run.go (about)

     1  // +build !nacl
     2  // run
     3  
     4  // Copyright 2014 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  // Run the linkx test.
     9  
    10  package main
    11  
    12  import (
    13  	"fmt"
    14  	"os"
    15  	"os/exec"
    16  )
    17  
    18  func main() {
    19  	// Successful run
    20  	cmd := exec.Command("go", "run", "-ldflags=-X main.tbd hello -X main.overwrite trumped -X main.nosuchsymbol neverseen", "linkx.go")
    21  	out, err := cmd.CombinedOutput()
    22  	if err != nil {
    23  		fmt.Println(string(out))
    24  		fmt.Println(err)
    25  		os.Exit(1)
    26  	}
    27  
    28  	want := "hello\ntrumped\n"
    29  	got := string(out)
    30  	if got != want {
    31  		fmt.Printf("got %q want %q\n", got, want)
    32  		os.Exit(1)
    33  	}
    34  
    35  	// Issue 8810
    36  	cmd = exec.Command("go", "run", "-ldflags=-X main.tbd", "linkx.go")
    37  	_, err = cmd.CombinedOutput()
    38  	if err == nil {
    39  		fmt.Println("-X linker flag should not accept keys without values")
    40  		os.Exit(1)
    41  	}
    42  }