diff --git a/integration-tests/bats/sql-shell.bats b/integration-tests/bats/sql-shell.bats index 7d1eb03831..edb70b8c83 100644 --- a/integration-tests/bats/sql-shell.bats +++ b/integration-tests/bats/sql-shell.bats @@ -83,6 +83,58 @@ teardown() { [[ "$output" =~ "+---------------------" ]] || false } +@test "sql-shell: shell works after failing query" { + skiponwindows "Need to install expect and make this script work on windows." + $BATS_TEST_DIRNAME/sql-works-after-failing-query.expect +} + +@test "sql-shell: delimiter" { + skiponwindows "Need to install expect and make this script work on windows." + mkdir doltsql + cd doltsql + dolt init + + run $BATS_TEST_DIRNAME/sql-delimiter.expect + [ "$status" -eq "0" ] + [[ ! "$output" =~ "Error" ]] || false + [[ ! "$output" =~ "error" ]] || false + + run dolt sql -q "SELECT * FROM test ORDER BY 1" -r=csv + [ "$status" -eq "0" ] + [[ "$output" =~ "pk,v1" ]] || false + [[ "$output" =~ "0,0" ]] || false + [[ "$output" =~ "1,1" ]] || false + [[ "${#lines[@]}" = "3" ]] || false + + run dolt sql -q "SHOW TRIGGERS" + [ "$status" -eq "0" ] + [[ "$output" =~ "SET NEW.v1 = NEW.v1 * 11" ]] || false + + cd .. + rm -rf doltsql +} + +@test "sql-shell: use databases" { + skiponwindows "Need to install expect and make this script work on windows." + mkdir doltsql + cd doltsql + dolt init + dolt sql -q "create database db1" + dolt sql -q "create database db2" + + dolt branch test + + run expect $BATS_TEST_DIRNAME/sql-use.expect + echo $output + + [ "$status" -eq "0" ] + [[ ! "$output" =~ "Error" ]] || false + [[ ! "$output" =~ "error" ]] || false + + cd .. + rm -rf doltsql +} + @test "sql-shell: default datadir, doltcfg, and privs" { # remove config files rm -rf .doltcfg diff --git a/integration-tests/bats/sql-use.expect b/integration-tests/bats/sql-use.expect index cea7a3b816..03d296eb83 100644 --- a/integration-tests/bats/sql-use.expect +++ b/integration-tests/bats/sql-use.expect @@ -1,41 +1,62 @@ -#!/usr/bin/expect +#!/usr/bin/expect -set timeout 1000 +set timeout 3 spawn dolt sql +# This script uses undefined variables in the failure case so that +# errors output includes the line of the failed test expectation + expect { - "doltsql> " { send "use `doltsql/test`;\r"; } - timeout { exit 1; } + "*doltsql> " { send -- "use `doltsql/test`;\r"; } + timeout { puts "$TESTFAILURE"; } } expect { - "doltsql/test> " { send "show tables;\r"; } - timeout { exit 1; } + "*doltsql/test> " { send -- "show tables;\r"; } + timeout { puts "$TESTFAILURE"; } } expect { - "doltsql/test> " { send "use information_schema;\r"; } - timeout { exit 1; } + "*doltsql/test> " { send -- "use information_schema;\r"; } + timeout { puts "$TESTFAILURE"; } } expect { - "information_schema> " { send "show tables;\r"; } - timeout { exit 1; } + "*information_schema> " { send -- "show tables;\r"; } + timeout { puts "$TESTFAILURE"; } } expect { - "information_schema> " { send "CREATE DATABASE mydb ;\r"; } - timeout { exit 1; } + "*information_schema> " { send -- "CREATE DATABASE mydb;\r"; } + timeout { puts "$TESTFAILURE"; } } expect { - "information_schema> " { send "use mydb ;\r"; } - timeout { exit 1; } + "*information_schema> " { send -- "use db1;\r"; } + timeout { puts "$TESTFAILURE"; } } -# TODO: The failed keyword seems to be triggering the connection_control_failed_login_attempts info_schema table. Not clear why the output -# of this table is comming all the way down to this command. expect { - "mydb> " { send "exit ;\r"; } - timeout { exit 1; } + "*db1> " { send -- "select database();\r"; } + timeout { puts "$TESTFAILURE"; } +} + +expect { + "|*db1*|*db1>" { send -- "use db2;\r"; } + timeout { puts "$TESTFAILURE"; } +} + +expect { + "*db2> " { send -- "select database();\r"; } + timeout { puts "$TESTFAILURE"; } +} + +expect { + "|.*db2.*|.*\rdb2>" { send -- "use mydb;\r"; } + timeout { puts "$TESTFAILURE"; } +} + +expect { + "mydb> " { send -- "exit ;\r"; } + timeout { puts "$TESTFAILURE"; } } diff --git a/integration-tests/bats/sql.bats b/integration-tests/bats/sql.bats index 442aebbed5..896298b906 100755 --- a/integration-tests/bats/sql.bats +++ b/integration-tests/bats/sql.bats @@ -1406,6 +1406,30 @@ SQL [[ "$output" =~ "exists" ]] || false } +@test "sql: use database with multiple dbs" { + dolt sql -q "create database db1" + dolt sql -q "create database db2" + + dolt sql <