Home | History | Annotate | Download | only in fixedbugs
      1 // run
      2 
      3 // Copyright 2015 The Go Authors. All rights reserved.
      4 // Use of this source code is governed by a BSD-style
      5 // license that can be found in the LICENSE file.
      6 
      7 // Test error message when EOF is encountered in the
      8 // middle of a BOM.
      9 //
     10 // Since the error requires an EOF, we cannot use the
     11 // errorcheckoutput mechanism.
     12 
     13 package main
     14 
     15 import (
     16 	"io/ioutil"
     17 	"log"
     18 	"os"
     19 	"os/exec"
     20 	"runtime"
     21 	"strings"
     22 )
     23 
     24 func main() {
     25 	// cannot use temp file on nacl via child process
     26 	if runtime.GOOS == "nacl" {
     27 		return
     28 	}
     29 
     30 	// create source
     31 	f, err := ioutil.TempFile("", "issue13268-")
     32 	if err != nil {
     33 		log.Fatalf("could not create source file: %v", err)
     34 	}
     35 	f.Write([]byte("package p\n\nfunc \xef\xef")) // if this fails, we will die later
     36 	f.Close()
     37 	defer os.Remove(f.Name())
     38 
     39 	// compile and test output
     40 	cmd := exec.Command("go", "tool", "compile", f.Name())
     41 	out, err := cmd.CombinedOutput()
     42 	if err == nil {
     43 		log.Fatalf("expected cmd/compile to fail")
     44 	}
     45 	if strings.HasPrefix(string(out), "illegal UTF-8 sequence") {
     46 		log.Fatalf("error %q not found", out)
     47 	}
     48 }
     49