modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/bug248.go (about)

     1  // +build !nacl,!plan9,!windows
     2  // run
     3  
     4  // Copyright 2009 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  package main
     9  
    10  import (
    11  	"fmt"
    12  	"os"
    13  	"os/exec"
    14  	"path/filepath"
    15  )
    16  
    17  func main() {
    18  	// TODO: If we get rid of errchk, re-enable this test on Windows.
    19  	errchk, err := filepath.Abs("errchk")
    20  	check(err)
    21  
    22  	err = os.Chdir(filepath.Join("fixedbugs", "bug248.dir"))
    23  	check(err)
    24  
    25  	run("go", "tool", "compile", "bug0.go")
    26  	run("go", "tool", "compile", "bug1.go")
    27  	run("go", "tool", "compile", "bug2.go")
    28  	run(errchk, "go", "tool", "compile", "-e", "bug3.go")
    29  	run("go", "tool", "link", "bug2.o")
    30  	run(fmt.Sprintf(".%ca.out", filepath.Separator))
    31  
    32  	os.Remove("bug0.o")
    33  	os.Remove("bug1.o")
    34  	os.Remove("bug2.o")
    35  	os.Remove("a.out")
    36  }
    37  
    38  func run(name string, args ...string) {
    39  	cmd := exec.Command(name, args...)
    40  	out, err := cmd.CombinedOutput()
    41  	if err != nil {
    42  		fmt.Println(string(out))
    43  		fmt.Println(err)
    44  		os.Exit(1)
    45  	}
    46  }
    47  
    48  func check(err error) {
    49  	if err != nil {
    50  		fmt.Println(err)
    51  		os.Exit(1)
    52  	}
    53  }