-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #730 from vyzo/rip-run-tests
RIP std/run-tests.ss
- Loading branch information
Showing
20 changed files
with
603 additions
and
643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,53 @@ | ||
;;; -*- Gerbil -*- | ||
;;; (C) vyzo at hackzen.org | ||
;;; :std/db/leveldb unit-test | ||
(import :std/test | ||
:std/db/leveldb | ||
:std/format | ||
:gerbil/gambit/random) | ||
(import :std/build-config) | ||
(cond-expand | ||
(config-have-leveldb | ||
(import :std/test | ||
:std/db/leveldb | ||
:std/os/temporaries) | ||
|
||
(export leveldb-test) | ||
(def leveldb-test | ||
(test-suite "test :std/db/leveldb library" | ||
(def db (leveldb-open (format "/tmp/test.db.~a" (random-integer (expt 2 32))))) | ||
(test-case "test put/get/delete" | ||
(leveldb-put db "abc" "this-is-abc") | ||
(leveldb-put db "def" "this-is-def") | ||
(check (bytes->string (leveldb-get db "abc")) => "this-is-abc") | ||
(check (bytes->string (leveldb-get db "def")) => "this-is-def") | ||
(leveldb-delete db "abc") | ||
(check (leveldb-get db "abc") => #f) | ||
(leveldb-delete db "def") | ||
(check (leveldb-get db "def") => #f)) | ||
(export leveldb-test test-setup! test-cleanup!) | ||
|
||
(test-case "test write batch" | ||
(def wb (leveldb-writebatch)) | ||
(leveldb-writebatch-put wb "abc" "this-is-abc") | ||
(leveldb-writebatch-put wb "def" "this-is-def") | ||
(leveldb-write db wb) | ||
(check (bytes->string (leveldb-get db "abc")) => "this-is-abc") | ||
(check (bytes->string (leveldb-get db "def")) => "this-is-def")) | ||
(def db #f) | ||
(def (test-setup!) | ||
(let (tmp (make-temporary-file-name "test.db")) | ||
(set! db (leveldb-open tmp)))) | ||
(def (test-cleanup!) | ||
(leveldb-close db)) | ||
|
||
(test-case "test iterators" | ||
(def itor (leveldb-iterator db)) | ||
(check (leveldb-iterator-valid? itor) => #f) | ||
(leveldb-iterator-seek-first itor) | ||
(check (leveldb-iterator-valid? itor) => #t) | ||
(check (bytes->string (leveldb-iterator-key itor)) => "abc") | ||
(check (bytes->string (leveldb-iterator-value itor)) => "this-is-abc") | ||
(leveldb-iterator-next itor) | ||
(check (leveldb-iterator-valid? itor) => #t) | ||
(check (bytes->string (leveldb-iterator-key itor)) => "def") | ||
(check (bytes->string (leveldb-iterator-value itor)) => "this-is-def") | ||
(leveldb-iterator-next itor) | ||
(check (leveldb-iterator-valid? itor) => #f) | ||
(leveldb-iterator-close itor)) | ||
(def leveldb-test | ||
(test-suite "test :std/db/leveldb library" | ||
(test-case "test put/get/delete" | ||
(leveldb-put db "abc" "this-is-abc") | ||
(leveldb-put db "def" "this-is-def") | ||
(check (bytes->string (leveldb-get db "abc")) => "this-is-abc") | ||
(check (bytes->string (leveldb-get db "def")) => "this-is-def") | ||
(leveldb-delete db "abc") | ||
(check (leveldb-get db "abc") => #f) | ||
(leveldb-delete db "def") | ||
(check (leveldb-get db "def") => #f)) | ||
|
||
(leveldb-close db))) | ||
(test-case "test write batch" | ||
(def wb (leveldb-writebatch)) | ||
(leveldb-writebatch-put wb "abc" "this-is-abc") | ||
(leveldb-writebatch-put wb "def" "this-is-def") | ||
(leveldb-write db wb) | ||
(check (bytes->string (leveldb-get db "abc")) => "this-is-abc") | ||
(check (bytes->string (leveldb-get db "def")) => "this-is-def")) | ||
|
||
(test-case "test iterators" | ||
(def itor (leveldb-iterator db)) | ||
(check (leveldb-iterator-valid? itor) => #f) | ||
(leveldb-iterator-seek-first itor) | ||
(check (leveldb-iterator-valid? itor) => #t) | ||
(check (bytes->string (leveldb-iterator-key itor)) => "abc") | ||
(check (bytes->string (leveldb-iterator-value itor)) => "this-is-abc") | ||
(leveldb-iterator-next itor) | ||
(check (leveldb-iterator-valid? itor) => #t) | ||
(check (bytes->string (leveldb-iterator-key itor)) => "def") | ||
(check (bytes->string (leveldb-iterator-value itor)) => "this-is-def") | ||
(leveldb-iterator-next itor) | ||
(check (leveldb-iterator-valid? itor) => #f) | ||
(leveldb-iterator-close itor)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,53 @@ | ||
;;; -*- Gerbil -*- | ||
;;; (C) vyzo at hackzen.org | ||
;;; :std/db/lmdb unit-test | ||
(import :std/test | ||
:std/db/lmdb | ||
:std/db/_lmdb | ||
:gerbil/gambit/random | ||
:std/format) | ||
(import :std/build-config) | ||
(cond-expand | ||
(config-have-lmdb | ||
(import :std/test | ||
:std/db/lmdb | ||
:std/db/_lmdb | ||
:std/os/temporaries) | ||
(export lmdb-test test-setup! test-cleanup!) | ||
|
||
(export lmdb-test) | ||
(def lmdb-test | ||
(test-suite "test :std/db/lmdb library" | ||
(def env (lmdb-open (format "/tmp/test.db.~a" (random-integer (expt 2 32))))) | ||
(def db (lmdb-open-db env "test")) | ||
(test-case "test put txn" | ||
(let (txn (lmdb-txn-begin env)) | ||
(lmdb-put txn db "hello" "world") | ||
(lmdb-put txn db "hello2" "world2") | ||
(check (bytes->string (lmdb-get txn db "hello")) => "world") | ||
(check (bytes->string (lmdb-get txn db "hello2")) => "world2") | ||
(lmdb-txn-commit txn))) | ||
(test-case "test get" | ||
(let (txn (lmdb-txn-begin env)) | ||
(check (bytes->string (lmdb-get txn db "hello")) => "world") | ||
(check (bytes->string (lmdb-get txn db "hello2")) => "world2") | ||
(lmdb-txn-commit txn))) | ||
(test-case "test cursors" | ||
(let* ((txn (lmdb-txn-begin env)) | ||
(cursor (lmdb-cursor-open txn db)) | ||
(entries | ||
(let lp ((next (lmdb-cursor-get cursor MDB_FIRST)) (vals [])) | ||
(match next | ||
((values key val) | ||
(lp (lmdb-cursor-get cursor MDB_NEXT) (cons (cons (bytes->string key) | ||
(bytes->string val)) | ||
vals))) | ||
(#f (reverse vals)))))) | ||
(check (length entries) => 2) | ||
(check (cdr (assoc "hello" entries)) => "world") | ||
(check (cdr (assoc "hello2" entries)) => "world2") | ||
(lmdb-txn-commit txn))))) | ||
(def env #f) | ||
(def db #f) | ||
|
||
(def (test-setup!) | ||
(let (tmp (make-temporary-file-name "test.db")) | ||
(set! env (lmdb-open tmp)) | ||
(set! db (lmdb-open-db env "test")))) | ||
|
||
(def (test-cleanup!) | ||
(lmdb-close-db db) | ||
(lmdb-close env)) | ||
|
||
(def lmdb-test | ||
(test-suite "test :std/db/lmdb library" | ||
(test-case "test put txn" | ||
(let (txn (lmdb-txn-begin env)) | ||
(lmdb-put txn db "hello" "world") | ||
(lmdb-put txn db "hello2" "world2") | ||
(check (bytes->string (lmdb-get txn db "hello")) => "world") | ||
(check (bytes->string (lmdb-get txn db "hello2")) => "world2") | ||
(lmdb-txn-commit txn))) | ||
(test-case "test get" | ||
(let (txn (lmdb-txn-begin env)) | ||
(check (bytes->string (lmdb-get txn db "hello")) => "world") | ||
(check (bytes->string (lmdb-get txn db "hello2")) => "world2") | ||
(lmdb-txn-commit txn))) | ||
(test-case "test cursors" | ||
(let* ((txn (lmdb-txn-begin env)) | ||
(cursor (lmdb-cursor-open txn db)) | ||
(entries | ||
(let lp ((next (lmdb-cursor-get cursor MDB_FIRST)) (vals [])) | ||
(match next | ||
((values key val) | ||
(lp (lmdb-cursor-get cursor MDB_NEXT) (cons (cons (bytes->string key) | ||
(bytes->string val)) | ||
vals))) | ||
(#f (reverse vals)))))) | ||
(check (length entries) => 2) | ||
(check (cdr (assoc "hello" entries)) => "world") | ||
(check (cdr (assoc "hello2" entries)) => "world2") | ||
(lmdb-txn-commit txn))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,73 @@ | ||
;;; -*- Gerbil -*- | ||
;;; (C) vyzo at hackzen.org | ||
;;; :std/db/mysql unit-test | ||
(import :std/test | ||
:std/db/dbi | ||
:std/db/mysql) | ||
(export mysql-test) | ||
(def mysql-test | ||
(test-suite "test :std/db/mysql" | ||
(def db (sql-connect mysql-connect host: "localhost" user: "test" passwd: "test" db: "test")) | ||
(import :std/build-config) | ||
(cond-expand | ||
((and config-have-mysql enable-mysql-test) | ||
(import :std/test | ||
:std/db/dbi | ||
:std/db/mysql) | ||
(export mysql-test test-setup! test-cleanup!) | ||
|
||
(test-case "prepare tables" | ||
(with-catch void (cut sql-eval db "DROP TABLE Users")) | ||
(with-catch void (cut sql-eval db "DROP TABLE HitCount")) | ||
(def db #f) | ||
(def (test-setup!) | ||
(set! db (sql-connect mysql-connect host: "localhost" user: "test" passwd: "test" db: "test")) | ||
(with-catch void (cut sql-eval db "DROP TABLE Users")) | ||
(with-catch void (cut sql-eval db "DROP TABLE HitCount"))) | ||
(def (test-cleanup!) | ||
(with-catch void (cut sql-eval db "DROP TABLE Users")) | ||
(with-catch void (cut sql-eval db "DROP TABLE HitCount")) | ||
(sql-close db)) | ||
|
||
(let (stmt (sql-prepare db "CREATE TABLE Users (FirstName VARCHAR(20), LastName VARCHAR(20), Secret VARCHAR(20))")) | ||
(check (sql-exec stmt) => #!void) | ||
(sql-finalize stmt)) | ||
(def mysql-test | ||
(test-suite "test :std/db/mysql" | ||
(test-case "prepare tables" | ||
(let (stmt (sql-prepare db "CREATE TABLE Users (FirstName VARCHAR(20), LastName VARCHAR(20), Secret VARCHAR(20))")) | ||
(check (sql-exec stmt) => #!void) | ||
(sql-finalize stmt)) | ||
|
||
(let (stmt (sql-prepare db "INSERT INTO Users (FirstName, LastName, Secret) VALUES (?, ?, ?)")) | ||
(sql-bind stmt "John" "Smith" "very secret") | ||
(check (sql-exec stmt) => #!void) | ||
(sql-reset stmt) | ||
(sql-clear stmt) | ||
(sql-bind stmt "Marc" "Smith" "oh so secret") | ||
(check (sql-exec stmt) => #!void) | ||
(sql-bind stmt "Minnie" "Smith" #f) | ||
(check (sql-exec stmt) => #!void) | ||
(sql-finalize stmt)) | ||
(let (stmt (sql-prepare db "INSERT INTO Users (FirstName, LastName, Secret) VALUES (?, ?, ?)")) | ||
(sql-bind stmt "John" "Smith" "very secret") | ||
(check (sql-exec stmt) => #!void) | ||
(sql-reset stmt) | ||
(sql-clear stmt) | ||
(sql-bind stmt "Marc" "Smith" "oh so secret") | ||
(check (sql-exec stmt) => #!void) | ||
(sql-bind stmt "Minnie" "Smith" #f) | ||
(check (sql-exec stmt) => #!void) | ||
(sql-finalize stmt)) | ||
|
||
(let (stmt (sql-prepare db "CREATE TABLE HitCount (User VARCHAR(20), Hits INTEGER)")) | ||
(check (sql-exec stmt) => #!void) | ||
(sql-finalize stmt)) | ||
(let (stmt (sql-prepare db "CREATE TABLE HitCount (User VARCHAR(20), Hits INTEGER)")) | ||
(check (sql-exec stmt) => #!void) | ||
(sql-finalize stmt)) | ||
|
||
(let (stmt (sql-prepare db "INSERT INTO HitCount (User,Hits) VALUES (?, ?)")) | ||
(sql-bind stmt "john" 20) | ||
(check (sql-exec stmt) => #!void) | ||
(sql-finalize stmt))) | ||
(let (stmt (sql-prepare db "INSERT INTO HitCount (User,Hits) VALUES (?, ?)")) | ||
(sql-bind stmt "john" 20) | ||
(check (sql-exec stmt) => #!void) | ||
(sql-finalize stmt))) | ||
|
||
(test-case "read and modify table" | ||
(test-case "read and modify table" | ||
(let (stmt (sql-prepare db "SELECT * FROM Users")) | ||
(check (sql-query stmt) => '(#("John" "Smith" "very secret") | ||
#("Marc" "Smith" "oh so secret") | ||
#("Minnie" "Smith" #f)))) | ||
|
||
(let (stmt (sql-prepare db "SELECT * FROM Users")) | ||
(check (sql-query stmt) => '(#("John" "Smith" "very secret") | ||
#("Marc" "Smith" "oh so secret") | ||
#("Minnie" "Smith" #f)))) | ||
(let (stmt (sql-prepare db "SELECT * FROM Users WHERE FirstName = ?")) | ||
(sql-bind stmt "John") | ||
(check (sql-query stmt) => '(#("John" "Smith" "very secret"))) | ||
(sql-finalize stmt)) | ||
|
||
(let (stmt (sql-prepare db "SELECT * FROM Users WHERE FirstName = ?")) | ||
(sql-bind stmt "John") | ||
(check (sql-query stmt) => '(#("John" "Smith" "very secret"))) | ||
(sql-finalize stmt)) | ||
(let (stmt (sql-prepare db "DELETE FROM Users WHERE FirstName = ?")) | ||
(sql-bind stmt "Marc") | ||
(check (sql-exec stmt) => #!void) | ||
(sql-finalize stmt)) | ||
|
||
(let (stmt (sql-prepare db "DELETE FROM Users WHERE FirstName = ?")) | ||
(sql-bind stmt "Marc") | ||
(check (sql-exec stmt) => #!void) | ||
(sql-finalize stmt)) | ||
(let (stmt (sql-prepare db "SELECT * FROM Users")) | ||
(check (sql-query stmt) => '(#("John" "Smith" "very secret") | ||
#("Minnie" "Smith" #f))) | ||
(sql-finalize stmt)) | ||
|
||
(let (stmt (sql-prepare db "SELECT * FROM Users")) | ||
(check (sql-query stmt) => '(#("John" "Smith" "very secret") | ||
#("Minnie" "Smith" #f))) | ||
(sql-finalize stmt)) | ||
|
||
(let (stmt (sql-prepare db "SELECT * FROM HitCount")) | ||
(check (sql-query stmt) => '(#("john" 20))) | ||
(sql-finalize stmt))) | ||
|
||
(with-catch void (cut sql-eval db "DROP TABLE Users")) | ||
(with-catch void (cut sql-eval db "DROP TABLE HitCount")) | ||
|
||
(sql-close db))) | ||
(let (stmt (sql-prepare db "SELECT * FROM HitCount")) | ||
(check (sql-query stmt) => '(#("john" 20))) | ||
(sql-finalize stmt))) | ||
)))) |
Oops, something went wrong.