mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-05 04:30:38 +03:00
Improvements to ".selftest --init". Tests are number in increments of 10
starting with 100. The tests are generated inside a SAVEPOINT. Errors are reported during test generation. Tests can be appended to existing tests. Add a test case to verify the schema. FossilOrigin-Name: b044b152aac2ec606750940ea816ad4a4aef8eb6
This commit is contained in:
33
src/shell.c
33
src/shell.c
@@ -2073,14 +2073,26 @@ static int captureOutputCallback(void *pArg, int nArg, char **azArg, char **az){
|
||||
** Generate an appropriate SELFTEST table in the main database.
|
||||
*/
|
||||
static void createSelftestTable(ShellState *p){
|
||||
char *zErrMsg = 0;
|
||||
sqlite3_exec(p->db,
|
||||
"CREATE TABLE selftest(\n"
|
||||
"SAVEPOINT selftest_init;\n"
|
||||
"CREATE TABLE IF NOT EXISTS selftest(\n"
|
||||
" tno INTEGER PRIMARY KEY,\n" /* Test number */
|
||||
" op TEXT,\n" /* Operator: memo run */
|
||||
" cmd TEXT,\n" /* Command text */
|
||||
" ans TEXT\n" /* Desired answer */
|
||||
");"
|
||||
"INSERT INTO selftest(op,cmd,ans)\n"
|
||||
"CREATE TEMP TABLE [_shell$self](op,cmd,ans);\n"
|
||||
"INSERT INTO [_shell$self](rowid,op,cmd)\n"
|
||||
" VALUES(coalesce((SELECT (max(tno)+100)/10 FROM selftest),10),\n"
|
||||
" 'memo','Tests generated by --init');\n"
|
||||
"INSERT INTO [_shell$self]\n"
|
||||
" SELECT 'run',\n"
|
||||
" 'SELECT hex(sha3_query(''SELECT type,name,tbl_name,sql "
|
||||
"FROM sqlite_master ORDER BY 2'',224))',\n"
|
||||
" hex(sha3_query('SELECT type,name,tbl_name,sql "
|
||||
"FROM sqlite_master ORDER BY 2',224));\n"
|
||||
"INSERT INTO [_shell$self]\n"
|
||||
" SELECT 'run',"
|
||||
" 'SELECT hex(sha3_query(''SELECT * FROM \"' ||"
|
||||
" printf('%w',name) || '\" NOT INDEXED'',224))',\n"
|
||||
@@ -2092,9 +2104,17 @@ static void createSelftestTable(ShellState *p){
|
||||
" AND coalesce(rootpage,0)>0\n"
|
||||
" )\n"
|
||||
" ORDER BY name;\n"
|
||||
"INSERT INTO selftest(op,cmd,ans)\n"
|
||||
"INSERT INTO [_shell$self]\n"
|
||||
" VALUES('run','PRAGMA integrity_check','ok');\n"
|
||||
,0,0,0);
|
||||
"INSERT INTO selftest(tno,op,cmd,ans)"
|
||||
" SELECT rowid*10,op,cmd,ans FROM [_shell$self];\n"
|
||||
"DROP TABLE [_shell$self];"
|
||||
,0,0,&zErrMsg);
|
||||
if( zErrMsg ){
|
||||
utf8_printf(stderr, "SELFTEST initialization failure: %s\n", zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
}
|
||||
sqlite3_exec(p->db, "RELEASE selftest_init",0,0,0);
|
||||
}
|
||||
|
||||
|
||||
@@ -5813,11 +5833,6 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
bSelftestExists = 1;
|
||||
}
|
||||
if( bIsInit ){
|
||||
if( bSelftestExists ){
|
||||
raw_printf(stderr, "The selftest table already exists\n");
|
||||
rc = 1;
|
||||
goto meta_command_exit;
|
||||
}
|
||||
createSelftestTable(p);
|
||||
bSelftestExists = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user