Home | History | Annotate | Download | only in tests
      1 #!/bin/bash
      2 
      3 [ -f testing.sh ] && . testing.sh
      4 
      5 #testing "name" "command" "result" "infile" "stdin"
      6 
      7 testing "touch" "touch walrus && [ -e walrus ] && echo yes" "yes\n" "" ""
      8 testing "1 2 3" "touch one two three && rm one two three && echo yes" "yes\n" \
      9   "" ""
     10 testing "-c" "touch -c walrus && [ -e walrus ] && echo yes" "yes\n" "" ""
     11 testing "-c missing" "touch -c warrus && [ ! -e warrus ] && echo yes" \
     12   "yes\n" "" ""
     13 
     14 testing "-t" \
     15   "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
     16   "20120123-123400.000000000\n" "" ""
     17 
     18 # Yes, the year could roll over while you're running this test. I do not care.
     19 testing "-t MMDDhhmm" \
     20   "touch -t 01231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
     21   "$(date +%Y)-01-23:12-34-00\n" "" ""
     22 
     23 testing "-t YYMMDDhhmm" \
     24   "touch -t 2101231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
     25   "$(date +%C)21-01-23:12-34-00\n" "" ""
     26 
     27 testing "-t CCYYMMDDhhmm" \
     28   "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
     29   "20120123-123400.000000000\n" "" ""
     30 
     31 testing "-t seconds" \
     32   "touch -t 201201231234.56 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
     33   "20120123-123456.000000000\n" "" ""
     34 
     35 testing "-t -" "touch -t 200109081946.40 - > walrus && date -r walrus +%s" \
     36    "1000000000\n" "" ""
     37 
     38 testing "-t nanoseconds" \
     39   "touch -t 201201231234.56123456789 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
     40   "20120123-123456.123456789\n" "" ""
     41 
     42 testing "-d" \
     43   "touch -d 2009-02-13T23:31:30Z walrus && date -r walrus +%s" \
     44   "1234567890\n" "" ""
     45 
     46 testing "-d with space" \
     47   "touch -d '2009-02-13 23:31:30Z' walrus && date -r walrus +%s" \
     48   "1234567890\n" "" ""
     49 
     50 testing "-d nanoseconds" \
     51   "touch -d 2009-02-13T23:31:30.123456789Z walrus && date -r walrus +%s.%N" \
     52   "1234567890.123456789\n" "" ""
     53 
     54 testing "-r" \
     55   "touch -r walrus walrus2 && date -r walrus2 +%s.%N" \
     56    "1234567890.123456789\n" "" ""
     57 
     58 # Yes, the year could roll over while you're running this test. I do not care.
     59 testing "-t MMDDhhmm" \
     60   "touch -t 01231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
     61   "$(date +%Y)-01-23:12-34-00\n" "" ""
     62 
     63 testing "-t CCMMDDhhmm" \
     64   "touch -t 2101231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
     65   "$(date +%C)21-01-23:12-34-00\n" "" ""
     66 
     67 testing "-a" "touch -t 197101020304 walrus &&
     68     touch -t 197203040506 -a walrus && stat -c '%X %Y' walrus" \
     69     "68562360 31662240\n" "" ""
     70 testing "-m" "touch -t 197101020304  walrus &&
     71     touch -t 197203040506 -m walrus && stat -c '%X %Y' walrus" \
     72     "31662240 68562360\n" "" ""
     73 testing "-am" "touch -t 197101020304 walrus &&
     74     touch -t 197203040506 -am walrus && stat -c '%X %Y' walrus" \
     75     "68562360 68562360\n" "" ""
     76 
     77 #testing "-t"
     78 rm walrus walrus2
     79