Skip to content

Commit 1cc114b

Browse files
authored
Merge pull request #5 from sqliteai/ci-integration-test
run integration test in the ci
2 parents cd10ac0 + c61fbb8 commit 1cc114b

File tree

5 files changed

+32
-347
lines changed

5 files changed

+32
-347
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ jobs:
8787
echo "::endgroup::"
8888
8989
echo "::group::prepare the test script"
90+
make test CC=$CC PLATFORM=$PLATFORM || echo "It should fail. Running remaining commands in the emulator"
9091
cat > commands.sh << EOF
9192
mv -f /data/local/tmp/sqlite3 /system/xbin
9293
cd /data/local/tmp
93-
$(make test -n)
94+
$(make test CC=$CC PLATFORM=$PLATFORM -n)
9495
EOF
9596
echo "::endgroup::"
9697

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
*.plist
66
/build
77
/dist
8+
*.sqlite

Makefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ CFLAGS := -Wall -Wextra -fPIC -g -O2 -DQJS_BUILD_LIBC $(INCLUDES)
3333
ifeq ($(PLATFORM),windows)
3434
TARGET := $(DIST_DIR)/js.dll
3535
LDFLAGS := -shared
36-
# Windows-specific flags
37-
CFLAGS += -D_WIN32
3836
# Create .def file for Windows
3937
DEF_FILE := $(BUILD_DIR)/js.def
4038
else ifeq ($(PLATFORM),macos)
@@ -99,6 +97,8 @@ ifeq ($(PLATFORM),windows)
9997
@echo "LIBRARY js.dll" > $@
10098
@echo "EXPORTS" >> $@
10199
@echo " sqlite3_js_init" >> $@
100+
@echo " sqlitejs_version" >> $@
101+
@echo " quickjs_version" >> $@
102102
endif
103103

104104
# Clean up
@@ -119,9 +119,24 @@ else # linux
119119
cp $(TARGET) $(DESTDIR)/usr/local/lib/sqlite3/
120120
endif
121121

122+
# Test source files
123+
TEST_FILES := test/main.c
124+
125+
# Test target files
126+
ifeq ($(PLATFORM),windows)
127+
TEST_TARGET := $(patsubst %.c,$(DIST_DIR)/%.exe,$(notdir $(TEST_FILES)))
128+
else
129+
TEST_TARGET := $(patsubst %.c,$(DIST_DIR)/%,$(notdir $(TEST_FILES)))
130+
endif
131+
132+
# Compile test target
133+
$(TEST_TARGET): $(TEST_FILES) $(TARGET)
134+
$(CC) $(INCLUDES) $^ -lm -o $@ libs/sqlite3.c -DSQLITE_CORE
135+
122136
# Testing the extension
123-
test: $(TARGET)
124-
sqlite3 ":memory:" -cmd ".bail on" ".load ./$(TARGET)" "SELECT js_eval('console.log(\"hello, world\nToday is\", new Date().toLocaleDateString())');"
137+
test: $(TARGET) $(TEST_TARGET)
138+
sqlite3 ":memory:" -cmd ".bail on" ".load ./$<" "SELECT js_eval('console.log(\"hello, world\nToday is\", new Date().toLocaleDateString())');"
139+
./$(TEST_TARGET)
125140

126141
# Help message
127142
help:
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <stdio.h>
99
#include "sqlite3.h"
10-
#include "quickjs.h"
1110
#include "sqlitejs.h"
1211

1312
#define DB_PATH "js_functions.sqlite"
@@ -33,8 +32,11 @@ int test_serialization (const char *db_path, bool load_functions, int nstep) {
3332
int rc = sqlite3_open(db_path, &db);
3433
if (rc != SQLITE_OK) goto abort_test;
3534

36-
// manually load extension
37-
rc = sqlite3_js_init(db, NULL, NULL);
35+
// enable load extension
36+
rc = sqlite3_enable_load_extension(db, 1);
37+
if (rc != SQLITE_OK) goto abort_test;
38+
39+
rc = db_exec(db, "SELECT load_extension('./dist/js');");
3840
if (rc != SQLITE_OK) goto abort_test;
3941

4042
rc = db_exec(db, (load_functions) ? "SELECT js_init_table(1);" : "SELECT js_init_table();");
@@ -67,8 +69,11 @@ int test_execution (void) {
6769
int rc = sqlite3_open(":memory:", &db);
6870
if (rc != SQLITE_OK) goto abort_test;
6971

70-
// manually load extension
71-
rc = sqlite3_js_init(db, NULL, NULL);
72+
// enable load extension
73+
rc = sqlite3_enable_load_extension(db, 1);
74+
if (rc != SQLITE_OK) goto abort_test;
75+
76+
rc = db_exec(db, "SELECT load_extension('./dist/js');");
7277
if (rc != SQLITE_OK) goto abort_test;
7378

7479
// context

0 commit comments

Comments
 (0)