1#!/bin/bash 2 3[ -f testing.sh ] && . testing.sh 4 5# ext stores extended attributes in a way that makes all the numbers in the 6# tests below incorrect. 7# TODO: include a read-only ext file system that we can mount for the tests? 8if [ "$(stat --format %C . 2>/dev/null)" != "?" ]; then 9 echo "$SHOWSKIP: du (SELinux extended attributes present)" 10 return 2>/dev/null 11 exit 12fi 13 14#testing "name" "command" "result" "infile" "stdin" 15 16# we only test with -k since getting POSIX version is variable 17# POSIXLY_CORRECT is sometimes needed, sometimes -P is needed, 18# while -k is the default on most Linux systems 19 20mkdir -p du_test/test du_2/foo 21testing "(no options)" "du -k du_test" "4\tdu_test/test\n8\tdu_test\n" "" "" 22testing "-s" "du -k -s du_test" "8\tdu_test\n" "" "" 23ln -s ../du_2 du_test/xyz 24# "du shall count the size of the symbolic link" 25# The tests assume that like for most POSIX systems symbolic 26# links are stored directly in the inode so that the 27# allocated file space is zero. 28testing "counts symlinks without following" "du -ks du_test" "8\tdu_test\n" "" "" 29testing "-L follows symlinks" "du -ksL du_test" "16\tdu_test\n" "" "" 30ln -s . du_test/up 31testing "-L avoid endless loop" "du -ksL du_test" "16\tdu_test\n" "" "" 32rm du_test/up 33# if -H and -L are specified, the last takes priority 34testing "-HL follows symlinks" "du -ksHL du_test" "16\tdu_test\n" "" "" 35testing "-H does not follow unspecified symlinks" "du -ksH du_test" "8\tdu_test\n" "" "" 36testing "-LH does not follow unspecified symlinks" "du -ksLH du_test" "8\tdu_test\n" "" "" 37testing "-H follows specified symlinks" "du -ksH du_test/xyz" "8\tdu_test/xyz\n" "" "" 38 39rm -rf du_test du_2 40 41