diff --git a/integration-tests/bats/sql-shell-prompt.expect b/integration-tests/bats/sql-shell-prompt.expect new file mode 100755 index 0000000000..3aab2a72a4 --- /dev/null +++ b/integration-tests/bats/sql-shell-prompt.expect @@ -0,0 +1,49 @@ +#!/usr/bin/expect + +spawn dolt sql + +expect { + -re "> " { send "create database mydb;\r"; } + timeout { exit 1; } + failed { exit 1; } +} +expect { + -re "> " { send "use mydb;\r"; } + timeout { exit 1; } + failed { exit 1; } +} +expect { + -re ".*mydb.*/.*main.*> " { send "create table tbl (i int);\r"; } + timeout { exit 1; } + failed { exit 1; } +} + +# Dirty workspace should show in prompt as a "*" before the ">" +# (all the .* instances here are to account for ansi colors chars. +expect { + -re ".*mydb.*/.*main.*\\*.*> " { send "call dolt_commit('-Am', 'msg');\r"; } + timeout { exit 1; } + failed { exit 1; } +} + +expect { + -re ".*mydb.*/.*main.*> " { send "call dolt_checkout('-b','other','HEAD');\r"; } + timeout { exit 1; } + failed { exit 1; } +} + +expect { + -re ".*mydb.*/.*main.*> " { send "use mysql;\r"; } + timeout { exit 1; } + failed { exit 1; } +} + +# using a non dolt db should result in a prompt without a slash. The brackets +# are required to get expect to properly parse this regex. +expect { + -re {.*mysql[^\\/]*> } { send "exit;\r"; } + timeout { exit 1; } + failed { exit 1; } +} + +expect eof diff --git a/integration-tests/bats/sql-shell.bats b/integration-tests/bats/sql-shell.bats index dad617a59d..def7adceea 100644 --- a/integration-tests/bats/sql-shell.bats +++ b/integration-tests/bats/sql-shell.bats @@ -67,6 +67,17 @@ teardown() { [[ "$output" =~ "+---------------------" ]] || false } +# bats test_tags=no_lambda +@test "sql-shell: sql shell prompt updates" { + skiponwindows "Need to install expect and make this script work on windows." + + # start in an empty directory + mkdir sql_shell_test + cd sql_shell_test + + $BATS_TEST_DIRNAME/sql-shell-prompt.expect +} + # bats test_tags=no_lambda @test "sql-shell: shell works after failing query" { skiponwindows "Need to install expect and make this script work on windows."