Commit 746114df authored by gwenn's avatar gwenn

Skip some tests when cgocheck is enabled.

parent 40f42098
...@@ -15,4 +15,5 @@ install: ...@@ -15,4 +15,5 @@ install:
before_script: before_script:
- go get github.com/bmizerany/assert - go get github.com/bmizerany/assert
script: script:
- GODEBUG=cgocheck=2 go test -v -tags all github.com/gwenn/gosqlite
- GODEBUG=cgocheck=0 go test -v -tags all github.com/gwenn/gosqlite - GODEBUG=cgocheck=0 go test -v -tags all github.com/gwenn/gosqlite
...@@ -15,6 +15,8 @@ import ( ...@@ -15,6 +15,8 @@ import (
) )
func TestInterrupt(t *testing.T) { func TestInterrupt(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
db.CreateScalarFunction("interrupt", 0, false, nil, func(ctx *ScalarContext, nArg int) { db.CreateScalarFunction("interrupt", 0, false, nil, func(ctx *ScalarContext, nArg int) {
...@@ -85,6 +87,8 @@ func TestBusyTimeout(t *testing.T) { ...@@ -85,6 +87,8 @@ func TestBusyTimeout(t *testing.T) {
} }
func TestBusyHandler(t *testing.T) { func TestBusyHandler(t *testing.T) {
skipIfCgoCheckActive(t)
f, db1, db2 := openTwoConnSameDb(t) f, db1, db2 := openTwoConnSameDb(t)
defer os.Remove(f.Name()) defer os.Remove(f.Name())
defer checkClose(db1, t) defer checkClose(db1, t)
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
package sqlite_test package sqlite_test
import ( import (
"testing"
. "github.com/gwenn/gosqlite" . "github.com/gwenn/gosqlite"
"testing"
) )
func checkCacheSize(t *testing.T, db *Conn, expectedSize, expectedMaxSize int) { func checkCacheSize(t *testing.T, db *Conn, expectedSize, expectedMaxSize int) {
......
...@@ -17,6 +17,8 @@ import ( ...@@ -17,6 +17,8 @@ import (
) )
func TestCsvModule(t *testing.T) { func TestCsvModule(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
err := LoadCsvModule(db) err := LoadCsvModule(db)
...@@ -112,6 +114,8 @@ var csvModuleTests = []struct { ...@@ -112,6 +114,8 @@ var csvModuleTests = []struct {
} }
func TestCsvModuleArguments(t *testing.T) { func TestCsvModuleArguments(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
err := LoadCsvModule(db) err := LoadCsvModule(db)
......
...@@ -24,6 +24,8 @@ func half(ctx *ScalarContext, nArg int) { ...@@ -24,6 +24,8 @@ func half(ctx *ScalarContext, nArg int) {
} }
func TestScalarFunction(t *testing.T) { func TestScalarFunction(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
err := db.CreateScalarFunction("half", 1, true, nil, half, nil) err := db.CreateScalarFunction("half", 1, true, nil, half, nil)
...@@ -71,6 +73,8 @@ func reDestroy(ad interface{}) { ...@@ -71,6 +73,8 @@ func reDestroy(ad interface{}) {
} }
func TestRegexpFunction(t *testing.T) { func TestRegexpFunction(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
err := db.CreateScalarFunction("regexp", 2, true, nil, re, reDestroy) err := db.CreateScalarFunction("regexp", 2, true, nil, re, reDestroy)
...@@ -106,6 +110,8 @@ func user(ctx *ScalarContext, nArg int) { ...@@ -106,6 +110,8 @@ func user(ctx *ScalarContext, nArg int) {
} }
func TestUserFunction(t *testing.T) { func TestUserFunction(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
err := db.CreateScalarFunction("user", 0, false, nil, user, nil) err := db.CreateScalarFunction("user", 0, false, nil, user, nil)
...@@ -140,6 +146,8 @@ func sumFinal(ctx *AggregateContext) { ...@@ -140,6 +146,8 @@ func sumFinal(ctx *AggregateContext) {
} }
func TestSumFunction(t *testing.T) { func TestSumFunction(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
err := db.CreateAggregateFunction("mysum", 1, nil, sumStep, sumFinal, nil) err := db.CreateAggregateFunction("mysum", 1, nil, sumStep, sumFinal, nil)
......
...@@ -7,6 +7,7 @@ package sqlite_test ...@@ -7,6 +7,7 @@ package sqlite_test
import ( import (
"fmt" "fmt"
"testing" "testing"
. "github.com/gwenn/gosqlite" . "github.com/gwenn/gosqlite"
) )
...@@ -44,6 +45,8 @@ func TestNoHook(t *testing.T) { ...@@ -44,6 +45,8 @@ func TestNoHook(t *testing.T) {
} }
func TestCommitHook(t *testing.T) { func TestCommitHook(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
...@@ -54,6 +57,8 @@ func TestCommitHook(t *testing.T) { ...@@ -54,6 +57,8 @@ func TestCommitHook(t *testing.T) {
} }
func TestRollbackHook(t *testing.T) { func TestRollbackHook(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
...@@ -64,6 +69,8 @@ func TestRollbackHook(t *testing.T) { ...@@ -64,6 +69,8 @@ func TestRollbackHook(t *testing.T) {
} }
func TestUpdateHook(t *testing.T) { func TestUpdateHook(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
createTable(db, t) createTable(db, t)
......
...@@ -6,6 +6,7 @@ package sqlite_test ...@@ -6,6 +6,7 @@ package sqlite_test
import ( import (
"fmt" "fmt"
"os"
"path" "path"
"reflect" "reflect"
"runtime" "runtime"
...@@ -23,6 +24,12 @@ func checkNoError(t *testing.T, err error, format string) { ...@@ -23,6 +24,12 @@ func checkNoError(t *testing.T, err error, format string) {
} }
} }
func skipIfCgoCheckActive(t *testing.T) {
if runtime.Version() >= "go1.6" && !strings.Contains(os.Getenv("GODEBUG"), "cgocheck=0") {
t.Skip("cgocheck")
}
}
func Must(b bool, err error) bool { func Must(b bool, err error) bool {
if err != nil { if err != nil {
panic(err) panic(err)
......
...@@ -382,11 +382,11 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error { ...@@ -382,11 +382,11 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error {
if i64 && len(value) > math.MaxInt32 { if i64 && len(value) > math.MaxInt32 {
return s.specificError("blob too big: %d at index %d", len(value), index) return s.specificError("blob too big: %d at index %d", len(value), index)
} }
var p *byte if len(value) == 0 {
if len(value) > 0 { rv = C.my_bind_blob(s.stmt, i, nil, 0)
p = &value[0] } else {
rv = C.my_bind_blob(s.stmt, i, unsafe.Pointer(&value[0]), C.int(len(value)))
} }
rv = C.my_bind_blob(s.stmt, i, unsafe.Pointer(p), C.int(len(value)))
case time.Time: case time.Time:
if NullIfZeroTime && value.IsZero() { if NullIfZeroTime && value.IsZero() {
rv = C.sqlite3_bind_null(s.stmt, i) rv = C.sqlite3_bind_null(s.stmt, i)
......
...@@ -17,12 +17,12 @@ import ( ...@@ -17,12 +17,12 @@ import (
func init() { func init() {
if os.Getenv("SQLITE_LOG") == "" { if os.Getenv("SQLITE_LOG") == "" {
err := ConfigLog(func(d interface{}, err error, msg string) { err := ConfigLog(func(d interface{}, err error, msg string) {
fmt.Printf("%s: %s, %s\n", d, err, msg) fmt.Printf("SQLITE: %s, %s\n", err, msg)
}, "SQLITE") }, nil)
if err != nil { if err != nil {
panic(fmt.Sprintf("couldn't config log: '%s'", err)) panic(fmt.Sprintf("couldn't config log: '%s'", err))
} }
err = ConfigLog(nil, "") err = ConfigLog(nil, nil)
if err != nil { if err != nil {
panic(fmt.Sprintf("couldn't unset logger: '%s'", err)) panic(fmt.Sprintf("couldn't unset logger: '%s'", err))
} }
...@@ -74,6 +74,8 @@ func TestNoTrace(t *testing.T) { ...@@ -74,6 +74,8 @@ func TestNoTrace(t *testing.T) {
} }
func TestTrace(t *testing.T) { func TestTrace(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
db.Trace(trace, t) db.Trace(trace, t)
...@@ -88,6 +90,8 @@ func TestTrace(t *testing.T) { ...@@ -88,6 +90,8 @@ func TestTrace(t *testing.T) {
} }
func TestProfile(t *testing.T) { func TestProfile(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
db.Profile(profile, t) db.Profile(profile, t)
......
...@@ -99,6 +99,8 @@ func (vc *testVTabCursor) Rowid() (int64, error) { ...@@ -99,6 +99,8 @@ func (vc *testVTabCursor) Rowid() (int64, error) {
} }
func TestCreateModule(t *testing.T) { func TestCreateModule(t *testing.T) {
skipIfCgoCheckActive(t)
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
intarray := []int{1, 2, 3} intarray := []int{1, 2, 3}
......
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