aboutsummaryrefslogtreecommitdiff
path: root/tests/path-entry/testscript
blob: 3ac363b0a797eb7ca9dbf1830d6f9231de857129 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# file      : tests/path-entry/testscript
# license   : MIT; see accompanying LICENSE file

# Note that atime tests may fail if running on a mount with noatime (for
# example, this happens on NetBSD).

: existing
:
{
  : file
  :
  : Note that the newline character is translated into 2 characters being
  : printed on Windows. This why we exclude it, to get consistent behavior on
  : both POSIX and Windows.
  :
  {
    cat <:'abc' >=f;
    $* f >>~%EOO%
      type: regular
      size: 3
      %.+
      EOO
  }

  : dir
  :
  : Note that the size value is meaningless for directory entries.
  :
  {
    mkdir -p d;
    $* d >>~%EOO%
      type: directory
      %.+
      EOO
  }

  : followed-symlink
  :
  {
    cat <:'abc' >=f;
    ln -s f l;
    $* -l l >>~%EOO%
      type: regular
      size: 3
      %.+
      EOO
  }

  : symlink
  :
  : If we are not cross-testing let's test if symlinks are properly followed.
  : On Windows that involves mklink command usability test. If we fail to
  : create a trial link (say because we are not in the Developer Mode and are
  : running non-elevated console), then the test group will be silently
  : skipped.
  :
  if ($test.target == $build.host)
  {
    +if ($cxx.target.class != 'windows')
      lnf = [cmdline] ^ln -s t l &l
      lnd = [cmdline] $lnf
    else
      echo 'yes' >=t
      if cmd /C 'mklink l t' >- 2>- &?l && cat l >'yes'
        lnf = [cmdline] cmd /C 'mklink l t' &l >-
        lnd = [cmdline] cmd /C 'mklink /D l t' &l >-
      end

      jnc = [cmdline] cmd /C 'mklink /J l t' &l >-
    end

    : symlink
    :
    if! $empty($lnf)
    {
      : file
      :
      {
        : get-info
        :
        : Test that the target type, size, permissions and file times are
        : obtained via a symlink.
        :
        {
          cat <:'abc' >=t;
          $lnf;
          $* -p 400 -m '2020-03-05 00:00:00' -a '2020-03-05 00:00:01' t | set ti;
          $* -l l >"$ti"
        }

        : set-info
        :
        : Test that permissions and file times are set via a symlink.
        :
        {
          cat <:'abc' >=t;
          $lnf;
          $* -p 400 -m '2020-03-05 00:00:00' -a '2020-03-05 00:00:01' l | set ti;
          sed -n -e 's/permissions: (.+)/\1/p' <"$ti" >~/'4.{2}'/;
          sed -n -e 's/mtime: (.+)/\1/p' <"$ti" >'2020-03-05 00:00:00';
          sed -n -e 's/atime: (.+)/\1/p' <"$ti" >'2020-03-05 00:00:01'
        }

        : touch
        :
        : Test that a symlink touch touches the target.
        :
        {
          cat <:'abc' >=t;
          $lnf;
          $* t | set ti;
          sleep 2;
          $* -t l | set li;
          if ("$ti" == "$li")
            exit "link touch doesn't change target"
          end
        }
      }

      : dir
      :
      {
        : get-info
        :
        : Test that the target type, size, permissions and file times are
        : obtained via a symlink.
        :
        {
          mkdir t;
          $lnd;
          $* -p 400 -m '2020-03-05 00:00:00' -a '2020-03-05 00:00:01' t | set ti;
          $* -l l >"$ti"
        }

        : set-info
        :
        : Test that permissions and file times are set via a symlink.
        :
        {
          mkdir t;
          $lnd;
          $* -p 400 -m '2020-03-05 00:00:00' -a '2020-03-05 00:00:01' l | set ti;
          sed -n -e 's/permissions: (.+)/\1/p' <"$ti" >~/'4.{2}'/;
          sed -n -e 's/mtime: (.+)/\1/p' <"$ti" >'2020-03-05 00:00:00';
          sed -n -e 's/atime: (.+)/\1/p' <"$ti" >'2020-03-05 00:00:01'
        }
      }
    }

    : junction
    :
    if! $empty($jnc)
    {
      : get-info
      :
      : Test that the target type, size, permissions and file times are
      : obtained via a junction.
      :
      {
        mkdir t;
        $jnc;

        # Pass the absolute path so the junction's target path matches.
        #
        $* -p 400 -m '2020-03-05 00:00:00' -a '2020-03-05 00:00:01' $~/t | \
        set ti;

        $* -l l >"$ti"
      }

      : set-info
      :
      : Test that permissions and file times are set via a junction.
      :
      {
        mkdir t;
        $jnc;
        $* -p 400 -m '2020-03-05 00:00:00' -a '2020-03-05 00:00:01' l | set ti;
        sed -n -e 's/permissions: (.+)/\1/p' <"$ti" >~/'4.{2}'/;
        sed -n -e 's/mtime: (.+)/\1/p' <"$ti" >'2020-03-05 00:00:00';
        sed -n -e 's/atime: (.+)/\1/p' <"$ti" >'2020-03-05 00:00:01'
      }
    }
  }
}

: non-existent
:
$* f == 1