Context
While testing a keepass2
installation procedure using bats
testing in bash, I noticed that the output of a command in terminal differs from the output that is captured in a bats
test. In terminal the command keepass2 --version
returns:
Gtk-Message: 15:29:44.377: Failed to load module "canberra-gtk-module"
KeePass 2.45
Copyright © 2003-2020 Dominik Reichl
Whereas the test output of the following test:
@test "Checking keepass2 version responds with Failed to load module canberra-gtk-module." {
COMMAND_OUTPUT=$(keepass2 --version)
EXPECTED_OUTPUT='Gtk-Message: 15:29:44.377: Failed to load module "canberra-gtk-module"
KeePass 2.45
Copyright © 2003-2020 Dominik Reichl'
assert_equal "$COMMAND_OUTPUT" "$EXPECTED_OUTPUT"
}
is:
✗ Checking keepass2 version does not respond with Failed to load module canberra-gtk-module.
(from function `assert_equal' in file test/post_setup/../../test/libs/bats-assert/src/assert.bash, line 91,
in test file test/post_setup/test_apt_install_keepass2_postsetup.bats, line 68)
`assert_equal "$COMMAND_OUTPUT" "$EXPECTED_OUTPUT"' failed
Gtk-Message: 15:51:27.775: Failed to load module "canberra-gtk-module"
/home/a/Documents/git/Productivity-setup/test/post_setup/../../test/libs/bats-assert/src/assert.bash: line 65: [: KeePass 2.45
Copyright © 2003-2020 Dominik Reichl: binary operator expected
-- values do not equal --
expected (3 lines):
Gtk-Message: 15:29:44.377: Failed to load module "canberra-gtk-module"
KeePass 2.45
Copyright © 2003-2020 Dominik Reichl
actual (2 lines):
KeePass 2.45
Copyright © 2003-2020 Dominik Reichl
--
So the bats
test thinks the output of the command only contains the last 2 lines of the command line output of the same command, whereas I would expect bats to capture the full 3 lines of output that I see in the command line when running keepass2 --version
.
Question
How can I capture the Gtk-Message: 15:29:44.377: Failed to load module "canberra-gtk-module"
line that is shown in the command line for command keepass2 --version
, in the bats test?
Aucun commentaire:
Enregistrer un commentaire