1#!/bin/bash 2 3[ -f testing.sh ] && . testing.sh 4 5#testing "name" "command" "result" "infile" "stdin" 6 7testing "touch" "touch walrus && [ -e walrus ] && echo yes" "yes\n" "" "" 8testing "1 2 3" "touch one two three && rm one two three && echo yes" "yes\n" \ 9 "" "" 10testing "-c" "touch -c walrus && [ -e walrus ] && echo yes" "yes\n" "" "" 11testing "-c missing" "touch -c warrus && [ ! -e warrus ] && echo yes" \ 12 "yes\n" "" "" 13 14testing "-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. 19testing "-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 23testing "-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 27testing "-t CCYYMMDDhhmm" \ 28 "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \ 29 "20120123-123400.000000000\n" "" "" 30 31testing "-t seconds" \ 32 "touch -t 201201231234.56 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \ 33 "20120123-123456.000000000\n" "" "" 34 35testing "-t -" "TZ=utc touch -t 200109090146.40 - > walrus && TZ=utc date -r walrus +%s" \ 36 "1000000000\n" "" "" 37 38toyonly 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 42testing "-d" \ 43 "touch -d 2009-02-13T23:31:30Z walrus && date -r walrus +%s" \ 44 "1234567890\n" "" "" 45 46testing "-d with space" \ 47 "touch -d '2009-02-13 23:31:30Z' walrus && date -r walrus +%s" \ 48 "1234567890\n" "" "" 49 50testing "-d nanoseconds" \ 51 "touch -d 2009-02-13T23:31:30.123456789Z walrus && date -r walrus +%s.%N" \ 52 "1234567890.123456789\n" "" "" 53 54testing "-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. 59testing "-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 63testing "-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 67testing "-a" "TZ=utc touch -t 197101020304 walrus && 68 TZ=utc touch -t 197203040506 -a walrus && TZ=utc stat -c '%X %Y' walrus" \ 69 "68533560 31633440\n" "" "" 70testing "-m" "TZ=utc touch -t 197101020304 walrus && 71 TZ=utc touch -t 197203040506 -m walrus && TZ=utc stat -c '%X %Y' walrus" \ 72 "31633440 68533560\n" "" "" 73testing "-am" "TZ=utc touch -t 197101020304 walrus && 74 TZ=utc touch -t 197203040506 -am walrus && TZ=utc stat -c '%X %Y' walrus" \ 75 "68533560 68533560\n" "" "" 76 77rm walrus walrus2 78