shell3.test 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # 2009 Dec 16
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. #
  12. # The focus of this file is testing the CLI shell tool.
  13. #
  14. # $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
  15. #
  16. # Test plan:
  17. #
  18. # shell3-1.*: Basic tests for running SQL statments from command line.
  19. # shell3-2.*: Basic tests for running SQL file from command line.
  20. #
  21. set testdir [file dirname $argv0]
  22. source $testdir/tester.tcl
  23. if {$tcl_platform(platform)=="windows"} {
  24. set CLI "sqlite3.exe"
  25. } else {
  26. set CLI "./sqlite3"
  27. }
  28. if {![file executable $CLI]} {
  29. finish_test
  30. return
  31. }
  32. db close
  33. forcedelete test.db test.db-journal test.db-wal
  34. sqlite3 db test.db
  35. #----------------------------------------------------------------------------
  36. # shell3-1.*: Basic tests for running SQL statments from command line.
  37. #
  38. # Run SQL statement from command line
  39. do_test shell3-1.1 {
  40. forcedelete foo.db
  41. set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
  42. set fexist [file exist foo.db]
  43. list $rc $fexist
  44. } {{0 {}} 1}
  45. do_test shell3-1.2 {
  46. catchcmd "foo.db" ".tables"
  47. } {0 t1}
  48. do_test shell3-1.3 {
  49. catchcmd "foo.db \"DROP TABLE t1;\""
  50. } {0 {}}
  51. do_test shell3-1.4 {
  52. catchcmd "foo.db" ".tables"
  53. } {0 {}}
  54. do_test shell3-1.5 {
  55. catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
  56. } {0 {}}
  57. do_test shell3-1.6 {
  58. catchcmd "foo.db" ".tables"
  59. } {0 {}}
  60. do_test shell3-1.7 {
  61. catchcmd "foo.db \"CREATE TABLE\""
  62. } {1 {Error: near "TABLE": syntax error}}
  63. #----------------------------------------------------------------------------
  64. # shell3-2.*: Basic tests for running SQL file from command line.
  65. #
  66. # Run SQL file from command line
  67. do_test shell3-2.1 {
  68. forcedelete foo.db
  69. set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
  70. set fexist [file exist foo.db]
  71. list $rc $fexist
  72. } {{0 {}} 1}
  73. do_test shell3-2.2 {
  74. catchcmd "foo.db" ".tables"
  75. } {0 t1}
  76. do_test shell3-2.3 {
  77. catchcmd "foo.db" "DROP TABLE t1;"
  78. } {0 {}}
  79. do_test shell3-2.4 {
  80. catchcmd "foo.db" ".tables"
  81. } {0 {}}
  82. do_test shell3-2.5 {
  83. catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
  84. } {0 {}}
  85. do_test shell3-2.6 {
  86. catchcmd "foo.db" ".tables"
  87. } {0 {}}
  88. do_test shell3-2.7 {
  89. catchcmd "foo.db" "CREATE TABLE"
  90. } {1 {Error: incomplete SQL: CREATE TABLE}}
  91. finish_test