/ Check-in [792afefa]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:In the shell, make ".testcase" and ".check" available in all configurations, not just SQLITE_DEBUG. All testcases to be named. Show the result of each testcase on stdout.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 792afefa9c750910082fd102f1ccd10309759dfc
User & Date: drh 2016-09-16 02:52:22
Context
2016-09-16
11:53
Fix SQLITE_OMIT_AUTHORIZATION so that it compiles cleanly. check-in: a3e3b3e1 user: drh tags: trunk
02:52
In the shell, make ".testcase" and ".check" available in all configurations, not just SQLITE_DEBUG. All testcases to be named. Show the result of each testcase on stdout. check-in: 792afefa user: drh tags: trunk
00:26
In the command-line shell, add the --new option to the ".open" command. Also, report the current database filename as part of the ".show" command. check-in: 8e5c9203 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

   622    622     FILE *traceOut;        /* Output for sqlite3_trace() */
   623    623     int nErr;              /* Number of errors seen */
   624    624     int mode;              /* An output mode setting */
   625    625     int cMode;             /* temporary output mode for the current query */
   626    626     int normalMode;        /* Output mode before ".explain on" */
   627    627     int writableSchema;    /* True if PRAGMA writable_schema=ON */
   628    628     int showHeader;        /* True to show column names in List or Column mode */
          629  +  int nCheck;            /* Number of ".check" commands run */
   629    630     unsigned shellFlgs;    /* Various flags */
   630    631     char *zDestTable;      /* Name of destination table when MODE_Insert */
          632  +  char zTestcase[30];    /* Name of current test case */
   631    633     char colSeparator[20]; /* Column separator character for several modes */
   632    634     char rowSeparator[20]; /* Row separator character for MODE_Ascii */
   633    635     int colWidth[100];     /* Requested width of each column when in column mode*/
   634    636     int actualWidth[100];  /* Actual width of each column */
   635    637     char nullValue[20];    /* The text to print when a NULL comes back from
   636    638                            ** the database */
   637    639     char outfile[FILENAME_MAX]; /* Filename for *out */
................................................................................
  2132   2134   */
  2133   2135   static char zHelp[] =
  2134   2136     ".auth ON|OFF           Show authorizer callbacks\n"
  2135   2137     ".backup ?DB? FILE      Backup DB (default \"main\") to FILE\n"
  2136   2138     ".bail on|off           Stop after hitting an error.  Default OFF\n"
  2137   2139     ".binary on|off         Turn binary output on or off.  Default OFF\n"
  2138   2140     ".changes on|off        Show number of rows changed by SQL\n"
  2139         -#ifdef SQLITE_DEBUG
  2140   2141     ".check GLOB            Fail if output since .testcase does not match\n"
  2141         -#endif
  2142   2142     ".clone NEWDB           Clone data into NEWDB from the existing database\n"
  2143   2143     ".databases             List names and files of attached databases\n"
  2144   2144     ".dbinfo ?DB?           Show status information about the database\n"
  2145   2145     ".dump ?TABLE? ...      Dump the database in an SQL text format\n"
  2146   2146     "                         If TABLE specified, only dump tables matching\n"
  2147   2147     "                         LIKE pattern TABLE.\n"
  2148   2148     ".echo on|off           Turn command echo on or off\n"
................................................................................
  2196   2196     ".shell CMD ARGS...     Run CMD ARGS... in a system shell\n"
  2197   2197     ".show                  Show the current values for various settings\n"
  2198   2198     ".stats ?on|off?        Show stats or turn stats on or off\n"
  2199   2199     ".system CMD ARGS...    Run CMD ARGS... in a system shell\n"
  2200   2200     ".tables ?TABLE?        List names of tables\n"
  2201   2201     "                         If TABLE specified, only list tables matching\n"
  2202   2202     "                         LIKE pattern TABLE.\n"
  2203         -#ifdef SQLITE_DEBUG
  2204         -  ".testcase              Begin redirecting output to 'testcase-out.txt'\n"
  2205         -#endif
         2203  +  ".testcase NAME         Begin redirecting output to 'testcase-out.txt'\n"
  2206   2204     ".timeout MS            Try opening locked tables for MS milliseconds\n"
  2207   2205     ".timer on|off          Turn SQL timer on or off\n"
  2208   2206     ".trace FILE|off        Output each SQL statement as it is run\n"
  2209   2207     ".vfsinfo ?AUX?         Information about the top-level VFS\n"
  2210   2208     ".vfslist               List all available VFSes\n"
  2211   2209     ".vfsname ?AUX?         Print the name of the VFS stack\n"
  2212   2210     ".width NUM1 NUM2 ...   Set column widths for \"column\" mode\n"
