]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (fdisk) avoid hardcoding of errno string
authorPatrick Steinhardt <ps@pks.im>
Fri, 23 Aug 2019 13:32:58 +0000 (15:32 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 27 Aug 2019 12:25:32 +0000 (14:25 +0200)
The test fdisk/oddinput hardcodes strings returned by strerror(3P) for
both the errors ENOENT and ENOTTY. As these strings are unportable,
convert the tests to use the test_strerror helper instead to convert
them with sed(1).

Signed-off-by: Patrick Steinhardt <ps@pks.im>
tests/expected/fdisk/oddinput
tests/helpers/test_strerror.c
tests/ts/fdisk/oddinput

index 2fccc6cd58fd1401a33c76a1aaba38a18509dc38..219e98b67c7d7db3f6bd44dc8817084fb351bc4d 100644 (file)
@@ -6,6 +6,6 @@ Units: cylinders of 16065 * 512 = 8225280 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Nonexistent file
-fdisk: cannot open _a_file_that_does_not_exist_: No such file or directory
+fdisk: cannot open _a_file_that_does_not_exist_: ENOENT
 Too small file
-fdisk: cannot open oddinput.toosmall: Inappropriate ioctl for device
+fdisk: cannot open oddinput.toosmall: ENOTTY
index 1919698ebfebc88fed6dce692a831679be15ca18..a063b116510277a5b9546f980250696b2ef93bc2 100644 (file)
@@ -18,6 +18,8 @@ static struct {
        const char *str;
        int error;
 } errors[] = {
+       E(ENOENT),
+       E(ENOTTY),
        E(EILSEQ)
 };
 
index 06792426494c0960ad3e498decf39a83f4c032bb..7b0c8bfd4b494482ca3e9e86579c6b14340e14fa 100755 (executable)
@@ -38,10 +38,12 @@ ts_log "Empty image listing" # this should report empty partition table
 $TS_CMD_FDISK -c=dos -u=cylinders -l ${TEST_IMAGE_NAME} 2>&1 | sed -e "s/${TEST_IMAGE_NAME//\//\\/}/testimage/" >> $TS_OUTPUT
 
 ts_log "Nonexistent file" # this originally does absolutely nothing
-$TS_CMD_FDISK -c=dos -u=cylinders -l _a_file_that_does_not_exist_ >> $TS_OUTPUT 2>&1
+$TS_CMD_FDISK -c=dos -u=cylinders -l _a_file_that_does_not_exist_ 2>&1 |
+    sed -e "s@$($TS_HELPER_STRERROR ENOENT)@ENOENT@" >> $TS_OUTPUT
 
 ts_log "Too small file" # same here
 echo  "This file is too small" >> oddinput.toosmall
-$TS_CMD_FDISK -c=dos -u=cylinders -l oddinput.toosmall >> $TS_OUTPUT 2>&1
+$TS_CMD_FDISK -c=dos -u=cylinders -l oddinput.toosmall 2>&1 |
+    sed -e "s@$($TS_HELPER_STRERROR ENOTTY)@ENOTTY@" >> $TS_OUTPUT
 rm oddinput.toosmall
 ts_finalize