test/system: Check the line count in the standard error & output streams

Note that 'run --keep-empty-lines' counts the trailing newline on the
last line as a separate line.

Until Bats 1.7.0, 'run --keep-empty-lines' had a bug where even when a
command produced no output, it would report a line count of one [1] due
to a stray line feed character.  This needs to be conditionalized, since
Fedora 35 has Bats 1.5.0.

[1] https://github.com/bats-core/bats-core/issues/573

https://github.com/containers/toolbox/pull/1192
This commit is contained in:
Debarshi Ray 2022-12-07 21:16:46 +01:00
parent 89385e12b5
commit f17a632f9a

View file

@ -70,6 +70,10 @@ teardown() {
assert_success
assert_line --index 1 --partial "<none>"
assert [ ${#lines[@]} -eq 3 ]
if check_bats_version 1.7.0; then
assert [ ${#stderr_lines[@]} -eq 0 ]
fi
}
@test "list: Try to list images and containers (no flag) with 3 containers and 2 images (the list should have 3 images and 2 containers)" {
@ -88,6 +92,10 @@ teardown() {
assert_success
assert_line --index 1 --partial "$(get_system_id)-toolbox:$(get_system_version)"
assert_line --index 2 --partial "fedora-toolbox:34"
assert [ ${#lines[@]} -eq 4 ]
if check_bats_version 1.7.0; then
assert [ ${#stderr_lines[@]} -eq 0 ]
fi
# Check containers
run --keep-empty-lines --separate-stderr $TOOLBOX list --containers
@ -96,6 +104,10 @@ teardown() {
assert_line --index 1 --partial "$(get_system_id)-toolbox-$(get_system_version)"
assert_line --index 2 --partial "non-default-one"
assert_line --index 3 --partial "non-default-two"
assert [ ${#lines[@]} -eq 5 ]
if check_bats_version 1.7.0; then
assert [ ${#stderr_lines[@]} -eq 0 ]
fi
# Check all together
run --keep-empty-lines --separate-stderr $TOOLBOX list
@ -106,6 +118,10 @@ teardown() {
assert_line --index 5 --partial "$(get_system_id)-toolbox-$(get_system_version)"
assert_line --index 6 --partial "non-default-one"
assert_line --index 7 --partial "non-default-two"
assert [ ${#lines[@]} -eq 9 ]
if check_bats_version 1.7.0; then
assert [ ${#stderr_lines[@]} -eq 0 ]
fi
}
@test "list: Images with and without names" {