................................................................................
  3356   3354         p->countChanges = booleanValue(azArg[1]);
  3357   3355       }else{
  3358   3356         raw_printf(stderr, "Usage: .changes on|off\n");
  3359   3357         rc = 1;
  3360   3358       }
  3361   3359     }else
  3362   3360   
  3363         -#ifdef SQLITE_DEBUG
  3364   3361     /* Cancel output redirection, if it is currently set (by .testcase)
  3365   3362     ** Then read the content of the testcase-out.txt file and compare against
  3366   3363     ** azArg[1].  If there are differences, report an error and exit.
  3367   3364     */
  3368   3365     if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
  3369   3366       char *zRes = 0;
  3370   3367       output_reset(p);
  3371   3368       if( nArg!=2 ){
  3372   3369         raw_printf(stderr, "Usage: .check GLOB-PATTERN\n");
  3373         -      rc = 1;
         3370  +      rc = 2;
  3374   3371       }else if( (zRes = readFile("testcase-out.txt"))==0 ){
  3375   3372         raw_printf(stderr, "Error: cannot read 'testcase-out.txt'\n");
  3376   3373         rc = 2;
  3377   3374       }else if( testcase_glob(azArg[1],zRes)==0 ){
  3378         -      raw_printf(stderr, ".check failed\n Expected: [%s]\n      Got: [%s]\n",
  3379         -                 azArg[1], zRes);
         3375  +      raw_printf(stderr,
         3376  +                 "testcase-%s FAILED\n Expected: [%s]\n      Got: [%s]\n",
         3377  +                 p->zTestcase, azArg[1], zRes);
  3380   3378         rc = 2;
         3379  +    }else{
         3380  +      raw_printf(stdout, "testcase-%s ok\n", p->zTestcase);
         3381  +      p->nCheck++;
  3381   3382       }
  3382   3383       sqlite3_free(zRes);
  3383   3384     }else
  3384         -#endif
  3385   3385   
  3386   3386     if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
  3387   3387       if( nArg==2 ){
  3388   3388         tryToClone(p, azArg[1]);
  3389   3389       }else{
  3390   3390         raw_printf(stderr, "Usage: .clone FILENAME\n");
  3391   3391         rc = 1;
................................................................................
  3989   3989         rc = 1;
  3990   3990       }
  3991   3991     }else
  3992   3992   
  3993   3993     if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
  3994   3994       char *zNewFilename;  /* Name of the database file to open */
  3995   3995       int iName = 1;       /* Index in azArg[] of the filename */
         3996  +    int newFlag = 0;     /* True to delete file before opening */
  3996   3997       /* Close the existing database */
  3997   3998       session_close_all(p);
  3998   3999       sqlite3_close(p->db);
  3999   4000       p->db = 0;
  4000   4001       sqlite3_free(p->zFreeOnClose);
  4001   4002       p->zFreeOnClose = 0;
  4002         -    /* Start a new database file if the --new flag is present */
  4003         -    if( nArg>2 && optionMatch(azArg[1],"new") ){
  4004         -      iName++;
  4005         -      if( nArg>iName ) shellDeleteFile(azArg[iName]);
         4003  +    /* Check for command-line arguments */
         4004  +    for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
         4005  +      const char *z = azArg[iName];
         4006  +      if( optionMatch(z,"new") ){
         4007  +        newFlag = 1;
         4008  +      }else if( z[0]=='-' ){
         4009  +        utf8_printf(stderr, "unknown option: %s\n", z);
         4010  +        rc = 1;
         4011  +      }
  4006   4012       }
  4007   4013       /* If a filename is specified, try to open it first */
  4008   4014       zNewFilename = nArg>iName ? sqlite3_mprintf("%s", azArg[iName]) : 0;
  4009   4015       if( zNewFilename ){
         4016  +      if( newFlag ) shellDeleteFile(zNewFilename);
  4010   4017         p->zDbFilename = zNewFilename;
  4011   4018         open_db(p, 1);
  4012   4019         if( p->db==0 ){
  4013   4020           utf8_printf(stderr, "Error: cannot open '%s'\n", zNewFilename);
  4014   4021           sqlite3_free(zNewFilename);
  4015   4022         }else{
  4016   4023           p->zFreeOnClose = zNewFilename;
................................................................................
  4664   4671         }
  4665   4672       }
  4666   4673   
  4667   4674       for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
  4668   4675       sqlite3_free(azResult);
  4669   4676     }else
  4670   4677   
  4671         -#ifdef SQLITE_DEBUG
  4672   4678     /* Begin redirecting output to the file "testcase-out.txt" */
  4673   4679     if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
  4674   4680       output_reset(p);
  4675   4681       p->out = output_file_open("testcase-out.txt");
  4676   4682       if( p->out==0 ){
  4677   4683         utf8_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
  4678   4684       }
         4685  +    if( nArg>=2 ){
         4686  +      sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
         4687  +    }else{
         4688  +      sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
         4689  +    }
  4679   4690     }else
  4680         -#endif
  4681   4691   
  4682   4692     if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
  4683   4693       static const struct {
  4684   4694          const char *zCtrlName;   /* Name of a test-control option */
  4685   4695          int ctrlCode;            /* Integer code for that option */
  4686   4696       } aCtrl[] = {
  4687   4697         { "prng_save",             SQLITE_TESTCTRL_PRNG_SAVE              },