1
0

shell4.test 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # 2010 July 28
  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. # These tests are specific to the .stats command.
  14. #
  15. # $Id: shell4.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
  16. #
  17. # Test plan:
  18. #
  19. # shell4-1.*: Basic tests specific to the "stats" command.
  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. # Test cases shell4-1.*: Tests specific to the "stats" command.
  37. #
  38. # should default to off
  39. do_test shell4-1.1.1 {
  40. set res [catchcmd "test.db" ".show"]
  41. list [regexp {stats: off} $res]
  42. } {1}
  43. do_test shell4-1.1.2 {
  44. set res [catchcmd "test.db" ".show"]
  45. list [regexp {stats: on} $res]
  46. } {0}
  47. # -stats should turn it on
  48. do_test shell4-1.2.1 {
  49. set res [catchcmd "-stats test.db" ".show"]
  50. list [regexp {stats: on} $res]
  51. } {1}
  52. do_test shell4-1.2.2 {
  53. set res [catchcmd "-stats test.db" ".show"]
  54. list [regexp {stats: off} $res]
  55. } {0}
  56. # .stats ON|OFF Turn stats on or off
  57. do_test shell4-1.3.1 {
  58. catchcmd "test.db" ".stats"
  59. } {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
  60. do_test shell4-1.3.2 {
  61. catchcmd "test.db" ".stats ON"
  62. } {0 {}}
  63. do_test shell4-1.3.3 {
  64. catchcmd "test.db" ".stats OFF"
  65. } {0 {}}
  66. do_test shell4-1.3.4 {
  67. # too many arguments
  68. catchcmd "test.db" ".stats OFF BAD"
  69. } {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
  70. # NB. whitespace is important
  71. do_test shell4-1.4.1 {
  72. set res [catchcmd "test.db" {.show}]
  73. list [regexp {stats: off} $res]
  74. } {1}
  75. do_test shell4-1.4.2 {
  76. set res [catchcmd "test.db" {.stats ON
  77. .show
  78. }]
  79. list [regexp {stats: on} $res]
  80. } {1}
  81. do_test shell4-1.4.3 {
  82. set res [catchcmd "test.db" {.stats OFF
  83. .show
  84. }]
  85. list [regexp {stats: off} $res]
  86. } {1}
  87. # make sure stats not present when off
  88. do_test shell4-1.5.1 {
  89. set res [catchcmd "test.db" {SELECT 1;}]
  90. list [regexp {Memory Used} $res] \
  91. [regexp {Heap Usage} $res] \
  92. [regexp {Autoindex Inserts} $res]
  93. } {0 0 0}
  94. # make sure stats are present when on
  95. do_test shell4-1.5.2 {
  96. set res [catchcmd "test.db" {.stats ON
  97. SELECT 1;
  98. }]
  99. list [regexp {Memory Used} $res] \
  100. [regexp {Heap Usage} $res] \
  101. [regexp {Autoindex Inserts} $res]
  102. } {1 1 1}
  103. finish_test