1
0
mirror of https://github.com/golang/go synced 2024-11-21 12:04:41 -07:00

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
This commit is contained in:
Shenghou Ma 2012-09-20 00:27:23 +08:00
parent 4d7c81bc67
commit 674bbafce6
4 changed files with 16 additions and 26 deletions

View File

@ -1,15 +1,22 @@
// skip
// Copyright 2009 The Go Authors. All rights reserved. // Copyright 2009 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.
// +build !netbsd
package stdio package stdio
/* /*
#include <stdio.h> #include <stdio.h>
// 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" import "C"
var Stdout = (*File)(C.stdout) var Stdout = (*File)(C.getStdout())
var Stderr = (*File)(C.stderr) var Stderr = (*File)(C.getStderr())

View File

@ -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 <stdio.h>
extern FILE __sF[3];
*/
import "C"
import "unsafe"
var Stdout = (*File)(unsafe.Pointer(&C.__sF[1]))
var Stderr = (*File)(unsafe.Pointer(&C.__sF[2]))

View File

@ -70,11 +70,10 @@ if x%CGO_ENABLED% == x0 goto nocgo
::if errorlevel 1 goto fail ::if errorlevel 1 goto fail
::echo. ::echo.
:: TODO ..\misc\cgo\stdio echo # ..\misc\cgo\stdio
::echo # ..\misc\cgo\stdio go run %GOROOT%\test\run.go - ..\misc\cgo\stdio
::go run %GOROOT%\test\run.go - ..\misc\cgo\stdio if errorlevel 1 goto fail
::if errorlevel 1 goto fail echo.
::echo.
echo # ..\misc\cgo\test echo # ..\misc\cgo\test
go test ..\misc\cgo\test go test ..\misc\cgo\test

View File

@ -344,7 +344,7 @@ func (t *test) run() {
if err != nil { if err != nil {
t.err = fmt.Errorf("%s\n%s", err, out) 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) t.err = fmt.Errorf("incorrect output\n%s", out)
} }