From f1288873486a6ed7ae3710429bf6c4d09b05ca1a Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Sat, 17 May 2025 16:11:16 -0400 Subject: [PATCH 1/3] Add script to create clone of testing/testing.db to allow for writes in tests --- scripts/clone_test_db.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 scripts/clone_test_db.sh diff --git a/scripts/clone_test_db.sh b/scripts/clone_test_db.sh new file mode 100755 index 000000000..7a9affb47 --- /dev/null +++ b/scripts/clone_test_db.sh @@ -0,0 +1,3 @@ +#!/bin/bash +rm -f testing/testing_clone.db +sqlite3 testing/testing/db '.clone testing/testing_clone.db' > /dev/null From 45de41626cd24f4874d2d716d9ed782e1fb1a512 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Sat, 17 May 2025 16:11:59 -0400 Subject: [PATCH 2/3] Adjust sqlite3 compat tests to use temp cloned database so further tests dont break --- sqlite3/tests/compat/mod.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/sqlite3/tests/compat/mod.rs b/sqlite3/tests/compat/mod.rs index 6dba7edba..ed1145713 100644 --- a/sqlite3/tests/compat/mod.rs +++ b/sqlite3/tests/compat/mod.rs @@ -74,7 +74,7 @@ mod tests { unsafe { let mut db = ptr::null_mut(); assert_eq!( - sqlite3_open(b"not-found/local.db\0".as_ptr() as *const i8, &mut db), + sqlite3_open(c"not-found/local.db".as_ptr(), &mut db), SQLITE_CANTOPEN ); } @@ -85,7 +85,7 @@ mod tests { unsafe { let mut db = ptr::null_mut(); assert_eq!( - sqlite3_open(b"../testing/testing.db\0".as_ptr() as *const i8, &mut db), + sqlite3_open(c"../testing/testing_clone.db".as_ptr(), &mut db), SQLITE_OK ); assert_eq!(sqlite3_close(db), SQLITE_OK); @@ -104,19 +104,13 @@ mod tests { unsafe { let mut db = ptr::null_mut(); assert_eq!( - sqlite3_open(b"../testing/testing.db\0".as_ptr() as *const i8, &mut db), + sqlite3_open(c"../testing/testing_clone.db".as_ptr(), &mut db), SQLITE_OK ); let mut stmt = ptr::null_mut(); assert_eq!( - sqlite3_prepare_v2( - db, - b"SELECT 1\0".as_ptr() as *const i8, - -1, - &mut stmt, - ptr::null_mut() - ), + sqlite3_prepare_v2(db, c"SELECT 1".as_ptr(), -1, &mut stmt, ptr::null_mut()), SQLITE_OK ); @@ -131,7 +125,7 @@ mod tests { // Test with valid db let mut db = ptr::null_mut(); assert_eq!( - sqlite3_open(b"../testing/testing.db\0".as_ptr() as *const i8, &mut db), + sqlite3_open(c"../testing/testing_clone.db".as_ptr(), &mut db), SQLITE_OK ); assert_eq!(sqlite3_wal_checkpoint(db, ptr::null()), SQLITE_OK); @@ -145,7 +139,7 @@ mod tests { // Test with valid db let mut db = ptr::null_mut(); assert_eq!( - sqlite3_open(b"../testing/testing.db\0".as_ptr() as *const i8, &mut db), + sqlite3_open(c"../testing/testing_clone.db".as_ptr(), &mut db), SQLITE_OK ); @@ -210,7 +204,7 @@ mod tests { unsafe { let mut db = ptr::null_mut(); assert_eq!( - sqlite3_open(b"../testing/testing.db\0".as_ptr() as *const i8, &mut db), + sqlite3_open(c"../testing/testing_clone.db".as_ptr(), &mut db), SQLITE_OK ); // Ensure that WAL is initially empty. @@ -222,7 +216,7 @@ mod tests { assert_eq!( sqlite3_prepare_v2( db, - b"CREATE TABLE test (id INTEGER PRIMARY KEY)\0".as_ptr() as *const i8, + c"CREATE TABLE test (id INTEGER PRIMARY KEY)".as_ptr(), -1, &mut stmt, ptr::null_mut() @@ -235,7 +229,7 @@ mod tests { assert_eq!( sqlite3_prepare_v2( db, - b"INSERT INTO test (id) VALUES (1)\0".as_ptr() as *const i8, + c"INSERT INTO test (id) VALUES (1)".as_ptr(), -1, &mut stmt, ptr::null_mut() From 6d70e6d0484687da9a96f5cf038b3c257a2d4bac Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Sat, 17 May 2025 16:23:17 -0400 Subject: [PATCH 3/3] Add reset db to Makefile to create clean testing db between tests that perform writes --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 245c57b12..846867a0c 100644 --- a/Makefile +++ b/Makefile @@ -74,8 +74,13 @@ test-time: SQLITE_EXEC=$(SQLITE_EXEC) ./testing/time.test .PHONY: test-time -test-sqlite3: +reset-db: + ./scripts/clone_test_db.sh +.PHONY: reset-db + +test-sqlite3: reset-db cargo test -p limbo_sqlite3 --test compat + ./scripts/clone_test_db.sh cargo test -p limbo_sqlite3 --test compat --features sqlite3 .PHONY: test-sqlite3