From d29adbf10ecb829e108cde25e4765f813275de49 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 15 Nov 2024 17:51:28 +0100 Subject: [PATCH] test/system: Ensure that error messages go to the standard error stream Currently, there's no way to get assert_line to use the stderr_lines array [1]. This is worked around by assigning stderr_lines to the 'lines' array. [1] https://github.com/bats-core/bats-assert/issues/42 https://github.com/containers/toolbox/pull/1595 --- test/system/101-create.bats | 268 +++++++++++++++++++++--------------- 1 file changed, 159 insertions(+), 109 deletions(-) diff --git a/test/system/101-create.bats b/test/system/101-create.bats index 789c87fde..d077c1d8a 100644 --- a/test/system/101-create.bats +++ b/test/system/101-create.bats @@ -37,7 +37,7 @@ teardown() { pull_default_image - run "$TOOLBX" create + run --separate-stderr "$TOOLBX" create assert_success assert_line --index 0 "Created container: $default_container" @@ -48,7 +48,7 @@ teardown() { @test "create: With a custom name (using option --container)" { pull_default_image - run "$TOOLBX" create --container "custom-containerName" + run --separate-stderr "$TOOLBX" create --container "custom-containerName" assert_success assert_line --index 0 "Created container: custom-containerName" @@ -59,7 +59,7 @@ teardown() { @test "create: With a custom image and name (using option --container)" { pull_distro_image fedora 34 - run "$TOOLBX" create --container "fedora34" --image fedora-toolbox:34 + run --separate-stderr "$TOOLBX" create --container "fedora34" --image fedora-toolbox:34 assert_success assert_line --index 0 "Created container: fedora34" @@ -80,18 +80,20 @@ teardown() { } @test "create: Try with an invalid custom name (using positional argument)" { - run "$TOOLBX" --assumeyes create "ßpeci@l.N@m€" + run --separate-stderr "$TOOLBX" --assumeyes create "ßpeci@l.N@m€" assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for 'CONTAINER'" assert_line --index 1 "Container names must match '[a-zA-Z0-9][a-zA-Z0-9_.-]*'." assert_line --index 2 "Run 'toolbox --help' for usage." } @test "create: Try with an invalid custom name (using option --container)" { - run "$TOOLBX" --assumeyes create --container "ßpeci@l.N@m€" + run --separate-stderr "$TOOLBX" --assumeyes create --container "ßpeci@l.N@m€" assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--container'" assert_line --index 1 "Container names must match '[a-zA-Z0-9][a-zA-Z0-9_.-]*'." assert_line --index 2 "Run 'toolbox --help' for usage." @@ -100,14 +102,15 @@ teardown() { @test "create: Try with an invalid custom image" { local image="ßpeci@l.N@m€" - run "$TOOLBX" create --image "$image" + run --separate-stderr "$TOOLBX" create --image "$image" assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--image'" assert_line --index 1 "Container name $image generated from image is invalid." assert_line --index 2 "Container names must match '[a-zA-Z0-9][a-zA-Z0-9_.-]*'." assert_line --index 3 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 4 ] + assert [ ${#stderr_lines[@]} -eq 4 ] } @test "create: Try with an invalid custom image (using --assumeyes)" { @@ -128,7 +131,7 @@ teardown() { @test "create: Arch Linux" { pull_distro_image arch latest - run "$TOOLBX" create --distro arch + run --separate-stderr "$TOOLBX" create --distro arch assert_success assert_line --index 0 "Created container: arch-toolbox-latest" @@ -143,7 +146,7 @@ teardown() { @test "create: Arch Linux ('--release latest')" { pull_distro_image arch latest - run "$TOOLBX" create --distro arch --release latest + run --separate-stderr "$TOOLBX" create --distro arch --release latest assert_success assert_line --index 0 "Created container: arch-toolbox-latest" @@ -158,7 +161,7 @@ teardown() { @test "create: Arch Linux ('--release rolling')" { pull_distro_image arch latest - run "$TOOLBX" create --distro arch --release rolling + run --separate-stderr "$TOOLBX" create --distro arch --release rolling assert_success assert_line --index 0 "Created container: arch-toolbox-latest" @@ -173,7 +176,7 @@ teardown() { @test "create: Fedora 34" { pull_distro_image fedora 34 - run "$TOOLBX" create --distro fedora --release f34 + run --separate-stderr "$TOOLBX" create --distro fedora --release f34 assert_success assert_line --index 0 "Created container: fedora-toolbox-34" @@ -188,7 +191,7 @@ teardown() { @test "create: RHEL 8.10" { pull_distro_image rhel 8.10 - run "$TOOLBX" create --distro rhel --release 8.10 + run --separate-stderr "$TOOLBX" create --distro rhel --release 8.10 assert_success assert_line --index 0 "Created container: rhel-toolbox-8.10" @@ -203,7 +206,7 @@ teardown() { @test "create: Ubuntu 16.04" { pull_distro_image ubuntu 16.04 - run "$TOOLBX" create --distro ubuntu --release 16.04 + run --separate-stderr "$TOOLBX" create --distro ubuntu --release 16.04 assert_success assert_line --index 0 "Created container: ubuntu-toolbox-16.04" @@ -219,7 +222,7 @@ teardown() { @test "create: Ubuntu 18.04" { pull_distro_image ubuntu 18.04 - run "$TOOLBX" create --distro ubuntu --release 18.04 + run --separate-stderr "$TOOLBX" create --distro ubuntu --release 18.04 assert_success assert_line --index 0 "Created container: ubuntu-toolbox-18.04" @@ -235,7 +238,7 @@ teardown() { @test "create: Ubuntu 20.04" { pull_distro_image ubuntu 20.04 - run "$TOOLBX" create --distro ubuntu --release 20.04 + run --separate-stderr "$TOOLBX" create --distro ubuntu --release 20.04 assert_success assert_line --index 0 "Created container: ubuntu-toolbox-20.04" @@ -327,13 +330,14 @@ teardown() { @test "create: Try an unsupported distribution" { local distro="foo" - run "$TOOLBX" --assumeyes create --distro "$distro" + run --separate-stderr "$TOOLBX" --assumeyes create --distro "$distro" assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--distro'" assert_line --index 1 "Distribution $distro is unsupported." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try a non-existent image" { @@ -349,412 +353,453 @@ teardown() { } @test "create: Try a non-existent image (using --assumeyes)" { - run "$TOOLBX" --assumeyes create --image foo.org/bar + run --separate-stderr "$TOOLBX" --assumeyes create --image foo.org/bar assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: failed to pull image foo.org/bar" assert_line --index 1 "If it was a private image, log in with: podman login foo.org" assert_line --index 2 "Use 'toolbox --verbose ...' for further details." } @test "create: Try Arch Linux with an invalid release ('--release foo')" { - run "$TOOLBX" --assumeyes create --distro arch --release foo + run --separate-stderr "$TOOLBX" --assumeyes create --distro arch --release foo assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be 'latest'." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Fedora with an invalid release ('--release -3')" { - run "$TOOLBX" --assumeyes create --distro fedora --release -3 + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --release -3 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive integer." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Fedora with an invalid release ('--release -3.0')" { - run "$TOOLBX" --assumeyes create --distro fedora --release -3.0 + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --release -3.0 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive integer." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Fedora with an invalid release ('--release -3.1')" { - run "$TOOLBX" --assumeyes create --distro fedora --release -3.1 + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --release -3.1 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive integer." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Fedora with an invalid release ('--release 0')" { - run "$TOOLBX" --assumeyes create --distro fedora --release 0 + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --release 0 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive integer." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Fedora with an invalid release ('--release 0.0')" { - run "$TOOLBX" --assumeyes create --distro fedora --release 0.0 + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --release 0.0 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive integer." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Fedora with an invalid release ('--release 0.1')" { - run "$TOOLBX" --assumeyes create --distro fedora --release 0.1 + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --release 0.1 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive integer." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Fedora with an invalid release ('--release 3.0')" { - run "$TOOLBX" --assumeyes create --distro fedora --release 3.0 + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --release 3.0 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive integer." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Fedora with an invalid release ('--release 3.1')" { - run "$TOOLBX" --assumeyes create --distro fedora --release 3.1 + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --release 3.1 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive integer." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Fedora with an invalid release ('--release foo')" { - run "$TOOLBX" --assumeyes create --distro fedora --release foo + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --release foo assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive integer." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Fedora with an invalid release ('--release 3foo')" { - run "$TOOLBX" --assumeyes create --distro fedora --release 3foo + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --release 3foo assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive integer." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try RHEL with an invalid release ('--release 8')" { - run "$TOOLBX" --assumeyes create --distro rhel --release 8 + run --separate-stderr "$TOOLBX" --assumeyes create --distro rhel --release 8 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the '.' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try RHEL with an invalid release ('--release 8.0.0')" { - run "$TOOLBX" --assumeyes create --distro rhel --release 8.0.0 + run --separate-stderr "$TOOLBX" --assumeyes create --distro rhel --release 8.0.0 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the '.' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try RHEL with an invalid release ('--release 8.0.1')" { - run "$TOOLBX" --assumeyes create --distro rhel --release 8.0.1 + run --separate-stderr "$TOOLBX" --assumeyes create --distro rhel --release 8.0.1 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the '.' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try RHEL with an invalid release ('--release 8.3.0')" { - run "$TOOLBX" --assumeyes create --distro rhel --release 8.3.0 + run --separate-stderr "$TOOLBX" --assumeyes create --distro rhel --release 8.3.0 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the '.' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try RHEL with an invalid release ('--release 8.3.1')" { - run "$TOOLBX" --assumeyes create --distro rhel --release 8.3.1 + run --separate-stderr "$TOOLBX" --assumeyes create --distro rhel --release 8.3.1 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the '.' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try RHEL with an invalid release ('--release foo')" { - run "$TOOLBX" --assumeyes create --distro rhel --release foo + run --separate-stderr "$TOOLBX" --assumeyes create --distro rhel --release foo assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the '.' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try RHEL with an invalid release ('--release 8.2foo')" { - run "$TOOLBX" --assumeyes create --distro rhel --release 8.2foo + run --separate-stderr "$TOOLBX" --assumeyes create --distro rhel --release 8.2foo assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the '.' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try RHEL with an invalid release ('--release -2.1')" { - run "$TOOLBX" --assumeyes create --distro rhel --release -2.1 + run --separate-stderr "$TOOLBX" --assumeyes create --distro rhel --release -2.1 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be a positive number." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try RHEL with an invalid release ('--release -2.-1')" { - run "$TOOLBX" --assumeyes create --distro rhel --release -2.-1 + run --separate-stderr "$TOOLBX" --assumeyes create --distro rhel --release -2.-1 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the '.' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try RHEL with an invalid release ('--release 2.-1')" { - run "$TOOLBX" --assumeyes create --distro rhel --release 2.-1 + run --separate-stderr "$TOOLBX" --assumeyes create --distro rhel --release 2.-1 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the '.' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 20')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 20 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 20 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the 'YY.MM' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 20.04.0')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 20.04.0 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 20.04.0 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the 'YY.MM' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 20.04.1')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 20.04.1 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 20.04.1 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the 'YY.MM' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release foo')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release foo + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release foo assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the 'YY.MM' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 20foo')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 20foo + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 20foo assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the 'YY.MM' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release foo.bar')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release foo.bar + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release foo.bar assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the 'YY.MM' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release foo.bar.baz')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release foo.bar.baz + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release foo.bar.baz assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the 'YY.MM' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 3.10')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 3.10 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 3.10 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release year must be 4 or more." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 202.4')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 202.4 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 202.4 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release year cannot have more than two digits." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 202.04')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 202.04 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 202.04 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release year cannot have more than two digits." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 2020.4')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 2020.4 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 2020.4 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release year cannot have more than two digits." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 2020.04')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 2020.04 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 2020.04 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release year cannot have more than two digits." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 04.10')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 04.10 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 04.10 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release year cannot have a leading zero." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 4.bar')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 4.bar + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 4.bar assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the 'YY.MM' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 4.bar.baz')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 4.bar.baz + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 4.bar.baz assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release must be in the 'YY.MM' format." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 4.0')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 4.0 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 4.0 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release month must be between 01 and 12." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 4.00')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 4.00 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 4.00 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release month must be between 01 and 12." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 4.13')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 4.13 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 4.13 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release month must be between 01 and 12." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try Ubuntu with an invalid release ('--release 20.4')" { - run "$TOOLBX" --assumeyes create --distro ubuntu --release 20.4 + run --separate-stderr "$TOOLBX" --assumeyes create --distro ubuntu --release 20.4 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: invalid argument for '--release'" assert_line --index 1 "The release month must have two digits." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try a non-default distro without a release" { @@ -767,13 +812,14 @@ teardown() { distro="rhel" fi - run "$TOOLBX" --assumeyes create --distro "$distro" + run --separate-stderr "$TOOLBX" --assumeyes create --distro "$distro" assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: option '--release' is needed" assert_line --index 1 "Distribution $distro doesn't match the host." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try using both --distro and --image" { @@ -788,12 +834,13 @@ teardown() { } @test "create: Try using both --distro and --image (using --assumeyes)" { - run "$TOOLBX" --assumeyes create --distro fedora --image fedora-toolbox:34 + run --separate-stderr "$TOOLBX" --assumeyes create --distro fedora --image fedora-toolbox:34 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: options --distro and --image cannot be used together" assert_line --index 1 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 2 ] + assert [ ${#stderr_lines[@]} -eq 2 ] } @test "create: Try using both --image and --release" { @@ -808,24 +855,26 @@ teardown() { } @test "create: Try using both --image and --release (using --assumeyes)" { - run "$TOOLBX" --assumeyes create --image fedora-toolbox:34 --release 34 + run --separate-stderr "$TOOLBX" --assumeyes create --image fedora-toolbox:34 --release 34 assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: options --image and --release cannot be used together" assert_line --index 1 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 2 ] + assert [ ${#stderr_lines[@]} -eq 2 ] } @test "create: Try a non-existent authentication file" { local file="$BATS_TEST_TMPDIR/non-existent-file" - run "$TOOLBX" create --authfile "$file" + run --separate-stderr "$TOOLBX" create --authfile "$file" assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: file $file not found" assert_line --index 1 "'podman login' can be used to create the file." assert_line --index 2 "Run 'toolbox --help' for usage." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] } @test "create: Try a non-existent authentication file (using --assumeyes)" { @@ -849,15 +898,16 @@ teardown() { run podman login --authfile "$authfile" --username user --password user "$DOCKER_REG_URI" assert_success - run "$TOOLBX" --assumeyes create --image "$DOCKER_REG_URI/$image" + run --separate-stderr "$TOOLBX" --assumeyes create --image "$DOCKER_REG_URI/$image" assert_failure + lines=("${stderr_lines[@]}") assert_line --index 0 "Error: failed to pull image $DOCKER_REG_URI/$image" assert_line --index 1 "If it was a private image, log in with: podman login $DOCKER_REG_URI" assert_line --index 2 "Use 'toolbox --verbose ...' for further details." - assert [ ${#lines[@]} -eq 3 ] + assert [ ${#stderr_lines[@]} -eq 3 ] - run "$TOOLBX" --assumeyes create --authfile "$authfile" --image "$DOCKER_REG_URI/$image" + run --separate-stderr "$TOOLBX" --assumeyes create --authfile "$authfile" --image "$DOCKER_REG_URI/$image" rm "$authfile"