3 [ -f testing.sh ] && . testing.sh
5 #testing "name" "command" "result" "infile" "stdin"
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" \
10 testing "-c" "touch -c walrus && [ -e walrus ] && echo yes" "yes\n" "" ""
11 testing "-c missing" "touch -c warrus && [ ! -e warrus ] && echo yes" \
15 "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
16 "20120123-123400.000000000\n" "" ""
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" "" ""
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" "" ""
27 testing "-t CCYYMMDDhhmm" \
28 "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
29 "20120123-123400.000000000\n" "" ""
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" "" ""
35 testing "-t -" "touch -t 200109081946.40 - > walrus && date -r walrus +%s" \
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" "" ""
43 "touch -d 2009-02-13T23:31:30Z walrus && date -r walrus +%s" \
46 testing "-d with space" \
47 "touch -d '2009-02-13 23:31:30Z' walrus && date -r walrus +%s" \
50 testing "-d nanoseconds" \
51 "touch -d 2009-02-13T23:31:30.123456789Z walrus && date -r walrus +%s.%N" \
52 "1234567890.123456789\n" "" ""
55 "touch -r walrus walrus2 && date -r walrus2 +%s.%N" \
56 "1234567890.123456789\n" "" ""
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" "" ""
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" "" ""
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" "" ""