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

misc/cgo/test: run tests

The new gotest ignores Test functions outside *_test.go files
(the old shell script allowed them), so replace one clumsy hack
with another.

The root problem is that the package makefiles only know
how to run cgo for source files in the package proper, not
for test files.  Making it work for test files is probably more
trouble than it's worth.

R=bradfitz
CC=golang-dev
https://golang.org/cl/4452060
This commit is contained in:
Russ Cox 2011-05-02 13:55:51 -04:00
parent 3599e3fc12
commit f985638b94
6 changed files with 40 additions and 18 deletions

View File

@ -58,7 +58,7 @@ import (
"testing"
)
func TestAlign(t *testing.T) {
func testAlign(t *testing.T) {
var evt C.SDL_KeyboardEvent
C.makeEvent(&evt)
if C.same(&evt, evt.typ, evt.which, evt.state, evt.keysym.scancode, evt.keysym.sym, evt.keysym.mod, evt.keysym.unicode) == 0 {

View File

@ -90,31 +90,31 @@ func Atol(s string) int {
return int(n)
}
func TestConst(t *testing.T) {
func testConst(t *testing.T) {
C.myConstFunc(nil, 0, nil)
}
func TestEnum(t *testing.T) {
func testEnum(t *testing.T) {
if C.Enum1 != 1 || C.Enum2 != 2 {
t.Error("bad enum", C.Enum1, C.Enum2)
}
}
func TestAtol(t *testing.T) {
func testAtol(t *testing.T) {
l := Atol("123")
if l != 123 {
t.Error("Atol 123: ", l)
}
}
func TestErrno(t *testing.T) {
func testErrno(t *testing.T) {
n, err := Strtol("asdf", 123)
if n != 0 || err != os.EINVAL {
t.Error("Strtol: ", n, err)
}
}
func TestMultipleAssign(t *testing.T) {
func testMultipleAssign(t *testing.T) {
p := C.CString("234")
n, m := C.strtol(p, nil, 345), C.strtol(p, nil, 10)
if n != 0 || m != 234 {

View File

@ -27,7 +27,7 @@ func goCallback(p unsafe.Pointer) {
(*(*func())(unsafe.Pointer(&p)))()
}
func TestCallback(t *testing.T) {
func testCallback(t *testing.T) {
var x = false
nestedCall(func() { x = true })
if !x {
@ -35,13 +35,13 @@ func TestCallback(t *testing.T) {
}
}
func TestCallbackGC(t *testing.T) {
func testCallbackGC(t *testing.T) {
nestedCall(runtime.GC)
}
func lockedOSThread() bool // in runtime.c
func TestCallbackPanic(t *testing.T) {
func testCallbackPanic(t *testing.T) {
// Make sure panic during callback unwinds properly.
if lockedOSThread() {
t.Fatal("locked OS thread on entry to TestCallbackPanic")
@ -62,14 +62,14 @@ func TestCallbackPanic(t *testing.T) {
panic("nestedCall returned")
}
func TestCallbackPanicLoop(t *testing.T) {
func testCallbackPanicLoop(t *testing.T) {
// Make sure we don't blow out m->g0 stack.
for i := 0; i < 100000; i++ {
TestCallbackPanic(t)
}
}
func TestCallbackPanicLocked(t *testing.T) {
func testCallbackPanicLocked(t *testing.T) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
@ -94,7 +94,7 @@ func TestCallbackPanicLocked(t *testing.T) {
// Callback with zero arguments used to make the stack misaligned,
// which broke the garbage collector and other things.
func TestZeroArgCallback(t *testing.T) {
func testZeroArgCallback(t *testing.T) {
defer func() {
s := recover()
if s != nil {
@ -118,7 +118,7 @@ func goFoo() {
func variadic(x ...interface{}) {}
func TestBlocking(t *testing.T) {
func testBlocking(t *testing.T) {
c := make(chan int)
go func() {
for i := 0; i < 10; i++ {

View File

@ -1,5 +1,27 @@
// Copyright 2011 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 cgotest
// dummy file so gotest thinks there are tests.
// the actual tests are in the main go files, next
// to the code they test.
import "testing"
// The actual test functions are in non-_test.go files
// so that they can use cgo (import "C").
// These wrappers are here for gotest to find.
func TestAlign(t *testing.T) { testAlign(t) }
func TestConst(t *testing.T) { testConst(t) }
func TestEnum(t *testing.T) { testEnum(t) }
func TestAtol(t *testing.T) { testAtol(t) }
func TestErrno(t *testing.T) { testErrno(t) }
func TestMultipleAssign(t *testing.T) { testMultipleAssign(t) }
func TestCallback(t *testing.T) { testCallback(t) }
func TestCallbackGC(t *testing.T) { testCallbackGC(t) }
func TestCallbackPanic(t *testing.T) { testCallbackPanic(t) }
func TestCallbackPanicLoop(t *testing.T) { testCallbackPanicLoop(t) }
func TestCallbackPanicLocked(t *testing.T) { testCallbackPanicLocked(t) }
func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) }
func TestBlocking(t *testing.T) { testBlocking(t) }
func Test1328(t *testing.T) { test1328(t) }
func TestParallelSleep(t *testing.T) { testParallelSleep(t) }

View File

@ -25,6 +25,6 @@ func BackIntoGo() {
func xvariadic(x ...interface{}) {
}
func Test1328(t *testing.T) {
func test1328(t *testing.T) {
C.IntoC()
}

View File

@ -35,7 +35,7 @@ func BackgroundSleep(n int) {
}()
}
func TestParallelSleep(t *testing.T) {
func testParallelSleep(t *testing.T) {
dt := -time.Nanoseconds()
parallelSleep(1)
dt += time.Nanoseconds()