Commit caf96861 authored by Yury Smolsky's avatar Yury Smolsky Committed by Brad Fitzpatrick

test: eliminate use of Perl in fixedbugs/bug345.go

To allow testing of fixedbugs/bug345.go in Go,
a new flag -n is introduced. This flag disables setting
of relative path for local imports and imports search path
to current dir, namely -D . -I . are not passed to the compiler.
Error regexps are fixed to allow running the test in temp directory.

This change eliminates the last place where Perl
script "errchk" was used.

Fixes #25586.

Change-Id: If085f466e6955312d77315f96d3ef1cb68495aef
Reviewed-on: https://go-review.googlesource.com/115277
Run-TryBot: Yury Smolsky <yury@smolsky.by>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent fffb3a5c
...@@ -6,8 +6,9 @@ package main ...@@ -6,8 +6,9 @@ package main
import ( import (
"bufio" "bufio"
"./io"
goio "io" goio "io"
"./io"
) )
func main() { func main() {
...@@ -22,7 +23,7 @@ func main() { ...@@ -22,7 +23,7 @@ func main() {
// main.go:27: cannot use &x (type *"io".SectionReader) as type *"/Users/rsc/g/go/test/fixedbugs/bug345.dir/io".SectionReader in function argument // main.go:27: cannot use &x (type *"io".SectionReader) as type *"/Users/rsc/g/go/test/fixedbugs/bug345.dir/io".SectionReader in function argument
var w io.Writer var w io.Writer
bufio.NewWriter(w) // ERROR "test/io|has incompatible type" bufio.NewWriter(w) // ERROR "[\w.]+[^.]/io|has incompatible type"
var x goio.SectionReader var x goio.SectionReader
io.SR(&x) // ERROR "test/io|has incompatible type" io.SR(&x) // ERROR "[\w.]+[^.]/io|has incompatible type"
} }
// +build !nacl,!js,!plan9,!windows // errorcheckdir -n
// run
// run
// Copyright 2011 The Go Authors. All rights reserved. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package ignored
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
)
func main() {
// TODO: If we get rid of errchk, re-enable this test on Plan 9 and Windows.
errchk, err := filepath.Abs("errchk")
check(err)
bugDir := filepath.Join(".", "fixedbugs", "bug345.dir")
run("go", "tool", "compile", filepath.Join(bugDir, "io.go"))
run(errchk, "go", "tool", "compile", "-e", filepath.Join(bugDir, "main.go"))
os.Remove("io.o")
}
var bugRE = regexp.MustCompile(`(?m)^BUG`)
func run(name string, args ...string) {
cmd := exec.Command(name, args...)
out, err := cmd.CombinedOutput()
if bugRE.Match(out) || err != nil {
fmt.Println(string(out))
fmt.Println(err)
os.Exit(1)
}
}
func check(err error) {
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
...@@ -216,8 +216,12 @@ func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, er ...@@ -216,8 +216,12 @@ func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, er
return runcmd(cmd...) return runcmd(cmd...)
} }
func compileInDir(runcmd runCmd, dir string, flags []string, names ...string) (out []byte, err error) { func compileInDir(runcmd runCmd, dir string, flags []string, localImports bool, names ...string) (out []byte, err error) {
cmd := []string{goTool(), "tool", "compile", "-e", "-D", ".", "-I", "."} cmd := []string{goTool(), "tool", "compile", "-e"}
if localImports {
// Set relative path for local imports and import search path to current dir.
cmd = append(cmd, "-D", ".", "-I", ".")
}
cmd = append(cmd, flags...) cmd = append(cmd, flags...)
if *linkshared { if *linkshared {
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink") cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
...@@ -489,6 +493,7 @@ func (t *test) run() { ...@@ -489,6 +493,7 @@ func (t *test) run() {
wantError := false wantError := false
wantAuto := false wantAuto := false
singlefilepkgs := false singlefilepkgs := false
localImports := true
f := strings.Fields(action) f := strings.Fields(action)
if len(f) > 0 { if len(f) > 0 {
action = f[0] action = f[0]
...@@ -530,6 +535,12 @@ func (t *test) run() { ...@@ -530,6 +535,12 @@ func (t *test) run() {
wantError = false wantError = false
case "-s": case "-s":
singlefilepkgs = true singlefilepkgs = true
case "-n":
// Do not set relative path for local imports to current dir,
// e.g. do not pass -D . -I . to the compiler.
// Used in fixedbugs/bug345.go to allow compilation and import of local pkg.
// See golang.org/issue/25635
localImports = false
case "-t": // timeout in seconds case "-t": // timeout in seconds
args = args[1:] args = args[1:]
var err error var err error
...@@ -668,7 +679,7 @@ func (t *test) run() { ...@@ -668,7 +679,7 @@ func (t *test) run() {
return return
} }
for _, gofiles := range pkgs { for _, gofiles := range pkgs {
_, t.err = compileInDir(runcmd, longdir, flags, gofiles...) _, t.err = compileInDir(runcmd, longdir, flags, localImports, gofiles...)
if t.err != nil { if t.err != nil {
return return
} }
...@@ -690,7 +701,7 @@ func (t *test) run() { ...@@ -690,7 +701,7 @@ func (t *test) run() {
errPkg-- errPkg--
} }
for i, gofiles := range pkgs { for i, gofiles := range pkgs {
out, err := compileInDir(runcmd, longdir, flags, gofiles...) out, err := compileInDir(runcmd, longdir, flags, localImports, gofiles...)
if i == errPkg { if i == errPkg {
if wantError && err == nil { if wantError && err == nil {
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out) t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
...@@ -727,7 +738,7 @@ func (t *test) run() { ...@@ -727,7 +738,7 @@ func (t *test) run() {
return return
} }
for i, gofiles := range pkgs { for i, gofiles := range pkgs {
_, err := compileInDir(runcmd, longdir, flags, gofiles...) _, err := compileInDir(runcmd, longdir, flags, localImports, gofiles...)
// Allow this package compilation fail based on conditions below; // Allow this package compilation fail based on conditions below;
// its errors were checked in previous case. // its errors were checked in previous case.
if err != nil && !(wantError && action == "errorcheckandrundir" && i == len(pkgs)-2) { if err != nil && !(wantError && action == "errorcheckandrundir" && i == len(pkgs)-2) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment