Commit ed799862 authored by gwenn's avatar gwenn

Introduce assert library.

parent 28ac60e4
......@@ -5,6 +5,7 @@
package sqlite_test
import (
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
"testing"
)
......@@ -42,8 +43,8 @@ func TestBackupMisuse(t *testing.T) {
defer checkClose(db, t)
bck, err := NewBackup(db, "", db, "")
assert(t, "source and destination must be distinct", bck == nil && err != nil)
assert.T(t, bck == nil && err != nil, "source and destination must be distinct")
err = bck.Run(10, 0, nil)
assert(t, "misuse expected", err != nil)
assert.T(t, err != nil, "misuse expected")
//println(err.Error())
}
......@@ -5,6 +5,7 @@
package sqlite_test
import (
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
"io"
"testing"
......@@ -47,15 +48,15 @@ func TestBlob(t *testing.T) {
content = make([]byte, size+5)
n, err = br.Read(content[:5])
checkNoError(t, err, "blob read error: %s")
assertEquals(t, "expected %d bytes but got %d", 5, n)
assert.Equal(t, 5, n, "bytes")
n, err = br.Read(content[5:])
checkNoError(t, err, "blob read error: %s")
assertEquals(t, "expected %d bytes but got %d", 5, n)
assert.Equal(t, 5, n, "bytes")
//fmt.Printf("%#v\n", content)
n, err = br.Read(content[10:])
assert(t, "error expected", n == 0 && err == io.EOF)
assert.T(t, n == 0 && err == io.EOF, "error expected")
err = br.Reopen(rowid)
checkNoError(t, err, "blob reopen error: %s")
......@@ -67,10 +68,10 @@ func TestBlobMisuse(t *testing.T) {
defer checkClose(db, t)
bw, err := db.NewBlobReadWriter("main", "test", "content", 0)
assert(t, "error expected", bw == nil && err != nil)
assert.T(t, bw == nil && err != nil, "error expected")
//println(err.Error())
/*err = bw.Close()
assert(t, "error expected", err != nil)*/
assert.T(t, err != nil, "error expected")*/
}
func TestZeroLengthBlob(t *testing.T) {
......@@ -87,5 +88,5 @@ func TestZeroLengthBlob(t *testing.T) {
var blob []byte
err = db.OneValue("SELECT content FROM test WHERE rowid = ?", &blob, rowid)
checkNoError(t, err, "select error: %s")
assert(t, "nil blob expected", blob == nil)
assert.T(t, blob == nil, "nil blob expected")
}
......@@ -5,6 +5,7 @@
package sqlite_test
import (
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
"io/ioutil"
"os"
......@@ -108,5 +109,5 @@ func TestBusyHandler(t *testing.T) {
_, err = db2.SchemaVersion("")
checkNoError(t, err, "couldn't query schema version: %#v")
assert(t, "busy handler not called!", called)
assert.T(t, called, "expected busy handler to be called")
}
......@@ -5,6 +5,7 @@
package sqlite_test
import (
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
"testing"
"time"
......@@ -105,8 +106,8 @@ func TestBindTimeAsString(t *testing.T) {
var tim time.Time
//err = db.OneValue("SELECT /*date(*/time/*)*/ FROM test where ROWID = ?", &tim, id1)
//checkNoError(t, err, "error selecting YearMonthDay: %s")
//assertEquals(t, "Year MonthDay: %d vs %d", now.Year(), tim.Year())
//assertEquals(t, "YearMonth Day: %d vs %d", now.YearDay(), tim.YearDay())
//assert.Equal(t, now.Year(), tim.Year(), "year")
//assert.Equal(t, now.YearDay(), tim.YearDay(), "yearDay")
err = db.OneValue("SELECT /*datetime(*/time/*)*/ FROM test where ROWID = ?", &tim, id2)
checkNoError(t, err, "error selecting TimeStamp: %s")
......@@ -137,9 +138,9 @@ func TestBindTimeAsNumeric(t *testing.T) {
var tim time.Time
err = db.OneValue("SELECT /*datetime(*/ time/*, 'unixepoch')*/ FROM test where ROWID = ?", &tim, id1)
checkNoError(t, err, "error selecting UnixTime: %s")
assertEquals(t, "Year: %s vs %s", now, tim)
assert.Equal(t, now, tim)
err = db.OneValue("SELECT /*julianday(*/time/*)*/ FROM test where ROWID = ?", &tim, id2)
checkNoError(t, err, "error selecting JulianTime: %s")
assertEquals(t, "Year: %s vs %s", now, tim)
assert.Equal(t, now, tim)
}
......@@ -6,6 +6,7 @@ package sqlite_test
import (
"database/sql"
"github.com/bmizerany/assert"
"testing"
)
......@@ -73,10 +74,10 @@ func TestSqlDml(t *testing.T) {
checkNoError(t, err, "Error updating data: %s")
id, err := result.LastInsertId()
checkNoError(t, err, "Error while calling LastInsertId: %s")
assertEquals(t, "expected %d got %d LastInsertId", int64(2), id)
assert.Equal(t, int64(2), id, "lastInsertId")
changes, err := result.RowsAffected()
checkNoError(t, err, "Error while calling RowsAffected: %s")
assertEquals(t, "expected %d got %d RowsAffected", int64(0), changes)
assert.Equal(t, int64(0), changes, "rowsAffected")
}
func TestSqlInsert(t *testing.T) {
......@@ -86,10 +87,10 @@ func TestSqlInsert(t *testing.T) {
checkNoError(t, err, "Error updating data: %s")
id, err := result.LastInsertId()
checkNoError(t, err, "Error while calling LastInsertId: %s")
assertEquals(t, "expected %d got %d LastInsertId", int64(1), id)
assert.Equal(t, int64(1), id, "lastInsertId")
changes, err := result.RowsAffected()
checkNoError(t, err, "Error while calling RowsAffected: %s")
assertEquals(t, "expected %d got %d RowsAffected", int64(1), changes)
assert.Equal(t, int64(1), changes, "rowsAffected")
}
func TestSqlExecWithIllegalCmd(t *testing.T) {
......@@ -137,10 +138,10 @@ func TestSqlPrepare(t *testing.T) {
checkNoError(t, err, "Error while executing stmt: %s")
id, err := result.LastInsertId()
checkNoError(t, err, "Error while calling LastInsertId: %s")
assertEquals(t, "expected %d got %d LastInsertId", int64(3), id)
assert.Equal(t, int64(3), id, "lastInsertId")
changes, err := result.RowsAffected()
checkNoError(t, err, "Error while calling RowsAffected: %s")
assertEquals(t, "expected %d got %d RowsAffected", int64(1), changes)
assert.Equal(t, int64(1), changes, "rowsAffected")
}
func TestRowsWithStmtClosed(t *testing.T) {
......
......@@ -5,6 +5,7 @@
package sqlite_test
import (
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
"math/rand"
"os"
......@@ -29,7 +30,7 @@ func TestScalarFunction(t *testing.T) {
var d float64
err = db.OneValue("SELECT half(6)", &d)
checkNoError(t, err, "couldn't retrieve result: %s")
assertEquals(t, "Expected %f but got %f", 3.0, d)
assert.Equal(t, 3.0, d)
err = db.CreateScalarFunction("half", 1, nil, nil, nil)
checkNoError(t, err, "couldn't destroy function: %s")
}
......@@ -82,16 +83,16 @@ func TestRegexpFunction(t *testing.T) {
}
i, _, err := s.ScanInt(0)
checkNoError(t, err, "couldn't scan result: %s")
assertEquals(t, "expected %d but got %d", 1, i)
assert(t, "unexpected reused state", !reused)
assert.Equal(t, 1, i)
assert.T(t, !reused, "unexpected reused state")
if b := Must(s.Next()); !b {
t.Fatalf("No result")
}
i, _, err = s.ScanInt(0)
checkNoError(t, err, "couldn't scan result: %s")
assertEquals(t, "expected %d but got %d", 0, i)
assert(t, "unexpected reused state", reused)
assert.Equal(t, 0, i)
assert.T(t, reused, "unexpected reused state")
}
func user(ctx *ScalarContext, nArg int) {
......@@ -110,7 +111,7 @@ func TestUserFunction(t *testing.T) {
var name string
err = db.OneValue("SELECT user()", &name)
checkNoError(t, err, "couldn't retrieve result: %s")
assert(t, "unexpected user name: %q", len(name) > 0)
assert.Tf(t, len(name) > 0, "unexpected user name: %q", name)
err = db.CreateScalarFunction("user", 1, nil, nil, nil)
checkNoError(t, err, "couldn't destroy function: %s")
}
......@@ -144,7 +145,7 @@ func TestSumFunction(t *testing.T) {
var i int
err = db.OneValue("SELECT mysum(i) FROM (SELECT 2 AS i UNION ALL SELECT 2)", &i)
checkNoError(t, err, "couldn't execute statement: %s")
assertEquals(t, "expected %d but got %v", 4, i)
assert.Equal(t, 4, i)
err = db.CreateAggregateFunction("mysum", 1, nil, nil, nil, nil)
checkNoError(t, err, "couldn't unregister function: %s")
......
......@@ -5,6 +5,7 @@
package sqlite_test
import (
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
"testing"
)
......@@ -35,12 +36,12 @@ func TestTables(t *testing.T) {
tables, err := db.Tables("")
checkNoError(t, err, "error looking for tables: %s")
assertEquals(t, "expected %d table but got %d", 0, len(tables))
assert.Equal(t, 0, len(tables), "table count")
createTable(db, t)
tables, err = db.Tables("main")
checkNoError(t, err, "error looking for tables: %s")
assertEquals(t, "expected %d table but got %d", 1, len(tables))
assertEquals(t, "wrong table name: %q <> %q", "test", tables[0])
assert.Equal(t, 1, len(tables), "table count")
assert.Equal(t, "test", tables[0], "table name")
}
func TestColumns(t *testing.T) {
......@@ -54,7 +55,7 @@ func TestColumns(t *testing.T) {
t.Fatalf("Expected 4 columns <> %d", len(columns))
}
column := columns[2]
assertEquals(t, "wrong column name: %q <> %q", "int_num", column.Name)
assert.Equal(t, "int_num", column.Name, "column name")
columns, err = db.Columns("main", "test")
checkNoError(t, err, "error listing columns: %s")
......@@ -67,9 +68,9 @@ func TestColumn(t *testing.T) {
column, err := db.Column("", "test", "id")
checkNoError(t, err, "error getting column metadata: %s")
assertEquals(t, "wrong column name: %q <> %q", "id", column.Name)
assertEquals(t, "wrong primary key index: %d <> %d", 1, column.Pk)
assert(t, "expecting autoinc flag to be false", !column.Autoinc)
assert.Equal(t, "id", column.Name, "column name")
assert.Equal(t, 1, column.Pk, "primary key index")
assert.T(t, !column.Autoinc, "expecting autoinc flag to be false")
column, err = db.Column("main", "test", "id")
checkNoError(t, err, "error getting column metadata: %s")
......@@ -106,8 +107,8 @@ func TestIndexes(t *testing.T) {
t.Fatalf("Expected one index <> %d", len(indexes))
}
index := indexes[0]
assertEquals(t, "wrong index name: %q <> %q", "test_index", index.Name)
assert(t, "index 'test_index' is not unique", !index.Unique)
assert.Equal(t, "test_index", index.Name, "index name")
assert.T(t, !index.Unique, "expected index 'test_index' to be not unique")
columns, err := db.IndexColumns("", "test_index")
checkNoError(t, err, "error listing index columns: %s")
......@@ -115,7 +116,7 @@ func TestIndexes(t *testing.T) {
t.Fatalf("expected one column <> %d", len(columns))
}
column := columns[0]
assertEquals(t, "Wrong column name: %q <> %q", "a_string", column.Name)
assert.Equal(t, "a_string", column.Name, "column name")
}
func TestColumnMetadata(t *testing.T) {
......@@ -126,11 +127,11 @@ func TestColumnMetadata(t *testing.T) {
defer checkFinalize(s, t)
databaseName := s.ColumnDatabaseName(0)
assertEquals(t, "wrong database name: %q <> %q", "main", databaseName)
assert.Equal(t, "main", databaseName, "database name")
tableName := s.ColumnTableName(0)
assertEquals(t, "wrong table name: %q <> %q", "sqlite_master", tableName)
assert.Equal(t, "sqlite_master", tableName, "table name")
originName := s.ColumnOriginName(0)
assertEquals(t, "wrong origin name: %q <> %q", "name", originName)
assert.Equal(t, "name", originName, "origin name")
declType := s.ColumnDeclaredType(0)
assertEquals(t, "wrong declared type: %q <> %q", "text", declType)
assert.Equal(t, "text", declType, "declared type")
}
......@@ -5,6 +5,7 @@
package sqlite_test
import (
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
"testing"
"time"
......@@ -17,14 +18,14 @@ func TestPool(t *testing.T) {
for i := 0; i <= 10; i++ {
c, err := pool.Get()
checkNoError(t, err, "error getting connection from the pool: %s")
assert(t, "no connection returned by the pool", c != nil)
assert(t, "connection returned by the pool is alive", !c.IsClosed())
assert.T(t, c != nil, "expected connection returned by the pool")
assert.T(t, !c.IsClosed(), "connection returned by the pool is alive")
_, err = c.SchemaVersion("main")
checkNoError(t, err, "error using connection from the pool: %s")
pool.Release(c)
}
pool.Close()
assert(t, "pool not closed", pool.IsClosed())
assert.T(t, pool.IsClosed(), "expected pool to be closed")
}
func TestTryGet(t *testing.T) {
......@@ -34,9 +35,9 @@ func TestTryGet(t *testing.T) {
defer pool.Close()
c, err := pool.TryGet()
checkNoError(t, err, "error getting connection from the pool: %s")
assert(t, "no connection returned by the pool", c != nil)
assert.T(t, c != nil, "expected connection returned by the pool")
defer pool.Release(c)
c1, err := pool.TryGet()
assert(t, "no connection returned by the pool", c1 == nil && err == nil)
assert.T(t, c1 == nil && err == nil, "expected no connection returned by the pool")
}
......@@ -5,6 +5,7 @@
package sqlite_test
import (
"github.com/bmizerany/assert"
"testing"
)
......@@ -19,7 +20,7 @@ func TestEncoding(t *testing.T) {
defer checkClose(db, t)
encoding, err := db.Encoding("")
checkNoError(t, err, "Error reading encoding of database: %s")
assertEquals(t, "Expecting %s but got %s", "UTF-8", encoding)
assert.Equal(t, "UTF-8", encoding)
}
func TestSchemaVersion(t *testing.T) {
......@@ -27,7 +28,7 @@ func TestSchemaVersion(t *testing.T) {
defer checkClose(db, t)
version, err := db.SchemaVersion("")
checkNoError(t, err, "Error reading schema version of database: %s")
assertEquals(t, "expecting %d but got %d", 0, version)
assert.Equal(t, 0, version)
}
func TestJournalMode(t *testing.T) {
......@@ -35,7 +36,7 @@ func TestJournalMode(t *testing.T) {
defer checkClose(db, t)
mode, err := db.JournalMode("")
checkNoError(t, err, "Error reading journaling mode of database: %s")
assertEquals(t, "expecting %s but got %s", "memory", mode)
assert.Equal(t, "memory", mode)
}
func TestSetJournalMode(t *testing.T) {
......@@ -43,7 +44,7 @@ func TestSetJournalMode(t *testing.T) {
defer checkClose(db, t)
mode, err := db.SetJournalMode("", "OFF")
checkNoError(t, err, "Error setting journaling mode of database: %s")
assertEquals(t, "expecting %s but got %s", "off", mode)
assert.Equal(t, "off", mode)
}
func TestLockingMode(t *testing.T) {
......@@ -51,7 +52,7 @@ func TestLockingMode(t *testing.T) {
defer checkClose(db, t)
mode, err := db.LockingMode("")
checkNoError(t, err, "Error reading locking-mode of database: %s")
assertEquals(t, "expecting %s but got %s", "normal", mode)
assert.Equal(t, "normal", mode)
}
func TestSetLockingMode(t *testing.T) {
......@@ -59,7 +60,7 @@ func TestSetLockingMode(t *testing.T) {
defer checkClose(db, t)
mode, err := db.SetLockingMode("", "exclusive")
checkNoError(t, err, "Error setting locking-mode of database: %s")
assertEquals(t, "expecting %s but got %s", "exclusive", mode)
assert.Equal(t, "exclusive", mode)
}
func TestSynchronous(t *testing.T) {
......@@ -67,7 +68,7 @@ func TestSynchronous(t *testing.T) {
defer checkClose(db, t)
mode, err := db.Synchronous("")
checkNoError(t, err, "Error reading synchronous flag of database: %s")
assertEquals(t, "expecting %d but got %d", 2, mode)
assert.Equal(t, 2, mode)
}
func TestSetSynchronous(t *testing.T) {
......@@ -77,5 +78,5 @@ func TestSetSynchronous(t *testing.T) {
checkNoError(t, err, "Error setting synchronous flag of database: %s")
mode, err := db.Synchronous("")
checkNoError(t, err, "Error reading synchronous flag of database: %s")
assertEquals(t, "expecting %d but got %d", 0, mode)
assert.Equal(t, 0, mode)
}
......@@ -5,6 +5,7 @@
package sqlite_test
import (
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
"reflect"
"strings"
......@@ -58,7 +59,7 @@ func TestOpen(t *testing.T) {
func TestOpenFailure(t *testing.T) {
db, err := Open("doesnotexist.sqlite", OpenReadOnly)
assert(t, "open failure expected", db == nil && err != nil)
assert.T(t, db == nil && err != nil, "open failure expected")
//println(err.Error())
}
......@@ -68,7 +69,7 @@ func TestEnableFKey(t *testing.T) {
b := Must(db.IsFKeyEnabled())
if !b {
b = Must(db.EnableFKey(true))
assert(t, "cannot enabled FK", b)
assert.T(t, b, "cannot enable FK")
}
}
......@@ -78,14 +79,14 @@ func TestEnableTriggers(t *testing.T) {
b := Must(db.AreTriggersEnabled())
if !b {
b = Must(db.EnableTriggers(true))
assert(t, "cannot enabled triggers", b)
assert.T(t, b, "cannot enable triggers")
}
}
func TestEnableExtendedResultCodes(t *testing.T) {
db := open(t)
defer checkClose(db, t)
checkNoError(t, db.EnableExtendedResultCodes(true), "cannot enabled extended result codes: %s")
checkNoError(t, db.EnableExtendedResultCodes(true), "cannot enable extended result codes: %s")
}
func TestCreateTable(t *testing.T) {
......@@ -121,9 +122,9 @@ func TestExists(t *testing.T) {
db := open(t)
defer checkClose(db, t)
b := Must(db.Exists("SELECT 1 WHERE 1 = 0"))
assert(t, "No row expected", !b)
assert.T(t, !b, "no row expected")
b = Must(db.Exists("SELECT 1 WHERE 1 = 1"))
assert(t, "One row expected", b)
assert.T(t, b, "one row expected")
}
func TestInsert(t *testing.T) {
......@@ -135,32 +136,32 @@ func TestInsert(t *testing.T) {
ierr := db.Exec("INSERT INTO test (float_num, int_num, a_string) VALUES (?, ?, ?)", float64(i)*float64(3.14), i, "hello")
checkNoError(t, ierr, "insert error: %s")
c := db.Changes()
assertEquals(t, "insert error: expected %d changes but got %d", 1, c)
assert.Equal(t, 1, c, "changes")
}
checkNoError(t, db.Commit(), "Error: %s")
lastID := db.LastInsertRowid()
assertEquals(t, "last insert row id error: expected %d but got %d", int64(1000), lastID)
assert.Equal(t, int64(1000), lastID, "last insert row id")
cs, _ := db.Prepare("SELECT COUNT(*) FROM test")
defer checkFinalize(cs, t)
paramCount := cs.BindParameterCount()
assertEquals(t, "bind parameter count error: expected %d but got %d", 0, paramCount)
assert.Equal(t, 0, paramCount, "bind parameter count")
columnCount := cs.ColumnCount()
assertEquals(t, "column count error: expected %d but got %d", 1, columnCount)
assert.Equal(t, 1, columnCount, "column count")
if !Must(cs.Next()) {
t.Fatal("no result for count")
}
assertEquals(t, "column & data count not equal: %d versus %d", columnCount, cs.DataCount())
assert.Equal(t, columnCount, cs.DataCount(), "column & data count expected to be equal")
var i int
checkNoError(t, cs.Scan(&i), "error scanning count: %s")
assertEquals(t, "count should be %d, but it is %d", 1000, i)
assert.Equal(t, 1000, i, "count")
if Must(cs.Next()) {
t.Fatal("Only one row expected")
}
assert(t, "Statement not reset", !cs.Busy())
assert.T(t, !cs.Busy(), "expected statement to be reset")
}
/*
......@@ -193,9 +194,9 @@ func TestConnExecWithSelect(t *testing.T) {
defer checkClose(db, t)
err := db.Exec("SELECT 1")
assert(t, "error expected", err != nil)
assert.T(t, err != nil, "error expected")
if serr, ok := err.(*StmtError); ok {
assertEquals(t, "expected %q but got %q", Row, serr.Code())
assert.Equal(t, Row, serr.Code())
} else {
t.Errorf("Expected StmtError but got %s", reflect.TypeOf(err))
}
......@@ -205,21 +206,21 @@ func TestConnInitialState(t *testing.T) {
db := open(t)
defer checkClose(db, t)
autoCommit := db.GetAutocommit()
assert(t, "autocommit expected to be active by default", autoCommit)
assert.T(t, autoCommit, "autocommit expected to be active by default")
totalChanges := db.TotalChanges()
assertEquals(t, "expected total changes: %d, actual: %d", 0, totalChanges)
assert.Equal(t, 0, totalChanges, "total changes")
err := db.LastError()
assertEquals(t, "expected last error: %v, actual: %v", nil, err)
assert.Equal(t, nil, err, "expected last error to be nil")
readonly, err := db.Readonly("main")
checkNoError(t, err, "Readonly status error: %s")
assert(t, "readonly expected to be unset by default", !readonly)
assert.T(t, !readonly, "readonly expected to be unset by default")
}
func TestReadonlyMisuse(t *testing.T) {
db := open(t)
defer checkClose(db, t)
_, err := db.Readonly("doesnotexist")
assert(t, "error expected", err != nil)
assert.T(t, err != nil, "error expected")
err.Error()
//println(err.Error())
}
......@@ -234,7 +235,7 @@ func TestConnSettings(t *testing.T) {
}
func TestComplete(t *testing.T) {
assert(t, "expected complete statement", Complete("SELECT 1;"))
assert.T(t, Complete("SELECT 1;"), "expected complete statement")
}
func TestExecMisuse(t *testing.T) {
......@@ -242,7 +243,7 @@ func TestExecMisuse(t *testing.T) {
defer checkClose(db, t)
createTable(db, t)
err := db.Exec("INSERT INTO test VALUES (?, ?, ?, ?); INSERT INTO test VALUES (?, ?, ?, ?)", 0, 273.1, 1, "test")
assert(t, "exec misuse expected", err != nil)
assert.T(t, err != nil, "exec misuse expected")
}
func TestTransaction(t *testing.T) {
......@@ -258,14 +259,3 @@ func TestTransaction(t *testing.T) {
})
checkNoError(t, err, "error: %s")
}
func assertEquals(t *testing.T, format string, expected, actual interface{}) {
if expected != actual {
t.Errorf(format, expected, actual)
}
}
func assert(t *testing.T, msg string, actual bool) {
if !actual {
t.Error(msg)
}
}
This diff is collapsed.
......@@ -6,6 +6,7 @@ package sqlite_test
import (
"fmt"
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
"testing"
)
......@@ -131,9 +132,9 @@ func TestLog(t *testing.T) {
func TestMemory(t *testing.T) {
used := MemoryUsed()
assert(t, "memory used", used >= 0)
assert.T(t, used >= 0, "memory used")
highwater := MemoryHighwater(false)
assert(t, "memory highwater", highwater >= 0)
assert.T(t, highwater >= 0, "memory highwater")
limit := SoftHeapLimit()
assert(t, "soft heap limit positive", limit >= 0)
assert.T(t, limit >= 0, "soft heap limit positive")
}
......@@ -6,6 +6,7 @@ package sqlite_test
import (
"fmt"
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
"testing"
)
......@@ -26,13 +27,13 @@ type testVTabCursor struct {
func (m testModule) Create(c *Conn, args []string) (VTab, error) {
//println("testVTab.Create")
assert(m.t, "Six arguments expected", len(args) == 6)
assertEquals(m.t, "Expected '%s' but got '%s' as module name", "test", args[0])
assertEquals(m.t, "Expected '%s' but got '%s' as db name", "main", args[1])
assertEquals(m.t, "Expected '%s' but got '%s' as table name", "vtab", args[2])
assertEquals(m.t, "Expected '%s' but got '%s' as first arg", "'1'", args[3])
assertEquals(m.t, "Expected '%s' but got '%s' as first arg", "2", args[4])
assertEquals(m.t, "Expected '%s' but got '%s' as first arg", "three", args[5])
assert.T(m.t, len(args) == 6, "six arguments expected")
assert.Equal(m.t, "test", args[0], "module name")
assert.Equal(m.t, "main", args[1], "db name")
assert.Equal(m.t, "vtab", args[2], "table name")
assert.Equal(m.t, "'1'", args[3], "first arg")
assert.Equal(m.t, "2", args[4], "second arg")
assert.Equal(m.t, "three", args[5], "third arg")
err := c.DeclareVTab("CREATE TABLE x(test TEXT)")
if err != nil {
return nil, err
......@@ -113,7 +114,7 @@ func TestCreateModule(t *testing.T) {
if err = s.Scan(&i, &value); err != nil {
return
}
assertEquals(t, "Expected '%d' but got '%d'", intarray[i], value)
assert.Equal(t, intarray[i], value, "Expected '%d' but got '%d'")
return
})
checkNoError(t, err, "couldn't select from virtual table: %s")
......
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