tests: Do not occlude subshell error codes when used as input to the test command

When using the output of a subshell as input, its error code is ignored in
the context of "set -e". Many test scripts use grub-shell in a subshell with
output used as an argument to the test command to test for expected output.
Refactor these tests so that the subshell output goes to a shell variable,
so that if the subshell errors the script will immediately exit with an
error code.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Glenn Washburn authored and Daniel Kiper committed 2021-10-14 14:45:10 +02:00
1 parent 5e0a8129ef
commit 9bbcfb71ce
13 files changed
+44 -14

No files matched your search

+6 -1
View File
@@ -41,7 +41,12 @@ echo "hello" > "$outfile"
tar cf "$imgfile" "$outfile"
if [ "$(echo "nativedisk; source '(usb0)/$outfile';" | "${grubshell}" --qemu-opts="-device pci-ohci -drive id=my_usb_disk,file=$imgfile,if=none -device usb-storage,drive=my_usb_disk" | tail -n 1)" != "Hello World" ]; then
v=$(echo "nativedisk; source '(usb0)/$outfile';" |
"${grubshell}" --qemu-opts="-device pci-ohci
-drive id=my_usb_disk,file=$imgfile,if=none
-device usb-storage,drive=my_usb_disk" |
tail -n 1)
if [ "$v" != "Hello World" ]; then
rm "$imgfile"
rm "$outfile"
exit 1