toybox/tests/truncate.test
<<
>>
Prefs
   1#!/bin/bash
   2
   3[ -f testing.sh ] && . testing.sh
   4
   5#testing "name" "command" "result" "infile" "stdin"
   6
   7SIZE='&& stat -c %s freep'
   8testing "0" "truncate -s 0 freep $SIZE" "0\n" "" ""
   9testing "12345" "truncate -s 12345 freep $SIZE" "12345\n" "" ""
  10testing "1m" "truncate -s 1m freep $SIZE" "1048576\n" "" ""
  11# We can't test against 0 because Android filesystems use an extra 4KiB for
  12# extended attributes (SELinux). We recreate the file because macOS behavior
  13# is a bit weird; for some file sizes (12345, in this example) blocks will
  14# have been allocated that aren't deallocated by the 1g extension.
  15rm freep; touch freep
  16testing "is sparse" "truncate -s 1g freep && [ $(stat -c %b freep) -le 8 ] &&
  17  echo okay" \
  18        "okay\n" "" ""
  19testing "+" "truncate -s 1k freep && truncate -s +1k freep $SIZE" \
  20        "2048\n" "" ""
  21testing "-" "truncate -s 4k freep && truncate -s -1k freep $SIZE" \
  22        "3072\n" "" ""
  23testing "< hit" \
  24        "truncate -s 5k freep && truncate -s \<4k freep $SIZE" "4096\n" "" ""
  25testing "< miss" \
  26        "truncate -s 4k freep && truncate -s \<6k freep $SIZE" "4096\n" "" ""
  27testing "> hit" \
  28        "truncate -s 3k freep && truncate -s \>4k freep $SIZE" "4096\n" "" ""
  29testing "> miss" \
  30        "truncate -s 4k freep && truncate -s \>2k freep $SIZE" "4096\n" "" ""
  31testing "/" "truncate -s 7k freep && truncate -s /3k freep $SIZE" \
  32        "6144\n" "" ""
  33testing "%" "truncate -s 7k freep && truncate -s %3k freep $SIZE" \
  34        "9216\n" "" ""
  35