truncate.test 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. SIZE='&& stat -c %s freep'
  5. testing "0" "truncate -s 0 freep $SIZE" "0\n" "" ""
  6. testing "12345" "truncate -s 12345 freep $SIZE" "12345\n" "" ""
  7. testing "1m" "truncate -s 1m freep $SIZE" "1048576\n" "" ""
  8. # We can't test against 0 because Android filesystems use an extra 4KiB for
  9. # extended attributes (SELinux).
  10. testing "is sparse" "truncate -s 1g freep && [ $(stat -c %b freep) -le 8 ] &&
  11. echo okay" \
  12. "okay\n" "" ""
  13. testing "+" "truncate -s 1k freep && truncate -s +1k freep $SIZE" \
  14. "2048\n" "" ""
  15. testing "-" "truncate -s 4k freep && truncate -s -1k freep $SIZE" \
  16. "3072\n" "" ""
  17. testing "< hit" \
  18. "truncate -s 5k freep && truncate -s \<4k freep $SIZE" "4096\n" "" ""
  19. testing "< miss" \
  20. "truncate -s 4k freep && truncate -s \<6k freep $SIZE" "4096\n" "" ""
  21. testing "> hit" \
  22. "truncate -s 3k freep && truncate -s \>4k freep $SIZE" "4096\n" "" ""
  23. testing "> miss" \
  24. "truncate -s 4k freep && truncate -s \>2k freep $SIZE" "4096\n" "" ""
  25. testing "/" "truncate -s 7k freep && truncate -s /3k freep $SIZE" \
  26. "6144\n" "" ""
  27. testing "%" "truncate -s 7k freep && truncate -s %3k freep $SIZE" \
  28. "9216\n" "" ""