1#!/bin/bash 2 3[ -f testing.sh ] && . testing.sh 4 5if [ "$(id -u)" -ne 0 ] 6then 7 echo "$SHOWSKIP: losetup (not root)" 8 continue 2>/dev/null 9 exit 10fi 11 12#testing "name" "command" "result" "infile" "stdin" 13 14truncate -s 1M blah.img && 15FILE="$(readlink -f blah.img)" 16DEV="$(printf '%04d' $(stat -t blah.img | awk '{print $7}'))" 17NODE="$(awk '{print $7}')" 18 19losetup -f 20losetup -f -s 21losetup -f file 22testing "cat" "cat && echo yes" "oneyes\n" "" "one" 23testing "cat -" "cat - && echo yes" "oneyes\n" "" "one" 24testing "cat file1 file2" "cat file1 file2" "one\ntwo\n" "" "" 25testing "cat - file" "cat - file1" "zero\none\n" "" "zero\n" 26testing "cat file -" "cat file1 -" "one\nzero\n" "" "zero\n" 27 28testing "cat file1 notfound file2" \ 29 "cat file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \ 30 "one\ntwo\ncat: notfound: No such file or directory\n" "" "" 31 32testing "cat file1" \ 33 "cat /proc/self/exe > file1 && cmp /proc/self/exe file1 && echo yes" \ 34 "yes\n" "" "" 35 36testing "cat - file1" \ 37 "cat - file1 | diff -a -U 0 - file1 | tail -n 1" \ 38 "-hello\n" "" "hello\n" 39 40testing "cat > /dev/full" \ 41 "cat - > /dev/full 2>stderr && echo ok; cat stderr; rm stderr" \ 42 "cat: xwrite: No space left on device\n" "" "zero\n" 43 44losetup -d 45 46rm blah.img 47