diff options
author | Jim Meyering <meyering@redhat.com> | 2011-05-09 22:00:57 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2011-05-10 14:53:32 +0200 |
commit | e47ae2865e20fdc5c8c88921388c91dc671b04c1 (patch) | |
tree | 523f8891380e9d18302ce017342823714588b0e8 /tests/t-local.sh | |
parent | 2c563e8a0ffaf8c02d5b050ee4ac97575bacd8d6 (diff) | |
download | parted-e47ae2865e20fdc5c8c88921388c91dc671b04c1.tar.gz |
tests: avoid subtle shell semantics bug
This bug was causing some root-only tests to be mistakenly skipped.
This bash command will always exit successfully,
i.e., the "return 1" will never happen:
bash -c 'f(){ local f=$(false)||return 1; return 0; }; f'
That's because the assignment always succeeds, and that success
is what determines the return value, not the $(...) command.
This is very counter-intuitive, sigh.
The work-around is to separate the declaration and assignment, as in
local f; f=$(...) || ...
* tests/t-local.sh (new_sdX_): Do that.
(gpt_corrupt_primary_table_): Likewise.
Diffstat (limited to 'tests/t-local.sh')
-rw-r--r-- | tests/t-local.sh | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/t-local.sh b/tests/t-local.sh index 8e2ef07..b9b8b28 100644 --- a/tests/t-local.sh +++ b/tests/t-local.sh @@ -74,7 +74,7 @@ scsi_debug_acquire_lock_() # Otherwise, return 1. new_sdX_() { - local m=$(grep -lw scsi_debug /sys/block/sd*/device/model) || return 1 + local m; m=$(grep -lw scsi_debug /sys/block/sd*/device/model) || return 1 # Remove the /sys/block/ prefix, and then the /device/model suffix. m=${m#/sys/block/} @@ -113,7 +113,7 @@ scsi_debug_setup_() case $new_dev in sd[a-z]) ;; sd[a-z][a-z]) ;; - *) return 1 ;; + *) warn_ $ME_ unexpected device name: $new_dev; return 1 ;; esac local t=/dev/$new_dev wait_for_dev_to_appear_ $t @@ -162,7 +162,8 @@ gpt_corrupt_primary_table_() case $ss in *[^0-9]*) echo "$0: invalid sector size: $ss">&2; return 1;; esac # get the first byte of the name - local orig_pte_name_byte=$(peek_ $dev $(gpt1_pte_name_offset_ $ss)) || return 1 + local orig_pte_name_byte + orig_pte_name_byte=$(peek_ $dev $(gpt1_pte_name_offset_ $ss)) || return 1 local new_byte test x"$orig_pte_name_byte" = xA && new_byte=B || new_byte=A |