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