Black Lives Matter. Support the Equal Justice Initiative.

Source file test/sinit_run.go

Documentation: test

     1  // +build !nacl,!js,gc
     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 sinit test.
     9  
    10  package main
    11  
    12  import (
    13  	"bytes"
    14  	"fmt"
    15  	"io/ioutil"
    16  	"os"
    17  	"os/exec"
    18  )
    19  
    20  func main() {
    21  	f, err := ioutil.TempFile("", "sinit-*.o")
    22  	if err != nil {
    23  		fmt.Println(err)
    24  		os.Exit(1)
    25  	}
    26  	f.Close()
    27  
    28  	cmd := exec.Command("go", "tool", "compile", "-o", f.Name(), "-S", "sinit.go")
    29  	out, err := cmd.CombinedOutput()
    30  	os.Remove(f.Name())
    31  	if err != nil {
    32  		fmt.Println(string(out))
    33  		fmt.Println(err)
    34  		os.Exit(1)
    35  	}
    36  
    37  	if len(bytes.TrimSpace(out)) == 0 {
    38  		fmt.Println("'go tool compile -S sinit.go' printed no output")
    39  		os.Exit(1)
    40  	}
    41  	if bytes.Contains(out, []byte("initdone")) {
    42  		fmt.Println("sinit generated an init function")
    43  		os.Exit(1)
    44  	}
    45  }
    46  

View as plain text