Debian Codegraph @

gcc/testsuite/go.test/test/fixedbugs/issue13268.go

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