Adding the sqlite sourcecode

This commit is contained in:
Jiří Stach committed 2025-07-17 11:54:48 +02:00
1 parent bdb54a1f8f
commit 406b584760
2208 files changed
+1172785 -1

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
#!/this/is/make
#
# This makefile compiles SQLTester test files into something
# we can readily import into JavaScript.
all:
SHELL := $(shell which bash 2>/dev/null)
MAKEFILE := $(lastword $(MAKEFILE_LIST))
CLEAN_FILES :=
DISTCLEAN_FILES := ./--dummy-- *~
test-list.mjs := test-list.mjs
test-list.mjs.gz := $(test-list.mjs).gz
CLEAN_FILES += $(test-list.mjs)
tests.dir := $(firstword $(wildcard tests ../../jni/src/tests))
$(info test script dir=$(tests.dir))
tests.all := $(wildcard $(tests.dir)/*.test)
bin.touint8array := ./touint8array
$(bin.touint8array): $(bin.touint8array).c $(MAKEFILE)
$(CC) -o $@ $<
CLEAN_FILES += $(bin.touint8array)
ifneq (,$(tests.all))
$(test-list.mjs): $(bin.touint8array) $(tests.all) $(MAKEFILE)
@{\
echo 'export default ['; \
sep=''; \
for f in $(sort $(tests.all)); do \
echo -en $$sep'{"name": "'$${f##*/}'", "content":'; \
$(bin.touint8array) < $$f; \
echo -n '}'; \
sep=',\n'; \
done; \
echo '];'; \
} > $@
@echo "Created $@"
$(test-list.mjs.gz): $(test-list.mjs)
gzip -c $< > $@
CLEAN_FILES += $(test-list.mjs.gz)
all: $(test-list.mjs.gz)
else
@echo "Cannot build $(test-list.mjs) for lack of input test files."; \
echo "Symlink ./tests to a directory containing SQLTester-format "; \
echo "test scripts named *.test, then try again"; \
exit 1
endif
.PHONY: clean distclean
clean:
-rm -f $(CLEAN_FILES)
distclean: clean
-rm -f $(DISTCLEAN_FILES)
File diff suppressed because it is too large. Load diff
+151
View File
@@ -0,0 +1,151 @@
/*
** 2023-08-29
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains a test application for SQLTester.mjs. It loads
** test scripts and runs them through the SQLTester class.
*/
import {default as ns} from './SQLTester.mjs';
import {default as allTests} from './test-list.mjs';
globalThis.sqlite3 = ns.sqlite3;
const log = function f(...args){
console.log('SQLTester.run:',...args);
return f;
};
const out = function f(...args){ return f.outer.out(...args) };
out.outer = new ns.Outer();
out.outer.getOutputPrefix = ()=>'SQLTester.run: ';
const outln = (...args)=>{ return out.outer.outln(...args) };
const affirm = function(expr, msg){
if( !expr ){
throw new Error(arguments[1]
? ("Assertion failed: "+arguments[1])
: "Assertion failed");
}
}
let ts = new ns.TestScript('SQLTester-sanity-check.test',`
/*
** This is a comment. There are many like it but this one is mine.
**
** SCRIPT_MODULE_NAME: sanity-check-0
** xMIXED_MODULE_NAME: mixed-module
** xMODULE_NAME: module-name
** xREQUIRED_PROPERTIES: small fast reliable
** xREQUIRED_PROPERTIES: RECURSIVE_TRIGGERS
** xREQUIRED_PROPERTIES: TEMPSTORE_FILE TEMPSTORE_MEM
** xREQUIRED_PROPERTIES: AUTOVACUUM INCRVACUUM
**
*/
/* --verbosity 3 */
/* ---must-fail */
/* # must fail */
/* --verbosity 0 */
--print Hello, world.
--close all
--oom
--db 0
--new my.db
--null zilch
--testcase 1.0
SELECT 1, null;
--result 1 zilch
--glob *zil*
--notglob *ZIL*
SELECT 1, 2;
intentional error;
--run
/* ---intentional-failure */
--testcase json-1
SELECT json_array(1,2,3)
--json [1,2,3]
--testcase tableresult-1
select 1, 'a' UNION
select 2, 'b' UNION
select 3, 'c' ORDER by 1
--tableresult
# [a-z]
2 b
3 c
--end
--testcase json-block-1
select json_array(1,2,3);
select json_object('a',1,'b',2);
--json-block
[1,2,3]
{"a":1,"b":2}
--end
--testcase col-names-on
--column-names 1
select 1 as 'a', 2 as 'b';
--result a 1 b 2
--testcase col-names-off
--column-names 0
select 1 as 'a', 2 as 'b';
--result 1 2
--close
--testcase the-end
--print Until next time
`);
const sqt = new ns.SQLTester()
.setLogger(console.log.bind(console))
.verbosity(1)
.addTestScript(ts);
sqt.outer().outputPrefix('');
const runTests = function(){
try{
if( 0 ){
affirm( !sqt.getCurrentDb(), 'sqt.getCurrentDb()' );
sqt.openDb('/foo.db', true);
affirm( !!sqt.getCurrentDb(),'sqt.getCurrentDb()' );
affirm( 'zilch' !== sqt.nullValue() );
ts.run(sqt);
affirm( 'zilch' === sqt.nullValue() );
sqt.addTestScript(ts);
}else{
for(const t of allTests){
sqt.addTestScript( new ns.TestScript(t) );
}
allTests.length = 0;
}
sqt.runTests();
}finally{
//log( "Metrics:", sqt.metrics );
sqt.reset();
}
};
if( globalThis.WorkerGlobalScope ){
const wPost = (type,payload)=>globalThis.postMessage({type, payload});
globalThis.onmessage = function({data}){
switch(data.type){
case 'run-tests':{
try{ runTests(); }
finally{ wPost('tests-end', sqt.metrics); }
break;
}
default:
log("unhandled onmessage: ",data);
break;
}
};
sqt.setLogger((msg)=>{
wPost('stdout', {message: msg});
});
wPost('is-ready');
//globalThis.onmessage({data:{type:'run-tests'}});
}else{
runTests();
}
+125
View File
@@ -0,0 +1,125 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<!--link rel="stylesheet" href="../common/emscripten.css"/-->
<link rel="stylesheet" href="../common/testing.css"/>
<title>SQLTester</title>
</head>
<style>
fieldset {
display: flex;
flex-direction: row;
padding-right: 1em;
}
fieldset > :not(.legend) {
display: flex;
flex-direction: row;
padding-right: 1em;
}
</style>
<body>
<h1>SQLTester for JS/WASM</h1>
<p>This app reads in a build-time-defined set of SQLTester test
scripts and runs them through the test suite.
</p>
<fieldset>
<legend>Options</legend>
<span class='input-wrapper'>
<input type='checkbox' id='cb-log-reverse' checked>
<label for='cb-log-reverse'>Reverse log order?</label>
</span>
<input type='button' id='btn-run-tests' value='Run tests'/>
</fieldset>
<div id='test-output'>Test output will go here.</div>
<!--script src='SQLTester.run.mjs' type='module'></script-->
<script>
(async function(){
const W = new Worker('SQLTester.run.mjs',{
type: 'module'
});
const wPost = (type,payload)=>W.postMessage({type,payload});
const mapToString = (v)=>{
switch(typeof v){
case 'string': return v;
case 'number': case 'boolean':
case 'undefined': case 'bigint':
return ''+v;
default: break;
}
if(null===v) return 'null';
if(v instanceof Error){
v = {
message: v.message,
stack: v.stack,
errorClass: v.name
};
}
return JSON.stringify(v,undefined,2);
};
const normalizeArgs = (args)=>args.map(mapToString);
const logTarget = document.querySelector('#test-output');
const logClass = function(cssClass,...args){
const ln = document.createElement('div');
if(cssClass){
for(const c of (Array.isArray(cssClass) ? cssClass : [cssClass])){
ln.classList.add(c);
}
}
ln.append(document.createTextNode(normalizeArgs(args).join(' ')));
logTarget.append(ln);
};
{
const cbReverse = document.querySelector('#cb-log-reverse');
const cbReverseKey = 'SQLTester:cb-log-reverse';
const cbReverseIt = ()=>{
logTarget.classList[cbReverse.checked ? 'add' : 'remove']('reverse');
};
cbReverse.addEventListener('change', cbReverseIt, true);
cbReverseIt();
}
const btnRun = document.querySelector('#btn-run-tests');
const runTests = ()=>{
btnRun.setAttribute('disabled','disabled');
wPost('run-tests');
logTarget.innerText = 'Running tests...';
}
btnRun.addEventListener('click', runTests);
const log2 = function f(...args){
logClass('', ...args);
return f;
};
const log = function f(...args){
logClass('','index.html:',...args);
return f;
};
const timerId = setTimeout( ()=>{
logClass('error',"The SQLTester module is taking an unusually ",
"long time to load. More information may be available",
"in the dev console.");
}, 3000 /* assuming localhost */ );
W.onmessage = function({data}){
switch(data.type){
case 'stdout': log2(data.payload.message); break;
case 'tests-end':
btnRun.removeAttribute('disabled');
delete data.payload.nTest;
log("test results:",data.payload);
break;
case 'is-ready':
clearTimeout(timerId);
runTests(); break;
default:
log("unhandled onmessage",data);
break;
}
};
})();
</script>
</body>
</html>
+29
View File
@@ -0,0 +1,29 @@
/*
** 2023-08-29
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains a tool for writing out the contents of stdin as
** a comma-separated list of numbers, one per byte.
*/
#include <stdio.h>
int main(int argc, char const **argv){
int i;
int rc = 0, colWidth = 30;
int ch;
printf("[");
for( i=0; EOF!=(ch = fgetc(stdin)); ++i ){
if( 0!=i ) printf(",");
if( i && 0==(i%colWidth) ) puts("");
printf("%d",ch);
}
printf("]");
return rc;
}