]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/test: run tests
authorRuss Cox <rsc@golang.org>
Mon, 2 May 2011 17:55:51 +0000 (13:55 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 2 May 2011 17:55:51 +0000 (13:55 -0400)
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

misc/cgo/test/align.go
misc/cgo/test/basic.go
misc/cgo/test/callback.go
misc/cgo/test/cgo_test.go
misc/cgo/test/issue1328.go
misc/cgo/test/issue1560.go

index 2d2979595c46f76bf55106fd0812c03f364651f2..07ab9ef503a060639dbe1a1aa332889d74dcbe1e 100644 (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 {
index a94074c52e21be3e08ead721e7d4111e1be6bc41..b9d0953bd3884690a7be2b8051be90ba67a883ac 100644 (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 {
index 450a7cbf267f0da9c058df69b45a481e3c6e3cac..3edee975810e504c8423bc98c176c9a793b2b7da 100644 (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++ {
index 967dc0e9249889e72f1a4376d83442e904624a5e..e23da15770b178f2223fd9161065a4719bb1452d 100644 (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) }
index f29d7057e9a16b326036ace22d5e07f0c0ada282..e01207dd9b0472966dea1232df46b7aa5d10003d 100644 (file)
@@ -25,6 +25,6 @@ func BackIntoGo() {
 func xvariadic(x ...interface{}) {
 }
 
-func Test1328(t *testing.T) {
+func test1328(t *testing.T) {
        C.IntoC()
 }
index 75d31c03595155232e3102c96a9b5c5728df8be4..e534cce4730b145c4613fad848e6eead2613da4a 100644 (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()