du.test 1.9 KB

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