Used bats/expect to perform a better test

This commit is contained in:
Neil Macneale IV
2025-08-27 13:14:49 -07:00
parent f09fdd132d
commit 305e135401
2 changed files with 40 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
for i in {1..20}; do
dolt commit --allow-empty -m "commit $i abc"
done
}
teardown() {
teardown_common
}
export NO_COLOR=1
@test "dolt log with pager" {
# We use `expect` because we need TTY simulation to get the pager to kick in
export DOLT_PAGER="tail -n 2"
run expect $BATS_TEST_DIRNAME/pager.expect
[ "$status" -eq 0 ]
[[ ! "$output" =~ "commit 2 abc" ]] || false
[[ "$output" =~ "commit 1 abc" ]] || false
[[ "$output" =~ "Initialize data repository" ]] || false
[ "${#lines[@]}" -eq 2 ]
export DOLT_PAGER="head -n 3"
run expect $BATS_TEST_DIRNAME/pager.expect
[ "$status" -eq 0 ]
[[ "$output" =~ "commit 20 abc" ]] || false
[[ "$output" =~ "commit 19 abc" ]] || false
[[ "$output" =~ "commit 18 abc" ]] || false
[[ ! "$output" =~ "commit 17 abc" ]] || false
[ "${#lines[@]}" -eq 3 ]
}
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/expect
spawn -noecho dolt log --oneline
expect eof