1
0
mirror of https://github.com/golang/go synced 2024-11-07 11:56:17 -07:00
go/test/fixedbugs/issue22662b.go
Richard Musiol e3c684777a all: skip unsupported tests for js/wasm
The general policy for the current state of js/wasm is that it only
has to support tests that are also supported by nacl.

The test nilptr3.go makes assumptions about which nil checks can be
removed. Since WebAssembly does not signal on reading a null pointer,
all nil checks have to be explicit.

Updates #18892

Change-Id: I06a687860b8d22ae26b1c391499c0f5183e4c485
Reviewed-on: https://go-review.googlesource.com/110096
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-30 19:39:18 +00:00

66 lines
1.9 KiB
Go

// run
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Verify the impact of line directives on error positions and position formatting.
package main
import (
"io/ioutil"
"log"
"os"
"os/exec"
"runtime"
"strings"
)
// Each of these tests is expected to fail (missing package clause)
// at the position determined by the preceeding line directive.
var tests = []struct {
src, pos string
}{
{"//line :10\n", ":10:"}, // no filename means no filename
{"//line :10:4\n", "filename:10:4"}, // no filename means use existing filename
{"//line foo.go:10\n", "foo.go:10:"}, // no column means don't print a column
{"//line foo.go:10:4\n", "foo.go:10:4:"}, // column means print a column
{"//line foo.go:10:4\n\n", "foo.go:11:1:"}, // relative columns start at 1 after newline
{"/*line :10*/", ":10:"},
{"/*line :10:4*/", "filename:10:4"},
{"/*line foo.go:10*/", "foo.go:10:"},
{"/*line foo.go:10:4*/", "foo.go:10:4:"},
{"/*line foo.go:10:4*/\n", "foo.go:11:1:"},
}
func main() {
if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
return // can not exec go tool
}
f, err := ioutil.TempFile("", "issue22662b.go")
if err != nil {
log.Fatal(err)
}
f.Close()
defer os.Remove(f.Name())
for _, test := range tests {
if err := ioutil.WriteFile(f.Name(), []byte(test.src), 0660); err != nil {
log.Fatal(err)
}
out, err := exec.Command("go", "tool", "compile", f.Name()).CombinedOutput()
if err == nil {
log.Fatalf("expected compiling\n---\n%s\n---\nto fail", test.src)
}
errmsg := strings.Replace(string(out), f.Name(), "filename", -1) // use "filename" instead of actual (long) filename
if !strings.HasPrefix(errmsg, test.pos) {
log.Fatalf("%q: got %q; want position %q", test.src, errmsg, test.pos)
}
}
}