Rob Landley | 8d9b9ca | 2013-05-27 13:39:03 -0500 | [diff] [blame] | 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" "" "" |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 8 | testing "1 2 3" "touch one two three && rm one two three && echo yes" "yes\n" \ |
Rob Landley | 8d9b9ca | 2013-05-27 13:39:03 -0500 | [diff] [blame] | 9 | "" "" |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 10 | testing "-c" "touch -c walrus && [ -e walrus ] && echo yes" "yes\n" "" "" |
| 11 | testing "-c missing" "touch -c warrus && [ ! -e warrus ] && echo yes" \ |
Rob Landley | 8d9b9ca | 2013-05-27 13:39:03 -0500 | [diff] [blame] | 12 | "yes\n" "" "" |
| 13 | |
Davis Mosenkovs | 00385e8 | 2016-04-20 14:44:13 -0700 | [diff] [blame] | 14 | testing "-t" \ |
| 15 | "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \ |
| 16 | "20120123-123400.000000000\n" "" "" |
| 17 | |
Rob Landley | 354ff68 | 2016-10-19 20:51:28 -0500 | [diff] [blame] | 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 | |
Davis Mosenkovs | 00385e8 | 2016-04-20 14:44:13 -0700 | [diff] [blame] | 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 | |
Rob Landley | 9c0ad32 | 2016-10-20 16:35:13 -0500 | [diff] [blame] | 35 | testing "-t -" "touch -t 200109081946.40 - > walrus && date -r walrus +%s" \ |
| 36 | "1000000000\n" "" "" |
| 37 | |
Davis Mosenkovs | 00385e8 | 2016-04-20 14:44:13 -0700 | [diff] [blame] | 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 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 42 | testing "-d" \ |
Rob Landley | 671146c | 2015-07-04 03:49:53 -0500 | [diff] [blame] | 43 | "touch -d 2009-02-13T23:31:30Z walrus && date -r walrus +%s" \ |
| 44 | "1234567890\n" "" "" |
| 45 | |
Rob Landley | 354ff68 | 2016-10-19 20:51:28 -0500 | [diff] [blame] | 46 | testing "-d with space" \ |
| 47 | "touch -d '2009-02-13 23:31:30Z' walrus && date -r walrus +%s" \ |
| 48 | "1234567890\n" "" "" |
| 49 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 50 | testing "-d nanoseconds" \ |
Rob Landley | 671146c | 2015-07-04 03:49:53 -0500 | [diff] [blame] | 51 | "touch -d 2009-02-13T23:31:30.123456789Z walrus && date -r walrus +%s.%N" \ |
| 52 | "1234567890.123456789\n" "" "" |
| 53 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 54 | testing "-r" \ |
Rob Landley | 671146c | 2015-07-04 03:49:53 -0500 | [diff] [blame] | 55 | "touch -r walrus walrus2 && date -r walrus2 +%s.%N" \ |
| 56 | "1234567890.123456789\n" "" "" |
| 57 | |
Rob Landley | 9f3d8aa | 2016-10-18 04:10:01 -0500 | [diff] [blame] | 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 | |
Rob Landley | 354ff68 | 2016-10-19 20:51:28 -0500 | [diff] [blame] | 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 | |
Elliott Hughes | 36b6eb7 | 2017-04-06 14:44:45 -0700 | [diff] [blame] | 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" "" "" |
Rob Landley | 354ff68 | 2016-10-19 20:51:28 -0500 | [diff] [blame] | 76 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 77 | #testing "-t" |
Rob Landley | 671146c | 2015-07-04 03:49:53 -0500 | [diff] [blame] | 78 | rm walrus walrus2 |