SQLite

Check-in [9fb7da6904]
Login

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

Overview
Comment:Move the shell test scripts into the test/ subfolder so that they are run automatically by "make test".
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9fb7da6904e479f4671eeebf1a4b7e4e4e4f2b7b
User & Date: drh 2012-04-24 12:46:05.097
Context
2012-04-24
13:14
New test cases for the ".dump" and ".mode insert" commands of the shell. (check-in: dfce856976 user: drh tags: trunk)
12:46
Move the shell test scripts into the test/ subfolder so that they are run automatically by "make test". (check-in: 9fb7da6904 user: drh tags: trunk)
12:12
Fix a sign-extension problem for BLOB output in ".insert" mode of the command-line shell. (check-in: 282f2a74c2 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Name change from tool/shell1.test to test/shell1.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 2009 Nov 11
#
# 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.
#
#***********************************************************************
#
# The focus of this file is testing the CLI shell tool.
#
# $Id: shell1.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
#

# Test plan:
#
#   shell1-1.*: Basic command line option handling.
#   shell1-2.*: Basic "dot" command token parsing.
#   shell1-3.*: Basic test that "dot" command can be called.
#

package require sqlite3

set CLI "./sqlite3"

proc do_test {name cmd expected} {
  puts -nonewline "$name ..."
  set res [uplevel $cmd]
  if {$res eq $expected} {
    puts Ok
  } else {
    puts Error
    puts "  Got: $res"
    puts "  Expected: $expected"
    exit
  }
}

proc execsql {sql} {
  uplevel [list db eval $sql]
}

proc catchsql {sql} {
  set rc [catch {uplevel [list db eval $sql]} msg]
  list $rc $msg
}

proc catchcmd {db {cmd ""}} {
  global CLI
  set out [open cmds.txt w]
  puts $out $cmd
  close $out
  set line "exec $CLI $db < cmds.txt"
  set rc [catch { eval $line } msg]
  list $rc $msg
}

file delete -force test.db test.db.journal
sqlite3 db test.db

#----------------------------------------------------------------------------
# Test cases shell1-1.*: Basic command line option handling.
#

# invalid option













<








|
|
|
|
<
<
<
<
<
<
|
<
<
<
|
|
<
|
<
<
<
|
<
<
|

<
<
<
<
<
|
<
<
<
<
<
|







1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25






26



27
28

29



30


31
32





33





34
35
36
37
38
39
40
41
# 2009 Nov 11
#
# 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.
#
#***********************************************************************
#
# The focus of this file is testing the CLI shell tool.
#

#

# Test plan:
#
#   shell1-1.*: Basic command line option handling.
#   shell1-2.*: Basic "dot" command token parsing.
#   shell1-3.*: Basic test that "dot" command can be called.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {$tcl_platform(platform)=="windows"} {
  set CLI "sqlite3.exe"






} else {



  set CLI "./sqlite3"
}

if {![file executable $CLI]} {



  finish_test


  return
}





db close





forcedelete test.db test.db-journal test.db-wal
sqlite3 db test.db

#----------------------------------------------------------------------------
# Test cases shell1-1.*: Basic command line option handling.
#

# invalid option
713
714
715
716
717
718
719
720
} {1 {Error: unknown command or invalid arguments:  "timer". Enter ".help" for help}}

do_test shell1-3-28.1 {
  catchcmd test.db \
     ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
} "0 {(123) hello\n456}"

puts "CLI tests completed successfully"







|
687
688
689
690
691
692
693
694
} {1 {Error: unknown command or invalid arguments:  "timer". Enter ".help" for help}}

do_test shell1-3-28.1 {
  catchcmd test.db \
     ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
} "0 {(123) hello\n456}"

finish_test
Name change from tool/shell2.test to test/shell2.test.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
#

# Test plan:
#
#   shell2-1.*: Misc. test of various tickets and reported errors.
#

package require sqlite3

set CLI "./sqlite3"

proc do_test {name cmd expected} {
  puts -nonewline "$name ..."
  set res [uplevel $cmd]
  if {$res eq $expected} {
    puts Ok
  } else {
    puts Error
    puts "  Got: $res"
    puts "  Expected: $expected"
    exit
  }
}

proc execsql {sql} {
  uplevel [list db eval $sql]
}

proc catchsql {sql} {
  set rc [catch {uplevel [list db eval $sql]} msg]
  list $rc $msg
}

proc catchcmd {db {cmd ""}} {
  global CLI
  set out [open cmds.txt w]
  puts $out $cmd
  close $out
  set line "exec $CLI $db < cmds.txt"
  set rc [catch { eval $line } msg]
  list $rc $msg
}

file delete -force test.db test.db.journal
sqlite3 db test.db


#----------------------------------------------------------------------------
#   shell2-1.*: Misc. test of various tickets and reported errors.
#








|
|
|
|
<
<
<
<
<
<
|
<
<
<
|
|
<
|
<
<
<
|
<
<
|

<
<
<
<
<
|
<
<
<
<
<
|







