#!/usr/bin/expect 

set timeout 3
spawn dolt sql

# This script uses undefined variables in the failure case so that
# error output includes the line of the failed test expectation

expect {
    -re ".*doltsql.*/.*main.*> " { send -- "use `doltsql/test`;\r"; }
    timeout { puts "$TESTFAILURE"; }
}

expect {
    -re ".*doltsql.*/.*test.*> " { send -- "show tables;\r"; }
    timeout { puts "$TESTFAILURE"; }
}

expect {
    -re ".*doltsql.*/.*test.*> " { send -- "use information_schema;\r"; }
    timeout { puts "$TESTFAILURE"; }
}

expect {
    -re ".*information_schema.*> " { send -- "show tables;\r"; }
    timeout { puts "$TESTFAILURE"; }
}

expect {
    -re ".*information_schema.*> " { send -- "CREATE DATABASE mydb;\r"; }
    timeout { puts "$TESTFAILURE"; }
}

expect {
    -re ".*information_schema.*> " { send -- "use db1;\r"; }
    timeout { puts "$TESTFAILURE"; }
}

expect {
    -re "|.*db1.*|\r.*db1.*> " { send -- "select database();\r"; }
    timeout { puts "$TESTFAILURE"; }
}

expect {
    -re ".*db1.*/.*main.*>" { send -- "use db2;\r"; }
    timeout { puts "$TESTFAILURE"; }
}

expect {
    -re ".*db2.*/.*main.*> " { send -- "select database();\r"; }
    timeout { puts "$TESTFAILURE"; }
}

expect {
    -re "|.*db2.*|.*\rdb2/main>" { send -- "use mydb;\r"; }
    timeout { puts "$TESTFAILURE"; }
}

expect {
    -re ".*mydb.*/.*main.*> " { send -- "exit ;\r"; }
    timeout { puts "$TESTFAILURE"; }
}
