mirror of
https://github.com/dolthub/dolt.git
synced 2025-12-30 16:12:39 -06:00
First pass on expect tests for add -p
This commit is contained in:
18
integration-tests/bats/add-patch-expect/all_none.expect
Executable file
18
integration-tests/bats/add-patch-expect/all_none.expect
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/expect
|
||||
|
||||
set timeout 5
|
||||
set env(NO_COLOR) 1
|
||||
|
||||
source "$env(BATS_CWD)/helper/common_expect_functions.tcl"
|
||||
|
||||
# Specify tables
|
||||
spawn dolt add -p coordinates colors
|
||||
|
||||
# colors table will be first (alpha order). Add everything.
|
||||
expect_with_defaults_2 { Yellow | 255 | 255 } {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "a\r"; }
|
||||
|
||||
# coordinates table is next.
|
||||
expect_with_defaults_2 {| - | 2 | 3.3 | 4.4 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "d\r"; }
|
||||
|
||||
expect eof
|
||||
exit
|
||||
15
integration-tests/bats/add-patch-expect/help_quit.expect
Executable file
15
integration-tests/bats/add-patch-expect/help_quit.expect
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/expect
|
||||
|
||||
set timeout 5
|
||||
set env(NO_COLOR) 1
|
||||
|
||||
source "$env(BATS_CWD)/helper/common_expect_functions.tcl"
|
||||
|
||||
spawn dolt add -p
|
||||
|
||||
expect_with_defaults {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "?\r"; }
|
||||
|
||||
expect_with_defaults_2 {\? - show this help} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "q\r"; }
|
||||
|
||||
expect eof
|
||||
exit
|
||||
41
integration-tests/bats/add-patch-expect/restart_multiple_times.expect
Executable file
41
integration-tests/bats/add-patch-expect/restart_multiple_times.expect
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/expect
|
||||
|
||||
set timeout 5
|
||||
set env(NO_COLOR) 1
|
||||
|
||||
source "$env(BATS_CWD)/helper/common_expect_functions.tcl"
|
||||
|
||||
spawn dolt add --patch
|
||||
|
||||
# This is a long script, but the idea is simple. Input y,n,y,s repeatedly and insure that the right prompts are seen
|
||||
|
||||
expect_with_defaults_2 {| \+ | 0 | Yellow | 255 | 255 | 0 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
|
||||
|
||||
expect_with_defaults_2 {| - | 2 | Green | 0 | 255 | 0 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; }
|
||||
|
||||
expect_with_defaults_2 {| > | 3 | SkyBlue | 0 | 128 | 255 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
|
||||
|
||||
expect_with_defaults_2 {| - | 2 | 3.3 | 4.4 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "s\r"; }
|
||||
|
||||
expect_with_defaults_2 {| - | 2 | Green | 0 | 255 | 0 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
|
||||
|
||||
expect_with_defaults_2 {| - | 2 | 3.3 | 4.4 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; }
|
||||
|
||||
expect_with_defaults_2 {| > | 3 | 5.5 | 100.001 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
|
||||
|
||||
expect_with_defaults_2 {| \+ | 4 | 42.24 | 23.32 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "s\r"; }
|
||||
|
||||
expect_with_defaults_2 {| - | 2 | 3.3 | 4.4 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
|
||||
|
||||
expect_with_defaults_2 {| \+ | 4 | 42.24 | 23.32 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; }
|
||||
|
||||
expect_with_defaults_2 {| - | 2 | sami |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "s\r"; }
|
||||
|
||||
expect_with_defaults_2 {| \+ | 4 | 42.24 | 23.32 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
|
||||
|
||||
expect_with_defaults_2 {| - | 2 | sami |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; }
|
||||
|
||||
expect_with_defaults_2 {| \+ | 4 | john |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
|
||||
|
||||
expect eof
|
||||
exit
|
||||
179
integration-tests/bats/add-patch.bats
Normal file
179
integration-tests/bats/add-patch.bats
Normal file
@@ -0,0 +1,179 @@
|
||||
#! /usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
setup() {
|
||||
skiponwindows "Need to install expect and make this script work on windows."
|
||||
setup_common
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE names (pk int primary key, name varchar(8));
|
||||
CREATE TABLE colors (pk int primary key, name varchar(8), red int, green int, blue int);
|
||||
CREATE TABLE coordinates (pk int primary key, x float, y float);
|
||||
|
||||
INSERT INTO names VALUES (1, 'neil');
|
||||
INSERT INTO names VALUES (2, 'sami');
|
||||
INSERT INTO names VALUES (3, 'jane');
|
||||
INSERT INTO colors VALUES (1, 'Red', 255, 0, 0);
|
||||
INSERT INTO colors VALUES (2, 'Green', 0, 255, 0);
|
||||
INSERT INTO colors VALUES (3, 'Blue', 0, 0, 255);
|
||||
INSERT INTO coordinates VALUES (1, 1.1, 2.2);
|
||||
INSERT INTO coordinates VALUES (2, 3.3, 4.4);
|
||||
INSERT INTO coordinates VALUES (3, 5.5, 6.6);
|
||||
|
||||
CALL dolt_commit('-Am', 'main commit 1');
|
||||
|
||||
UPDATE names SET name = 'joey' WHERE pk = 1;
|
||||
UPDATE colors SET name = 'SkyBlue', red = 0, green = 128, blue = 255 WHERE pk = 3;
|
||||
UPDATE coordinates SET y = 100.001 WHERE pk = 3;
|
||||
|
||||
INSERT INTO names VALUES (4,'john');
|
||||
INSERT INTO colors VALUES (0, 'Yellow', 255, 255, 0);
|
||||
INSERT INTO coordinates VALUES (4, 42.24, 23.32);
|
||||
|
||||
DELETE FROM names WHERE pk = 2;
|
||||
DELETE FROM colors WHERE pk = 2;
|
||||
DELETE FROM coordinates WHERE pk = 2;
|
||||
SQL
|
||||
|
||||
# The default setup has three tables, at this stage there have the a single update, insert, and delete
|
||||
# on each table. In addition, each contains an unmodified row. Finally, the diff shows that the updates
|
||||
# to each table are in different orders based on the primary key.
|
||||
#
|
||||
# diff --dolt a/colors b/colors
|
||||
# --- a/colors
|
||||
# +++ b/colors
|
||||
# +---+----+---------+-----+-------+------+
|
||||
# | | pk | name | red | green | blue |
|
||||
# +---+----+---------+-----+-------+------+
|
||||
# | + | 0 | Yellow | 255 | 255 | 0 |
|
||||
# | - | 2 | Green | 0 | 255 | 0 |
|
||||
# | < | 3 | Blue | 0 | 0 | 255 |
|
||||
# | > | 3 | SkyBlue | 0 | 128 | 255 |
|
||||
# +---+----+---------+-----+-------+------+
|
||||
# diff --dolt a/coordinates b/coordinates
|
||||
# --- a/coordinates
|
||||
# +++ b/coordinates
|
||||
# +---+----+-------+---------+
|
||||
# | | pk | x | y |
|
||||
# +---+----+-------+---------+
|
||||
# | - | 2 | 3.3 | 4.4 |
|
||||
# | < | 3 | 5.5 | 6.6 |
|
||||
# | > | 3 | 5.5 | 100.001 |
|
||||
# | + | 4 | 42.24 | 23.32 |
|
||||
# +---+----+-------+---------+
|
||||
# diff --dolt a/names b/names
|
||||
# --- a/names
|
||||
# +++ b/names
|
||||
# +---+----+------+
|
||||
# | | pk | name |
|
||||
# +---+----+------+
|
||||
# | < | 1 | neil |
|
||||
# | > | 1 | joey |
|
||||
# | - | 2 | sami |
|
||||
# | + | 4 | john |
|
||||
# +---+----+------+
|
||||
#
|
||||
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "add-patch: clean workspace" {
|
||||
dolt reset --hard
|
||||
|
||||
run dolt add --patch
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "No changes." ]] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "add-patch: all changes staged" {
|
||||
dolt add .
|
||||
|
||||
run dolt add --patch
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "No changes." ]] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "add-patch: help and quit" {
|
||||
run dolt sql -r csv -q "select dolt_hashof_db()"
|
||||
[ $status -eq 0 ]
|
||||
ORIG_DB_HASH=$(echo "$output" | awk 'NR==2')
|
||||
|
||||
run $BATS_TEST_DIRNAME/add-patch-expect/help_quit.expect
|
||||
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run dolt sql -r csv -q "select dolt_hashof_db()"
|
||||
[ $status -eq 0 ]
|
||||
DB_HASH=$(echo "$output" | awk 'NR==2')
|
||||
|
||||
# Verify that the state of the database hasn't changed.
|
||||
[[ "$DB_HASH" == "$ORIG_DB_HASH" ]] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "add-patch: a then d for two tables" {
|
||||
# This test does: `add -p coordinates colors` -> 'a' -> 'd'
|
||||
run $BATS_TEST_DIRNAME/add-patch-expect/all_none.expect
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run dolt sql -q "select name from colors AS OF STAGED"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "Red" ]] || false
|
||||
[[ "$output" =~ "SkyBlue" ]] || false
|
||||
[[ "$output" =~ "Yellow" ]] || false
|
||||
[[ ! "$output" =~ "Green" ]] || false
|
||||
|
||||
# Should be no changes on coordinates.
|
||||
run dolt sql -q "select pk, y from coordinates AS OF STAGED"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "| 1 | 2.2 |" ]] || false
|
||||
[[ "$output" =~ "| 2 | 4.4 |" ]] || false
|
||||
[[ "$output" =~ "| 3 | 6.6 |" ]] || false
|
||||
[[ ! "$output" =~ "23.32" ]] || false # Value for inserted row - should not be there.
|
||||
|
||||
# Should be no changes on names.
|
||||
run dolt sql -q "select pk, name from names AS OF STAGED"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "| 1 | neil |" ]] || false
|
||||
[[ "$output" =~ "| 2 | sami |" ]] || false
|
||||
[[ "$output" =~ "| 3 | jane |" ]] || false
|
||||
[[ ! "$output" =~ "john" ]] || false # Value for inserted row - should not be there.
|
||||
}
|
||||
|
||||
@test "add-patch: y/n repeatedly with restarts" {
|
||||
# This test repeatedly does 'y/n/y/s' until the program exits.
|
||||
run $BATS_TEST_DIRNAME/add-patch-expect/restart_multiple_times.expect
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run dolt sql -q "select name from colors AS OF STAGED"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "Red" ]] || false
|
||||
[[ "$output" =~ "SkyBlue" ]] || false
|
||||
[[ "$output" =~ "Yellow" ]] || false
|
||||
[[ ! "$output" =~ "Green" ]] || false
|
||||
|
||||
run dolt sql -q "select pk, y from coordinates AS OF STAGED"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "| 1 | 2.2 |" ]] || false
|
||||
[[ "$output" =~ "| 3 | 100.001 |" ]] || false
|
||||
[[ "$output" =~ "| 4 | 23.32 |" ]] || false
|
||||
|
||||
run dolt sql -q "select pk, name from names AS OF STAGED"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "| 1 | neil |" ]] || false
|
||||
[[ "$output" =~ "| 3 | jane |" ]] || false
|
||||
[[ ! "$output" =~ "john" ]] || false # last promoted row - should not be staged.
|
||||
}
|
||||
|
||||
|
||||
# Test needed:
|
||||
# restart workflow.
|
||||
# add keyless table tests.
|
||||
@@ -3,68 +3,7 @@
|
||||
set timeout 5
|
||||
set env(NO_COLOR) 1
|
||||
|
||||
|
||||
proc expect_with_defaults {pattern action} {
|
||||
expect {
|
||||
-re $pattern {
|
||||
# puts "Matched pattern: $pattern"
|
||||
eval $action
|
||||
}
|
||||
timeout {
|
||||
puts "<<Timeout>>";
|
||||
exit 1
|
||||
}
|
||||
eof {
|
||||
puts "<<End of File reached>>";
|
||||
exit 1
|
||||
}
|
||||
failed {
|
||||
puts "<<Failed>>";
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proc expect_with_defaults_2 {patternA patternB action} {
|
||||
# First, match patternA
|
||||
expect {
|
||||
-re $patternA {
|
||||
puts "<<Matched expected pattern A: $patternA>>"
|
||||
# Now match patternB
|
||||
expect {
|
||||
-re $patternB {
|
||||
puts "<<Matched expected pattern B: $patternB>>"
|
||||
eval $action
|
||||
}
|
||||
timeout {
|
||||
puts "<<Timeout waiting for pattern B>>"
|
||||
exit 1
|
||||
}
|
||||
eof {
|
||||
puts "<<End of File reached while waiting for pattern B>>"
|
||||
exit 1
|
||||
}
|
||||
failed {
|
||||
puts "<<Failed while waiting for pattern B>>"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
timeout {
|
||||
puts "<<Timeout waiting for pattern A>>"
|
||||
exit 1
|
||||
}
|
||||
eof {
|
||||
puts "<<End of File reached while waiting for pattern A>>"
|
||||
exit 1
|
||||
}
|
||||
failed {
|
||||
puts "<<Failed while waiting for pattern A>>"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
source "$env(BATS_CWD)/helper/common_expect_functions.tcl"
|
||||
|
||||
spawn dolt sql
|
||||
|
||||
|
||||
Reference in New Issue
Block a user