From 674bbafce6a52ef843eb130200d2946c92d9934d Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Thu, 20 Sep 2012 00:27:23 +0800 Subject: [PATCH] misc/cgo/stdio: make it work on Windows and also test it use a function to get stdout and stderr, instead of depending on a specific libc implementation. also make test/run.go replace \r\n by \n before comparing output. Fixes #2121. Part of issue 1741. R=alex.brainman, rsc, r, remyoudompheng CC=golang-dev https://golang.org/cl/5847068 --- misc/cgo/stdio/stdio.go | 15 +++++++++++---- misc/cgo/stdio/stdio_netbsd.go | 16 ---------------- src/run.bat | 9 ++++----- test/run.go | 2 +- 4 files changed, 16 insertions(+), 26 deletions(-) delete mode 100644 misc/cgo/stdio/stdio_netbsd.go diff --git a/misc/cgo/stdio/stdio.go b/misc/cgo/stdio/stdio.go index 67b7aea1e2a..76cb8ad80d6 100644 --- a/misc/cgo/stdio/stdio.go +++ b/misc/cgo/stdio/stdio.go @@ -1,15 +1,22 @@ +// skip + // Copyright 2009 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. -// +build !netbsd - package stdio /* #include + +// on mingw, stderr and stdout are defined as &_iob[FILENO] +// on netbsd, they are defined as &__sF[FILENO] +// and cgo doesn't recognize them, so write a function to get them, +// instead of depending on internals of libc implementation. +FILE *getStdout(void) { return stdout; } +FILE *getStderr(void) { return stderr; } */ import "C" -var Stdout = (*File)(C.stdout) -var Stderr = (*File)(C.stderr) +var Stdout = (*File)(C.getStdout()) +var Stderr = (*File)(C.getStderr()) diff --git a/misc/cgo/stdio/stdio_netbsd.go b/misc/cgo/stdio/stdio_netbsd.go deleted file mode 100644 index 075c1d0c79f..00000000000 --- a/misc/cgo/stdio/stdio_netbsd.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2009 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. - -package stdio - -/* -#include - -extern FILE __sF[3]; -*/ -import "C" -import "unsafe" - -var Stdout = (*File)(unsafe.Pointer(&C.__sF[1])) -var Stderr = (*File)(unsafe.Pointer(&C.__sF[2])) diff --git a/src/run.bat b/src/run.bat index 7f4a68889a4..4998d815fb3 100644 --- a/src/run.bat +++ b/src/run.bat @@ -70,11 +70,10 @@ if x%CGO_ENABLED% == x0 goto nocgo ::if errorlevel 1 goto fail ::echo. -:: TODO ..\misc\cgo\stdio -::echo # ..\misc\cgo\stdio -::go run %GOROOT%\test\run.go - ..\misc\cgo\stdio -::if errorlevel 1 goto fail -::echo. +echo # ..\misc\cgo\stdio +go run %GOROOT%\test\run.go - ..\misc\cgo\stdio +if errorlevel 1 goto fail +echo. echo # ..\misc\cgo\test go test ..\misc\cgo\test diff --git a/test/run.go b/test/run.go index b23860692c1..c82c138be5e 100644 --- a/test/run.go +++ b/test/run.go @@ -344,7 +344,7 @@ func (t *test) run() { if err != nil { t.err = fmt.Errorf("%s\n%s", err, out) } - if string(out) != t.expectedOutput() { + if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() { t.err = fmt.Errorf("incorrect output\n%s", out) }