14
15
16
17
18
19
20
21
22
23
24






25



26
27

28



29


30
31





32





33
34
35
36
37
38
39
40
# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
#

# Test plan:
#
#   shell2-1.*: Misc. test of various tickets and reported errors.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {$tcl_platform(platform)=="windows"} {
  set CLI "sqlite3.exe"






} else {



  set CLI "./sqlite3"
}

if {![file executable $CLI]} {



  finish_test


  return
}





db close





forcedelete test.db test.db-journal test.db-wal
sqlite3 db test.db


#----------------------------------------------------------------------------
#   shell2-1.*: Misc. test of various tickets and reported errors.
#

215
216
217
218
219
220
221
222
1
2
SELECT * FROM foo2;
b
1
2}}

puts "CLI tests completed successfully"







|
190
191
192
193
194
195
196
197
1
2
SELECT * FROM foo2;
b
1
2}}

finish_test
Name change from tool/shell3.test to test/shell3.test.
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#

# Test plan:
#
#   shell3-1.*: Basic tests for running SQL statments from command line.
#   shell3-2.*: Basic tests for running SQL file from command line.
#

package require sqlite3

set CLI "./sqlite3"

proc do_test {name cmd expected} {
  puts -nonewline "$name ..."
  set res [uplevel $cmd]
  if {$res eq $expected} {
    puts Ok
  } else {
    puts Error
    puts "  Got: $res"
    puts "  Expected: $expected"
    exit
  }
}

proc execsql {sql} {
  uplevel [list db eval $sql]
}

proc catchsql {sql} {
  set rc [catch {uplevel [list db eval $sql]} msg]
  list $rc $msg
}

proc catchcmd {db {cmd ""}} {
  global CLI
  set out [open cmds.txt w]
  puts $out $cmd
  close $out
  set line "exec $CLI $db < cmds.txt"
  set rc [catch { eval $line } msg]
  list $rc $msg
}

file delete -force test.db test.db.journal
sqlite3 db test.db


#----------------------------------------------------------------------------
#   shell3-1.*: Basic tests for running SQL statments from command line.
#

# Run SQL statement from command line
do_test shell3-1.1 {







|
|
|
|
<
<
<
<
<
<
|
<
<
<
|
|
<
|
<
<
<
|
<
<
|

<
<
<
<
<
|
<
<
<
<
<
|

<







15
16
17
18
19
20
21
22
23
24
25






26



27
28

29



30


31
32





33





34
35

36
37
38
39
40
41
42
#

# Test plan:
#
#   shell3-1.*: Basic tests for running SQL statments from command line.
#   shell3-2.*: Basic tests for running SQL file from command line.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {$tcl_platform(platform)=="windows"} {
  set CLI "sqlite3.exe"






} else {



  set CLI "./sqlite3"
}

if {![file executable $CLI]} {



  finish_test


  return
}





db close





forcedelete test.db test.db-journal test.db-wal
sqlite3 db test.db


#----------------------------------------------------------------------------
#   shell3-1.*: Basic tests for running SQL statments from command line.
#

# Run SQL statement from command line
do_test shell3-1.1 {
116
117
118
119
120
121
122
123
124
do_test shell3-2.6 {
  catchcmd "foo.db" ".tables"
} {0 {}}
do_test shell3-2.7 {
  catchcmd "foo.db" "CREATE TABLE"
} {1 {Error: incomplete SQL: CREATE TABLE}}


puts "CLI tests completed successfully"







|
<
90
91
92
93
94
95
96
97

do_test shell3-2.6 {
  catchcmd "foo.db" ".tables"
} {0 {}}
do_test shell3-2.7 {
  catchcmd "foo.db" "CREATE TABLE"
} {1 {Error: incomplete SQL: CREATE TABLE}}

finish_test

Name change from tool/shell4.test to test/shell4.test.
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
# $Id: shell4.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
#

# Test plan:
#
#   shell4-1.*: Basic tests specific to the "stats" command.
#

set CLI "./sqlite3"

proc do_test {name cmd expected} {
  puts -nonewline "$name ..."
  set res [uplevel $cmd]
  if {$res eq $expected} {
    puts Ok
  } else {
    puts Error
    puts "  Got: $res"
    puts "  Expected: $expected"
    exit
  }
}

proc catchcmd {db {cmd ""}} {
  global CLI
  set out [open cmds.txt w]
  puts $out $cmd
  close $out
  set line "exec $CLI $db < cmds.txt"
  set rc [catch { eval $line } msg]
  list $rc $msg
}

file delete -force test.db test.db.journal


#----------------------------------------------------------------------------
# Test cases shell4-1.*: Tests specific to the "stats" command.
#

# should default to off
do_test shell4-1.1.1 {







|
|
|
<
<
|
<
<
|
<
<
<
|
|
<
|
<
<
<
<
|
<
<
|

|
|
>







15
16
17
18
19
20
21
22
23
24


25


26



27
28

29




30


31
32
33
34
35
36
37
38
39
40
41
42
# $Id: shell4.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
#

# Test plan:
#
#   shell4-1.*: Basic tests specific to the "stats" command.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {$tcl_platform(platform)=="windows"} {


  set CLI "sqlite3.exe"


} else {



  set CLI "./sqlite3"
}

if {![file executable $CLI]} {




  finish_test


  return
}
db close
forcedelete test.db test.db-journal test.db-wal
sqlite3 db test.db

#----------------------------------------------------------------------------
# Test cases shell4-1.*: Tests specific to the "stats" command.
#

# should default to off
do_test shell4-1.1.1 {
122
123
124
125
126
127
128
129
SELECT 1;
}]
  list [regexp {Memory Used} $res] \
       [regexp {Heap Usage} $res] \
       [regexp {Autoindex Inserts} $res]
} {1 1 1}

