toybox/tests/du.test
<<
>>
Prefs
   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# darwin stores empty directories in the inode itself, making all the numbers
  15# in the tests below 0. (TODO this is not the right fix.)
  16if [ "$(uname)" == "Darwin" ]; then
  17  echo "$SHOWSKIP: du (Darwin stores empty directories in inode)"
  18  return 2>/dev/null
  19  exit
  20fi
  21
  22#testing "name" "command" "result" "infile" "stdin"
  23
  24# we only test with -k since getting POSIX version is variable
  25# POSIXLY_CORRECT is sometimes needed, sometimes -P is needed,
  26# while -k is the default on most Linux systems
  27
  28mkdir -p du_test/test du_2/foo
  29testing "(no options)" "du -k du_test" "4\tdu_test/test\n8\tdu_test\n" "" ""
  30testing "-s" "du -k -s du_test" "8\tdu_test\n" "" ""
  31ln -s ../du_2 du_test/xyz
  32# "du shall count the size of the symbolic link"
  33# The tests assume that like for most POSIX systems symbolic
  34# links are stored directly in the inode so that the
  35# allocated file space is zero.
  36testing "counts symlinks without following" "du -ks du_test" "8\tdu_test\n" "" ""
  37testing "-L follows symlinks" "du -ksL du_test" "16\tdu_test\n" "" ""
  38ln -s . du_test/up
  39testing "-L avoid endless loop" "du -ksL du_test" "16\tdu_test\n" "" ""
  40rm du_test/up
  41# if -H and -L are specified, the last takes priority
  42testing "-HL follows symlinks" "du -ksHL du_test" "16\tdu_test\n" "" ""
  43testing "-H does not follow unspecified symlinks" "du -ksH du_test" "8\tdu_test\n" "" ""
  44testing "-LH does not follow unspecified symlinks" "du -ksLH du_test" "8\tdu_test\n" "" ""
  45testing "-H follows specified symlinks" "du -ksH du_test/xyz" "8\tdu_test/xyz\n" "" ""
  46
  47rm -rf du_test du_2
  48