aboutsummaryrefslogtreecommitdiff
path: root/tests/touch.test
blob: da6fe99a967edcf9ee2c79eee6c0933d13b1ca2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

testing "touch" "touch walrus && [ -e walrus ] && echo yes" "yes\n" "" ""
testing "1 2 3" "touch one two three && rm one two three && echo yes" "yes\n" \
  "" ""
testing "-c" "touch -c walrus && [ -e walrus ] && echo yes" "yes\n" "" ""
testing "-c missing" "touch -c warrus && [ ! -e warrus ] && echo yes" \
  "yes\n" "" ""

testing "-t" \
  "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
  "20120123-123400.000000000\n" "" ""

# Yes, the year could roll over while you're running this test. I do not care.
testing "-t MMDDhhmm" \
  "touch -t 01231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
  "$(date +%Y)-01-23:12-34-00\n" "" ""

testing "-t YYMMDDhhmm" \
  "touch -t 2101231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
  "$(date +%C)21-01-23:12-34-00\n" "" ""

testing "-t CCYYMMDDhhmm" \
  "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
  "20120123-123400.000000000\n" "" ""

testing "-t seconds" \
  "touch -t 201201231234.56 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
  "20120123-123456.000000000\n" "" ""

testing "-t -" "touch -t 200109081946.40 - > walrus && date -r walrus +%s" \
   "1000000000\n" "" ""

testing "-t nanoseconds" \
  "touch -t 201201231234.56123456789 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
  "20120123-123456.123456789\n" "" ""

testing "-d" \
  "touch -d 2009-02-13T23:31:30Z walrus && date -r walrus +%s" \
  "1234567890\n" "" ""

testing "-d with space" \
  "touch -d '2009-02-13 23:31:30Z' walrus && date -r walrus +%s" \
  "1234567890\n" "" ""

testing "-d nanoseconds" \
  "touch -d 2009-02-13T23:31:30.123456789Z walrus && date -r walrus +%s.%N" \
  "1234567890.123456789\n" "" ""

testing "-r" \
  "touch -r walrus walrus2 && date -r walrus2 +%s.%N" \
   "1234567890.123456789\n" "" ""

# Yes, the year could roll over while you're running this test. I do not care.
testing "-t MMDDhhmm" \
  "touch -t 01231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
  "$(date +%Y)-01-23:12-34-00\n" "" ""

testing "-t CCMMDDhhmm" \
  "touch -t 2101231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
  "$(date +%C)21-01-23:12-34-00\n" "" ""

testing "-a" "touch -t 197101020304 walrus &&
    touch -t 197203040506 -a walrus && stat -c '%X %Y' walrus" \
    "68562360 31662240\n" "" ""
testing "-m" "touch -t 197101020304  walrus &&
    touch -t 197203040506 -m walrus && stat -c '%X %Y' walrus" \
    "31662240 68562360\n" "" ""
testing "-am" "touch -t 197101020304 walrus &&
    touch -t 197203040506 -am walrus && stat -c '%X %Y' walrus" \
    "68562360 68562360\n" "" ""

#testing "-t"
rm walrus walrus2