4 The author disclaims copyright to this source code. In place of a
5 legal notice, here is a blessing:
7 * May you do good and not evil.
8 * May you find forgiveness for yourself and forgive others.
9 * May you share freely, never taking more than you give.
11 ***********************************************************************
13 This file contains bootstrapping code used by various test scripts
14 which live in this file's directory.
17 /* querySelectorAll() proxy */
18 const EAll = function(/*[element=document,] cssSelector*/){
19 return (arguments
.length
>1 ? arguments
[0] : document
)
20 .querySelectorAll(arguments
[arguments
.length
-1]);
22 /* querySelector() proxy */
23 const E = function(/*[element=document,] cssSelector*/){
24 return (arguments
.length
>1 ? arguments
[0] : document
)
25 .querySelector(arguments
[arguments
.length
-1]);
29 Helpers for writing sqlite3-specific tests.
31 self
/*window or worker*/.SqliteTestUtil
= {
32 /** Running total of the number of tests run via
36 If expr is a function, it is called and its result
37 is returned, coerced to a bool, else expr, coerced to
40 toBool: function(expr
){
41 return (expr
instanceof Function
) ? !!expr() : !!expr
;
43 /** abort() if expr is false. If expr is a function, it
44 is called and its result is evaluated.
46 assert
: function f(expr
, msg
){
48 f
._
= ('undefined'===typeof abort
49 ? (msg
)=>{throw new Error(msg
)}
53 if(!this.toBool(expr
)){
54 f
._(msg
|| "Assertion failed.");
58 /** Identical to assert() but throws instead of calling
60 affirm: function(expr
, msg
){
62 if(!this.toBool(expr
)) throw new Error(msg
|| "Affirmation failed.");
65 /** Calls f() and squelches any exception it throws. If it
66 does not throw, this function throws. */
67 mustThrow: function(f
, msg
){
70 try{ f(); } catch(e
){err
=e
;}
71 if(!err
) throw new Error(msg
|| "Expected exception.");
74 /** Throws if expr is truthy or expr is a function and expr()
76 throwIf: function(expr
, msg
){
78 if(this.toBool(expr
)) throw new Error(msg
|| "throwIf() failed");
81 /** Throws if expr is falsy or expr is a function and expr()
83 throwUnless: function(expr
, msg
){
85 if(!this.toBool(expr
)) throw new Error(msg
|| "throwUnless() failed");
92 This is a module object for use with the emscripten-installed
93 initSqlite3Module() factory function.
95 self
.sqlite3TestModule
= {
97 /* function(theModule){...} */
99 //onRuntimeInitialized: function(){},
100 /* Proxy for C-side stdout output. */
102 console
.log
.apply(console
, Array
.prototype.slice
.call(arguments
));
104 /* Proxy for C-side stderr output. */
105 printErr: function(){
106 console
.error
.apply(console
, Array
.prototype.slice
.call(arguments
));
109 Called by the module init bits to report loading
110 progress. It gets passed an empty argument when loading is
111 done (after onRuntimeInitialized() and any this.postRun
112 callbacks have been run).
114 setStatus
: function f(text
){
116 f
.last
= { text
: '', step
: 0 };
118 status
: E('#module-status'),
119 progress
: E('#module-progress'),
120 spinner
: E('#module-spinner')
123 if(text
=== f
.last
.text
) return;
126 f
.ui
.progress
.value
= f
.last
.step
;
127 f
.ui
.progress
.max
= f
.last
.step
+ 1;
131 f
.ui
.status
.classList
.remove('hidden');
132 f
.ui
.status
.innerText
= text
;
135 f
.ui
.progress
.remove();
136 f
.ui
.spinner
.remove();
137 delete f
.ui
.progress
;
140 f
.ui
.status
.classList
.add('hidden');
144 })(self
/*window or worker*/);