* test-lib.sh (compare): Define "compare" as a function, not a variable.
* tests/t*.sh: use "compare", not "$compare"
test_expect_success \
'run parted -s FILE mklabel msdos' \
'parted -s $dev mklabel msdos > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
# ----------------------------------------------
# Now, ensure that a simple mklabel command succeeds.
test_expect_success \
'check its "interactive" output' \
- '$compare out exp 1>&2'
+ 'compare out exp 1>&2'
test_expect_success 'create interactive input' 'printf "y\n\n" > in'
test_expect_success \
'check its output -- slightly different here, due to prompts' \
- '$compare out exp'
+ 'compare out exp'
test_done
'test $fail = 0 &&
mv out o2 && sed "s,^Disk .*/$dev:,Disk .../$dev:," o2 > out'
-test_expect_success 'check for expected output' '$compare out exp'
+test_expect_success 'check for expected output' 'compare out exp'
test_done
test_expect_success \
'label the test disk' \
'parted -s $dev mklabel msdos > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
# Expect parted's mkpartfs command to fail.
test_expect_failure \
test_expect_success \
'check for expected failure diagnostic' \
- '$compare out exp'
+ 'compare out exp'
test_expect_success 'clean up, preparing for next test' 'rm $dev out'
test_expect_success \
'label the test disk' \
'parted -s $dev mklabel msdos > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
test_expect_success \
'create an msdos file system' \
'parted -s $dev mkpartfs primary fat32 1 40 > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
test_done
'dd if=/dev/zero "of=$dev" bs=1k count=1 2> /dev/null &&
parted -s "$dev" mklabel msdos > out 2>&1 &&
parted -s "$dev" mkpartfs primary fat32 1 40 >> out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
mount_point="`pwd`/mnt"
'echo "Error: Partition(s) on $dev are being used." > exp'
test_expect_success \
'check for expected failure diagnostic' \
- '$compare out exp'
+ 'compare out exp'
# ==================================================
# Now, test it in interactive mode.
test_expect_success \
'check for expected failure diagnostic' \
- '$compare out exp'
+ 'compare out exp'
test_done
test_expect_success \
'check for expected diagnostic' '
echo Error: File system too small for ext2. > exp &&
- $compare out exp'
+ compare out exp'
test_expect_success \
'create the smallest ext2 partition' '
parted -s $dev mkpartfs primary ext2 10KB 29696B > out 2>&1
- $compare out /dev/null'
+ compare out /dev/null'
# Restore $dev to initial state by writing 1KB of zeroes at the beginning.
# Then relabel.
test_expect_success \
'create another ext2 file system (this would fail for parted-1.8.7)' '
parted -s $dev mkpartfs primary ext2 2 10 > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
test_expect_success \
'create a smaller one; this would succeed for parted-1.8.7' '
dd if=/dev/zero of=$dev bs=1K count=1 conv=notrunc 2> /dev/null &&
parted -s $dev mklabel msdos &&
parted -s $dev mkpartfs primary ext2 2 9 > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
test_done
test_expect_success \
'label the test disk' \
'parted -s $dev mklabel msdos > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
test_expect_success \
'create a partition' \
'create an msdos file system' \
'parted -s $dev mkfs 1 fat32 > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
N=10M
test_expect_success \
test_expect_success \
'label the test disk' \
'parted -s $dev mklabel msdos > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
# test if can create a partition and a filesystem in the same session.
fail=0
'check for expected prompt' \
'echo "Warning: The existing file system will be destroyed and all" \
"data on the partition will be lost. Do you want to continue?" > exp &&
- $compare out2 exp'
+ compare out2 exp'
#############################################################
# Ensure that an invalid file system type elicits a diagnostic.
'check for expected diagnostic' \
'{ echo "parted: invalid token: bogus"
echo "Error: Expecting a file system type."; } > exp &&
- $compare out exp'
+ compare out exp'
#############################################################
# Demonstrate 3-block-group failure for 16+MB EXT2 file system.
test_expect_success \
"try to create an ext2 file system of size $size" \
'parted -s $dev mkpartfs primary ext2 0 ${size}B >out 2>&1'
- test_expect_success 'check for empty output' '$compare out /dev/null'
+ test_expect_success 'check for empty output' 'compare out /dev/null'
}
test_expect_success \
'label the test disk' \
'parted -s $dev mklabel msdos > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
test_expect_success \
'create a partition' \
'parted -s $dev mkpart primary 0 1 > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
test_expect_success \
'create a linux-swap file system' \
'parted -s $dev mkfs 1 "linux-swap(new)" > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
# Extract the byte at offset 451. It must be 0x82, not 0x83.
test_expect_success \
'extract byte 451 (fs-type)' \
'od -t x1 -An -j450 -N1 $dev > out && echo " 82" > exp'
-test_expect_success 'expect it to be 82, not 83' '$compare out exp'
+test_expect_success 'expect it to be 82, not 83' 'compare out exp'
test_done
test_expect_success \
'label the test disk' \
'parted -s $dev mklabel msdos > out 2>&1'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
test_expect_success \
'create two partition' \
parted -s $dev mkpart primary 41s 80s > out 2>&1
'
-test_expect_success 'expect no output' '$compare out /dev/null'
+test_expect_success 'expect no output' 'compare out /dev/null'
test_expect_success \
'write "FAT" where it would cause trouble' \
printf "1:1s:40s:40s:::;\n2:41s:80s:40s:::;\n" > exp
'
-test_expect_success 'expect two partitions' '$compare out exp'
+test_expect_success 'expect two partitions' 'compare out exp'
test_done
'normalize the actual output' \
'sed "s,\r *\r,,;s, $,," out > o2 && mv -f o2 out'
-test_expect_success 'check for expected output' '$compare out exp'
+test_expect_success 'check for expected output' 'compare out exp'
test_done
test_expect_success \
'run parted -s FILE mklabel msdos' \
'parted -s $dev mklabel msdos > out 2>&1'
-test_expect_success 'check for empty output' '$compare out /dev/null'
+test_expect_success 'check for empty output' 'compare out /dev/null'
test_expect_success \
'make an ext2 primary partition' \
'parted -s $dev mkpartfs primary ext2 0 $ORIG_SIZE > out 2>&1'
-test_expect_success 'check for empty output' '$compare out /dev/null'
+test_expect_success 'check for empty output' 'compare out /dev/null'
test_expect_success \
'resize ext2 primary partition' \
'parted -s $dev resize 1 0 $NEW_SIZE > out 2>&1'
-test_expect_success 'check for empty output' '$compare out /dev/null'
+test_expect_success 'check for empty output' 'compare out /dev/null'
test_done
test_expect_success \
'label the test disk as a sun disk' \
'parted -s $dev mklabel sun > out 2>&1'
-test_expect_success 'check for empty output' '$compare out /dev/null'
+test_expect_success 'check for empty output' 'compare out /dev/null'
test_expect_success \
'create a single partition' \
'parted -s $dev unit s mkpart ext2 0s 50s > out 2>&1'
-test_expect_success 'check for empty output' '$compare out /dev/null'
+test_expect_success 'check for empty output' 'compare out /dev/null'
test_expect_success \
'print the partition data in machine readable format' \
test_expect_success \
'check for expected values for the partition' '
printf "$exp:::;\n" > exp &&
- $compare out exp'
+ compare out exp'
test_expect_success \
'set the raid flag' \
'parted -s $dev set 1 raid >out 2>&1'
-test_expect_success 'check for empty output' '$compare out /dev/null'
+test_expect_success 'check for empty output' 'compare out /dev/null'
test_expect_success \
'print the partition data in machine readable format again' \
test_expect_success \
'check for expected values (including raid flag) for the partition' '
printf "$exp:::raid;\n" > exp &&
- $compare out exp'
+ compare out exp'
test_done
"ensure that partprobe succeeds and produces no output" \
'
partprobe -s $dev > out 2>err &&
- $compare err /dev/null &&
+ compare err /dev/null &&
echo "$dev: dvh partitions 9 <17>" > exp &&
- $compare out exp
+ compare out exp
'
test_done
'test $fail = 0 &&
mv out o2 && sed "s,^Disk .*/$dev:,Disk .../$dev:," o2 > out'
-test_expect_success 'check for expected output' '$compare out exp'
+test_expect_success 'check for expected output' 'compare out exp'
test_done
test_expect_success \
'run parted -s "$dev" mklabel msdos' \
'parted -s $dev mklabel msdos > out 2>&1'
-test_expect_success 'check for empty output' '$compare out /dev/null'
+test_expect_success 'check for empty output' 'compare out /dev/null'
test_expect_success \
"determine the map type" \
test_expect_success \
'check its output' \
- '$compare out exp'
+ 'compare out exp'
#
# Multipath Map
test_expect_success \
'run parted -s "$dev" mklabel msdos' \
'parted -s $dev mklabel msdos > out 2>&1'
-test_expect_success 'check for empty output' '$compare out /dev/null'
+test_expect_success 'check for empty output' 'compare out /dev/null'
test_expect_success \
"determine the map type" \
test_expect_success \
'check its output' \
- '$compare out exp'
+ 'compare out exp'
test_done
test_expect_success \
'Compare the real error and the expected one' \
- '$compare out errS'
+ 'compare out errS'
# Test mkpart/mkpartfsin interactive mode.
test_expect_success \
test_expect_success \
'Compare the real error and the expected one' \
- '$compare out errI'
+ 'compare out errI'
done
test_done
test_expect_success \
'run parted -s "$d1" mklabel msdos' \
'parted -s $d1 mklabel msdos > out 2>&1'
-test_expect_success 'check for empty output' '$compare out /dev/null'
+test_expect_success 'check for empty output' 'compare out /dev/null'
test_expect_failure \
'run parted -s "$d1" mkpart primary 1 10' \
test_expect_success 'prepare actual/expected output' \
'emit_expected_diagnostic > exp &&
cut -b1-64 out > k && mv k out'
-test_expect_success 'check for expected output' '$compare exp out'
+test_expect_success 'check for expected output' 'compare exp out'
test_done
cd "$test_dir_rand_" || error "failed to cd to $test_dir_rand_"
if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
- compare='diff -u'
+ compare() { diff -u "$@"; }
elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
- compare='cmp -s'
+ compare() { cmp -s "$@"; }
else
- compare=cmp
+ compare() { cmp "$@"; }
fi