Skip to content

Commit 6dd301a

Browse files
committed
test(bindings): run full suite with absolute path (second run), add test_seekdb_absolute, remove in-process close+open test
1 parent ca0b4cd commit 6dd301a

File tree

9 files changed

+121
-13
lines changed

9 files changed

+121
-13
lines changed

unittest/include/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
seekdb.db
22
build
3-
node_modules
3+
node_modules
4+
*.db

unittest/include/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ target_link_libraries(test_seekdb
1515
libseekdb
1616
)
1717

18-
# Add test target
18+
# Add test target: first run with default (relative) path
1919
add_test(NAME test_seekdb COMMAND test_seekdb)
2020
set_tests_properties(test_seekdb PROPERTIES TIMEOUT 300)
2121

22+
# Second run with absolute path (same as Rust/Python/Go/Node bindings)
23+
set(SEEKDB_ABS_DIR "${CMAKE_CURRENT_BINARY_DIR}/seekdb_abs.db")
24+
add_test(NAME test_seekdb_absolute COMMAND test_seekdb ${SEEKDB_ABS_DIR})
25+
set_tests_properties(test_seekdb_absolute PROPERTIES TIMEOUT 300 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
26+

unittest/include/go/test.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,26 @@ echo "Running Go tests..."
4343
echo ""
4444
# Note: C ABI layer handles SIGSEGV gracefully during static destructors
4545
# Exit code is 0 and no segfault messages are output
46-
go run test.go
46+
go run test.go "${DB_DIR}"
47+
GO_EXIT=$?
48+
if [ $GO_EXIT -ne 0 ]; then
49+
echo "First run (relative path) failed with exit $GO_EXIT"
50+
exit $GO_EXIT
51+
fi
52+
53+
# Second run: absolute path (same suite, no close+reopen in process)
54+
DB_DIR_ABS="$(pwd)/seekdb_abs.db"
55+
rm -rf "${DB_DIR_ABS}"
56+
echo ""
57+
echo "Running Go tests with absolute path: $DB_DIR_ABS"
58+
echo ""
59+
go run test.go "${DB_DIR_ABS}"
60+
ABS_EXIT=$?
61+
rm -rf "${DB_DIR_ABS}" 2>/dev/null || true
62+
if [ $ABS_EXIT -ne 0 ]; then
63+
echo "Second run (absolute path) failed with exit $ABS_EXIT"
64+
exit $ABS_EXIT
65+
fi
4766

4867
echo ""
4968
echo "Test completed!"

unittest/include/nodejs/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ if (require.main === module) {
832832

833833
module.exports = {
834834
testOpen,
835+
testAbsolutePathOpen,
835836
testConnection,
836837
testErrorHandling,
837838
testResultOperations,

unittest/include/nodejs/test.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,26 @@ echo "Running Node.js tests..."
4949
echo ""
5050
# Note: C ABI layer handles SIGSEGV gracefully during static destructors
5151
# Exit code is 0 and no segfault messages are output
52-
node test.js
52+
node test.js "${DB_DIR}" "test"
53+
NODE_EXIT=$?
54+
if [ $NODE_EXIT -ne 0 ]; then
55+
echo "First run (relative path) failed with exit $NODE_EXIT"
56+
exit $NODE_EXIT
57+
fi
58+
59+
# Second run: absolute path (same suite, no close+reopen in process)
60+
DB_DIR_ABS="$(pwd)/seekdb_abs.db"
61+
rm -rf "${DB_DIR_ABS}"
62+
echo ""
63+
echo "Running Node.js tests with absolute path: $DB_DIR_ABS"
64+
echo ""
65+
node test.js "${DB_DIR_ABS}" "test"
66+
ABS_EXIT=$?
67+
rm -rf "${DB_DIR_ABS}" 2>/dev/null || true
68+
if [ $ABS_EXIT -ne 0 ]; then
69+
echo "Second run (absolute path) failed with exit $ABS_EXIT"
70+
exit $ABS_EXIT
71+
fi
5372

5473
echo ""
5574
echo "Test completed!"

unittest/include/nodejs_napi/test.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,26 @@ echo "Running Node.js N-API tests..."
4949
echo ""
5050
# Note: C ABI layer handles SIGSEGV gracefully during static destructors
5151
# Exit code is 0 and no segfault messages are output
52-
node test.js "$@"
52+
node test.js "${DB_DIR}" "test"
53+
NODE_EXIT=$?
54+
if [ $NODE_EXIT -ne 0 ]; then
55+
echo "First run (relative path) failed with exit $NODE_EXIT"
56+
exit $NODE_EXIT
57+
fi
58+
59+
# Second run: absolute path (same suite, no close+reopen in process)
60+
DB_DIR_ABS="${SCRIPT_DIR}/seekdb_abs.db"
61+
rm -rf "${DB_DIR_ABS}"
62+
echo ""
63+
echo "Running Node.js N-API tests with absolute path: $DB_DIR_ABS"
64+
echo ""
65+
node test.js "${DB_DIR_ABS}" "test"
66+
ABS_EXIT=$?
67+
rm -rf "${DB_DIR_ABS}" 2>/dev/null || true
68+
if [ $ABS_EXIT -ne 0 ]; then
69+
echo "Second run (absolute path) failed with exit $ABS_EXIT"
70+
exit $ABS_EXIT
71+
fi
5372

5473
echo ""
5574
echo "Test completed!"

unittest/include/python/test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ echo ""
5353
# Python also uses os._exit() to avoid cleanup issues
5454
# Exit code is 0 and no segfault messages are output
5555
$PYTHON_CMD -u test.py "${DB_DIR}" "test"
56+
PY_EXIT=$?
57+
if [ $PY_EXIT -ne 0 ]; then
58+
echo "First run (relative path) failed with exit $PY_EXIT"
59+
exit $PY_EXIT
60+
fi
61+
62+
# Second run: absolute path (same suite, no close+reopen in process)
63+
DB_DIR_ABS="$(pwd)/seekdb_abs.db"
64+
rm -rf "${DB_DIR_ABS}"
65+
echo ""
66+
echo "Running Python tests with absolute path: $DB_DIR_ABS"
67+
echo ""
68+
$PYTHON_CMD -u test.py "${DB_DIR_ABS}" "test"
69+
ABS_EXIT=$?
70+
rm -rf "${DB_DIR_ABS}" 2>/dev/null || true
71+
if [ $ABS_EXIT -ne 0 ]; then
72+
echo "Second run (absolute path) failed with exit $ABS_EXIT"
73+
exit $ABS_EXIT
74+
fi
5675

5776
echo ""
5877
echo "Test completed!"

unittest/include/rust/test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ if [ ! -f "$TEST_BIN" ]; then
6565
fi
6666

6767
"$TEST_BIN" "${DB_DIR}" "test"
68+
RUST_EXIT=$?
69+
if [ $RUST_EXIT -ne 0 ]; then
70+
echo "First run (relative path) failed with exit $RUST_EXIT"
71+
exit $RUST_EXIT
72+
fi
73+
74+
# Second run: absolute path (same suite, no close+reopen in process)
75+
DB_DIR_ABS="$(pwd)/seekdb_abs.db"
76+
rm -rf "${DB_DIR_ABS}"
77+
echo ""
78+
echo "Running Rust tests with absolute path: $DB_DIR_ABS"
79+
echo ""
80+
"$TEST_BIN" "${DB_DIR_ABS}" "test"
81+
ABS_EXIT=$?
82+
rm -rf "${DB_DIR_ABS}" 2>/dev/null || true
83+
if [ $ABS_EXIT -ne 0 ]; then
84+
echo "Second run (absolute path) failed with exit $ABS_EXIT"
85+
exit $ABS_EXIT
86+
fi
6887

6988
echo ""
7089
echo "Test completed!"

unittest/include/test_seekdb.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ struct TestResult {
2525
std::string message;
2626
};
2727

28+
// Database path used by main(); set in main() so same-path-reuse tests use it
29+
static const char* g_db_path = "./seekdb.db";
30+
2831
// Test database open (database is already open in main, just verify it's open)
2932
TestResult test_open() {
3033
// Database is already open in main(), so just verify we can create a connection
@@ -2713,13 +2716,13 @@ TestResult test_empty_json_metadata() {
27132716
return {true, ""};
27142717
}
27152718

2716-
// Same-process same-path reuse: second seekdb_open() with same path (relative) must return success (no "db opened by other process").
2719+
// Same-process same-path reuse: second seekdb_open() with same path must return success (no "db opened by other process").
27172720
TestResult test_embedded_same_path_reuse_relative() {
2718-
// Database already opened in main() with "./seekdb.db"; open again with same path must succeed
2719-
int ret = seekdb_open("./seekdb.db");
2721+
// Re-open with the same path used in main() (relative or absolute)
2722+
int ret = seekdb_open(g_db_path);
27202723
if (ret != SEEKDB_SUCCESS) {
27212724
const char* err = seekdb_last_error();
2722-
return {false, std::string("second seekdb_open(\"./seekdb.db\") should succeed, got: ") + (err ? err : "unknown")};
2725+
return {false, std::string("second seekdb_open(same path) should succeed, got: ") + (err ? err : "unknown")};
27232726
}
27242727
return {true, ""};
27252728
}
@@ -2730,7 +2733,7 @@ TestResult test_embedded_same_path_reuse_absolute() {
27302733
if (getcwd(cwd, sizeof(cwd)) == nullptr) {
27312734
return {false, "getcwd failed"};
27322735
}
2733-
std::string abs_path = std::string(cwd) + "/seekdb.db";
2736+
std::string abs_path = (g_db_path[0] == '/') ? g_db_path : (std::string(cwd) + "/" + g_db_path);
27342737
int ret = seekdb_open(abs_path.c_str());
27352738
if (ret != SEEKDB_SUCCESS) {
27362739
const char* err = seekdb_last_error();
@@ -4304,14 +4307,17 @@ TestResult test_stmt_store_result() {
43044307
return {true, ""};
43054308
}
43064309

4307-
int main() {
4310+
int main(int argc, char* argv[]) {
4311+
// Database path: argv[1] if provided, else default relative path (same as other bindings)
4312+
g_db_path = (argc >= 2 && argv[1] && argv[1][0] != '\0') ? argv[1] : "./seekdb.db";
4313+
43084314
std::cout << std::string(70, '=') << std::endl;
43094315
std::cout << "SeekDB C++ Binding Test Suite" << std::endl;
43104316
std::cout << std::string(70, '=') << std::endl;
43114317
std::cout << std::endl;
4312-
4318+
43134319
// Open database once at the beginning
4314-
int ret = seekdb_open("./seekdb.db");
4320+
int ret = seekdb_open(g_db_path);
43154321
if (ret != SEEKDB_SUCCESS) {
43164322
std::cerr << "Failed to open database: " << ret << std::endl;
43174323
return 1;

0 commit comments

Comments
 (0)