github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cli/interactive_tests/test_multiline_statements.tcl (about)

     1  #! /usr/bin/env expect -f
     2  
     3  source [file join [file dirname $argv0] common.tcl]
     4  
     5  start_server $argv
     6  
     7  # we force TERM to xterm, otherwise we can't
     8  # test bracketed paste below.
     9  set env(TERM) xterm
    10  
    11  spawn $argv sql
    12  eexpect root@
    13  
    14  start_test "Test that a multi-line entry can be recalled escaped."
    15  send "select 'foo\r"
    16  eexpect " ->"
    17  send "bar';\r"
    18  eexpect "1 row"
    19  eexpect "root@"
    20  
    21  # Send up-arrow.
    22  send "\033\[A"
    23  eexpect "select 'foo\r\nbar';"
    24  send "\r"
    25  eexpect "root@"
    26  
    27  send "select 1,\r"
    28  eexpect " ->"
    29  send "2, 3\r"
    30  eexpect " ->"
    31  end_test
    32  
    33  start_test "Test that \show does what it says."
    34  send "\\show\r"
    35  eexpect "select 1,"
    36  eexpect "2, 3"
    37  eexpect " ->"
    38  end_test
    39  
    40  start_test "Test finishing the multi-line statement."
    41  send ";\r"
    42  eexpect "1 row"
    43  eexpect "root@"
    44  
    45  # Send up-arrow.
    46  send "\033\[A"
    47  eexpect "select 1,"
    48  eexpect "2, 3"
    49  eexpect ";"
    50  end_test
    51  
    52  start_test "Test that Ctrl+C after the first line merely cancels the statement and presents the prompt."
    53  send "\r"
    54  eexpect root@
    55  send "select\r"
    56  eexpect " ->"
    57  interrupt
    58  eexpect root@
    59  end_test
    60  
    61  start_test "Test that \show does what it says."
    62  send "select\r"
    63  eexpect " ->"
    64  send "\\show\r"
    65  eexpect "select\r\n*->"
    66  interrupt
    67  end_test
    68  
    69  start_test "Test that a dangling table creation can be committed, and that other non-DDL, non-DML statements can be issued in the same txn. (#15283)"
    70  send "create database if not exists t;"
    71  send "drop table if exists t.blih;"
    72  send "create table if not exists t.kv(k int primary key, v int);\r"
    73  eexpect "CREATE TABLE"
    74  eexpect root@
    75  send "begin; create table t.blih(x INT REFERENCES t.kv(k));\r\r"
    76  eexpect "CREATE TABLE"
    77  eexpect root@
    78  eexpect OPEN
    79  
    80  send "show all cluster settings;\r"
    81  eexpect "rows"
    82  eexpect root@
    83  eexpect OPEN
    84  
    85  send "commit;\r"
    86  eexpect COMMIT
    87  eexpect root@
    88  end_test
    89  
    90  start_test "Test that a multi-line bracketed paste is handled properly."
    91  send "\033\[200~"
    92  send "\\set display_format csv\r\n"
    93  send "values (1,'a'), (2,'b'), (3,'c');\r\n"
    94  send "\033\[201~\r\n"
    95  eexpect "1,a"
    96  eexpect "2,b"
    97  eexpect "3,c"
    98  eexpect root@
    99  end_test
   100  
   101  
   102  
   103  interrupt
   104  eexpect eof
   105  
   106  stop_server $argv