blob: da6fe99a967edcf9ee2c79eee6c0933d13b1ca2e [file] [log] [blame]
Rob Landley8d9b9ca2013-05-27 13:39:03 -05001#!/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" "" ""
Rob Landley336c44a2016-03-02 15:20:04 -06008testing "1 2 3" "touch one two three && rm one two three && echo yes" "yes\n" \
Rob Landley8d9b9ca2013-05-27 13:39:03 -05009 "" ""
Rob Landley336c44a2016-03-02 15:20:04 -060010testing "-c" "touch -c walrus && [ -e walrus ] && echo yes" "yes\n" "" ""
11testing "-c missing" "touch -c warrus && [ ! -e warrus ] && echo yes" \
Rob Landley8d9b9ca2013-05-27 13:39:03 -050012 "yes\n" "" ""
13
Davis Mosenkovs00385e82016-04-20 14:44:13 -070014testing "-t" \
15 "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
16 "20120123-123400.000000000\n" "" ""
17
Rob Landley354ff682016-10-19 20:51:28 -050018# 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
Davis Mosenkovs00385e82016-04-20 14:44:13 -070031testing "-t seconds" \
32 "touch -t 201201231234.56 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
33 "20120123-123456.000000000\n" "" ""
34
Rob Landley9c0ad322016-10-20 16:35:13 -050035testing "-t -" "touch -t 200109081946.40 - > walrus && date -r walrus +%s" \
36 "1000000000\n" "" ""
37
Davis Mosenkovs00385e82016-04-20 14:44:13 -070038testing "-t nanoseconds" \
39 "touch -t 201201231234.56123456789 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
40 "20120123-123456.123456789\n" "" ""
41
Rob Landley336c44a2016-03-02 15:20:04 -060042testing "-d" \
Rob Landley671146c2015-07-04 03:49:53 -050043 "touch -d 2009-02-13T23:31:30Z walrus && date -r walrus +%s" \
44 "1234567890\n" "" ""
45
Rob Landley354ff682016-10-19 20:51:28 -050046testing "-d with space" \
47 "touch -d '2009-02-13 23:31:30Z' walrus && date -r walrus +%s" \
48 "1234567890\n" "" ""
49
Rob Landley336c44a2016-03-02 15:20:04 -060050testing "-d nanoseconds" \
Rob Landley671146c2015-07-04 03:49:53 -050051 "touch -d 2009-02-13T23:31:30.123456789Z walrus && date -r walrus +%s.%N" \
52 "1234567890.123456789\n" "" ""
53
Rob Landley336c44a2016-03-02 15:20:04 -060054testing "-r" \
Rob Landley671146c2015-07-04 03:49:53 -050055 "touch -r walrus walrus2 && date -r walrus2 +%s.%N" \
56 "1234567890.123456789\n" "" ""
57
Rob Landley9f3d8aa2016-10-18 04:10:01 -050058# 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
Rob Landley354ff682016-10-19 20:51:28 -050063testing "-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
Elliott Hughes36b6eb72017-04-06 14:44:45 -070067testing "-a" "touch -t 197101020304 walrus &&
68 touch -t 197203040506 -a walrus && stat -c '%X %Y' walrus" \
69 "68562360 31662240\n" "" ""
70testing "-m" "touch -t 197101020304 walrus &&
71 touch -t 197203040506 -m walrus && stat -c '%X %Y' walrus" \
72 "31662240 68562360\n" "" ""
73testing "-am" "touch -t 197101020304 walrus &&
74 touch -t 197203040506 -am walrus && stat -c '%X %Y' walrus" \
75 "68562360 68562360\n" "" ""
Rob Landley354ff682016-10-19 20:51:28 -050076
Rob Landley336c44a2016-03-02 15:20:04 -060077#testing "-t"
Rob Landley671146c2015-07-04 03:49:53 -050078rm walrus walrus2