puts "CLI tests completed successfully"







|
109
110
111
112
113
114
115
116
SELECT 1;
}]
  list [regexp {Memory Used} $res] \
       [regexp {Heap Usage} $res] \
       [regexp {Autoindex Inserts} $res]
} {1 1 1}

finish_test
Name change from tool/shell5.test to test/shell5.test.
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
# $Id: shell5.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
#

# Test plan:
#
#   shell5-1.*: Basic tests specific to the ".import" command.
#

set CLI "./sqlite3"

proc do_test {name cmd expected} {
  puts -nonewline "$name ..."
  set res [uplevel $cmd]
  if {$res eq $expected} {
    puts Ok
  } else {
    puts Error
    puts "  Got: $res"
    puts "  Expected: $expected"
    exit
  }
}

proc catchcmd {db {cmd ""}} {
  global CLI
  set out [open cmds.txt w]
  puts $out $cmd
  close $out
  set line "exec $CLI $db < cmds.txt"
  set rc [catch { eval $line } msg]
  list $rc $msg
}

file delete -force test.db test.db.journal


#----------------------------------------------------------------------------
# Test cases shell5-1.*: Basic handling of the .import and .separator commands.
#

# .import FILE TABLE     Import data from FILE into TABLE
do_test shell5-1.1.1 {







|
|
|
<
<
|
<
<
|
<
<
<
|
|
<
|
<
<
<
<
|
<
<
|

|
|
>







15
16
17
18
19
20
21
22
23
24


25


26



27
28

29




30


31
32
33
34
35
36
37
38
39
40
41
42
# $Id: shell5.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
#

# Test plan:
#
#   shell5-1.*: Basic tests specific to the ".import" command.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {$tcl_platform(platform)=="windows"} {


  set CLI "sqlite3.exe"


} else {



  set CLI "./sqlite3"
}

if {![file executable $CLI]} {




  finish_test


  return
}
db close
forcedelete test.db test.db-journal test.db-wal
sqlite3 db test.db

#----------------------------------------------------------------------------
# Test cases shell5-1.*: Basic handling of the .import and .separator commands.
#

# .import FILE TABLE     Import data from FILE into TABLE
do_test shell5-1.1.1 {
235
236
237
238
239
240
241
242
243
  }
  close $in
  set res [catchcmd "test.db" {CREATE TABLE t3(a);
.import shell5.csv t3
SELECT COUNT(*) FROM t3;}]
} [list 0 $rows]


puts "CLI tests completed successfully"







|
<
222
223
224
225
226
227
228
229

  }
  close $in
  set res [catchcmd "test.db" {CREATE TABLE t3(a);
.import shell5.csv t3
SELECT COUNT(*) FROM t3;}]
} [list 0 $rows]

finish_test

Changes to test/tester.tcl.
513
514
515
516
517
518
519










520
521
522
523
524
525
526
    }
  } else {
    puts " Omitted"
    omit_test $name "pattern mismatch" 0
  }
  flush stdout
}











proc filepath_normalize {p} {
  # test cases should be written to assume "unix"-like file paths
  if {$::tcl_platform(platform)!="unix"} {
    # lreverse*2 as a hack to remove any unneeded {} after the string map
    lreverse [lreverse [string map {\\ /} [regsub -nocase -all {[a-z]:[/\\]+} $p {/}]]]
  } {







>
>
>
>
>
>
>
>
>
>







513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
    }
  } else {
    puts " Omitted"
    omit_test $name "pattern mismatch" 0
  }
  flush stdout
}

proc catchcmd {db {cmd ""}} {
  global CLI
  set out [open cmds.txt w]
  puts $out $cmd
  close $out
  set line "exec $CLI $db < cmds.txt"
  set rc [catch { eval $line } msg]
  list $rc $msg
}

proc filepath_normalize {p} {
  # test cases should be written to assume "unix"-like file paths
  if {$::tcl_platform(platform)!="unix"} {
    # lreverse*2 as a hack to remove any unneeded {} after the string map
    lreverse [lreverse [string map {\\ /} [regsub -nocase -all {[a-z]:[/\\]+} $p {/}]]]
  } {