Fix expect tests again, ansi colors are hard

This commit is contained in:
Neil Macneale IV
2024-01-03 16:24:12 -08:00
parent e7b29cb00b
commit 7aaa6eab75
4 changed files with 28 additions and 27 deletions

View File

@@ -835,8 +835,9 @@ func formattedPrompts(db, branch string) (string, string) {
return fmt.Sprintf("%s/%s> ", cyanDb, yellowBr), multi
}
// getDBBranchFromSession returns the current database name for the session, handling all the errors along the way by printing
// red error messages to the CLI. If there was an issue getting the db name, the ok return value will be false.
// getDBBranchFromSession returns the current database name and current branch for the session, handling all the errors
// along the way by printing red error messages to the CLI. If there was an issue getting the db name, the ok return
// value will be false and the strings will be empty.
func getDBBranchFromSession(sqlCtx *sql.Context, qryist cli.Queryist) (db string, branch string, ok bool) {
_, resp, err := qryist.Query(sqlCtx, "select database() as db, active_branch() as branch")
if err != nil {
@@ -864,7 +865,7 @@ func getDBBranchFromSession(sqlCtx *sql.Context, qryist cli.Queryist) (db string
} else {
db = row[0].(string)
// It is possilbe to `use mydb/branch`, and as far as your session is concerned your database is mydb/branch. We
// It is possible to `use mydb/branch`, and as far as your session is concerned your database is mydb/branch. We
// allow that, but also want to show the user the branch name in the prompt. So we munge the DB in this case.
if strings.HasSuffix(db, "/"+branch) {
db = db[:len(db)-len(branch)-1]

View File

@@ -3,32 +3,32 @@
set timeout 2
spawn dolt sql
expect {
"doltsql/main> " { send "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT);\r"; }
"> " { send "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT);\r"; }
timeout { exit 1; }
failed { exit 1; }
}
expect {
"doltsql/main> " { send "INSERT INTO test VALUES (0,0);\r"; }
"> " { send "INSERT INTO test VALUES (0,0);\r"; }
timeout { exit 1; }
failed { exit 1; }
}
expect {
"doltsql/main> " { send "DELIMITER $$\r"; }
"> " { send "DELIMITER $$\r"; }
timeout { exit 1; }
failed { exit 1; }
}
expect {
"doltsql/main> " { send "INSERT INTO test VALUES (1,1)$$\r"; }
"> " { send "INSERT INTO test VALUES (1,1)$$\r"; }
timeout { exit 1; }
failed { exit 1; }
}
expect {
"doltsql/main> " { send "delimiter #\r"; }
"> " { send "delimiter #\r"; }
timeout { exit 1; }
failed { exit 1; }
}
expect {
"doltsql/main> " { send "CREATE TRIGGER tt BEFORE INSERT ON test FOR EACH ROW\r"; }
"> " { send "CREATE TRIGGER tt BEFORE INSERT ON test FOR EACH ROW\r"; }
timeout { exit 1; }
failed { exit 1; }
}
@@ -53,7 +53,7 @@ expect {
failed { exit 1; }
}
expect {
"doltsql/main> " { send "DeLiMiTeR ;\r"; }
"> " { send "DeLiMiTeR ;\r"; }
timeout { exit 1; }
failed { exit 1; }
}

View File

@@ -4,34 +4,34 @@ set timeout 2
spawn dolt sql
expect {
"doltsql/main> " { send "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);\r"; }
"> " { send "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);\r"; }
timeout { exit 1; }
failed { exit 1; }
}
expect {
"doltsql/main> " { send "INSERT INTO test VALUES (0,0);\r"; }
"> " { send "INSERT INTO test VALUES (0,0);\r"; }
timeout { exit 1; }
failed { exit 1; }
}
expect {
"doltsql/main> " { send "INSERT INTO test VALUES (1,0);\r"; }
"> " { send "INSERT INTO test VALUES (1,0);\r"; }
timeout { exit 1; }
"UNIQUE" { exp_continue; }
failed { exp_continue; }
}
expect {
"doltsql/main> " { send "INSERT INTO test VALUES (1,1);\r"; }
"> " { send "INSERT INTO test VALUES (1,1);\r"; }
timeout { exit 1; }
failed { exit 1; }
}
expect {
"doltsql/main> " { send "INSERT INTO test VALUES (2,2);\r"; }
timeout { exit 1; }
failed { exit 1; }
}
"> " { send "INSERT INTO test VALUES (2,2);\r"; }
timeout { exit 1; }
failed { exit 1; }
}
expect eof

View File

@@ -7,32 +7,32 @@ spawn dolt sql
# error output includes the line of the failed test expectation
expect {
"*doltsql/main> " { send -- "use `doltsql/test`;\r"; }
-re ".*doltsql.*/.*main.*> " { send -- "use `doltsql/test`;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"*doltsql/test> " { send -- "show tables;\r"; }
-re ".*doltsql.*/.*test.*> " { send -- "show tables;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"*doltsql/test> " { send -- "use information_schema;\r"; }
-re ".*doltsql.*/.*test.*> " { send -- "use information_schema;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"*information_schema> " { send -- "show tables;\r"; }
-re ".*information_schema.*> " { send -- "show tables;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"*information_schema> " { send -- "CREATE DATABASE mydb;\r"; }
-re ".*information_schema.*> " { send -- "CREATE DATABASE mydb;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"*information_schema> " { send -- "use db1;\r"; }
-re ".*information_schema.*> " { send -- "use db1;\r"; }
timeout { puts "$TESTFAILURE"; }
}
@@ -42,12 +42,12 @@ expect {
}
expect {
"*db1/main>" { send -- "use db2;\r"; }
-re ".*db1.*/.*main.*>" { send -- "use db2;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"*db2/main> " { send -- "select database();\r"; }
-re ".*db2.*/.*main.*> " { send -- "select database();\r"; }
timeout { puts "$TESTFAILURE"; }
}
@@ -57,6 +57,6 @@ expect {
}
expect {
"mydb/main> " { send -- "exit ;\r"; }
-re ".*mydb.*/.*main.*> " { send -- "exit ;\r"; }
timeout { puts "$TESTFAILURE"; }
}