diff --git a/integration-tests/bats/add-patch-expect/all_none.expect b/integration-tests/bats/add-patch-expect/all_none.expect new file mode 100755 index 0000000000..239e3f08fc --- /dev/null +++ b/integration-tests/bats/add-patch-expect/all_none.expect @@ -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 diff --git a/integration-tests/bats/add-patch-expect/help_quit.expect b/integration-tests/bats/add-patch-expect/help_quit.expect new file mode 100755 index 0000000000..6bdb62bcae --- /dev/null +++ b/integration-tests/bats/add-patch-expect/help_quit.expect @@ -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 diff --git a/integration-tests/bats/add-patch-expect/restart_multiple_times.expect b/integration-tests/bats/add-patch-expect/restart_multiple_times.expect new file mode 100755 index 0000000000..e13b2403c9 --- /dev/null +++ b/integration-tests/bats/add-patch-expect/restart_multiple_times.expect @@ -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 diff --git a/integration-tests/bats/add-patch.bats b/integration-tests/bats/add-patch.bats new file mode 100644 index 0000000000..426f842946 --- /dev/null +++ b/integration-tests/bats/add-patch.bats @@ -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 < | 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. diff --git a/integration-tests/bats/sql-shell-slash-cmds.expect b/integration-tests/bats/sql-shell-slash-cmds.expect index e7a6bc4a7d..63871c3dd4 100755 --- a/integration-tests/bats/sql-shell-slash-cmds.expect +++ b/integration-tests/bats/sql-shell-slash-cmds.expect @@ -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 "<>"; - exit 1 - } - eof { - puts "<>"; - exit 1 - } - failed { - puts "<>"; - exit 1 - } - } -} - -proc expect_with_defaults_2 {patternA patternB action} { - # First, match patternA - expect { - -re $patternA { - puts "<>" - # Now match patternB - expect { - -re $patternB { - puts "<>" - eval $action - } - timeout { - puts "<>" - exit 1 - } - eof { - puts "<>" - exit 1 - } - failed { - puts "<>" - exit 1 - } - } - } - timeout { - puts "<>" - exit 1 - } - eof { - puts "<>" - exit 1 - } - failed { - puts "<>" - exit 1 - } - } -} - +source "$env(BATS_CWD)/helper/common_expect_functions.tcl" spawn dolt sql