aboutsummaryrefslogtreecommitdiff
path: root/tests/mventry/testscript
blob: c6cbf45e63c31b46e99f84aff599a21ffbee33e9 (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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# file      : tests/mventry/testscript
# license   : MIT; see accompanying LICENSE file

: file
:
{
  : non-existing
  :
  $* a b 2>- == 1

  : over
  :
  {
    : non-existing
    :
    echo 'foo' >=a &!a;
    $* a b &b;
    cat b >'foo';
    test -f a == 1

    : existing-file
    :
    echo 'foo' >=a &!a;
    echo 'bar' >=b;
    $* a b;
    cat b >'foo';
    test -f a == 1

    : existing-dir
    :
    echo 'foo' >=a;
    mkdir b;
    $* a b 2>- == 1
  }

  : to-dir
  :
  echo 'foo' >=a &!a;
  mkdir b;
  $* a b/ &b/a;
  cat b/a >'foo';
  test -f a == 1
}

: dir
:
{
  : over
  {
    : non-existing
    :
    mkdir -p a/b &!a/b/ &!a/;
    echo 'foo' >=a/c &!a/c;
    $* a b &b/ &b/c &b/b/;
    cat b/c >'foo';
    test -d b/b;
    test -d a == 1

    : empty-dir
    :
    mkdir -p a/b &!a/b/ &!a/;
    echo 'foo' >=a/c &!a/c;
    mkdir b;
    $* a b &b/c &b/b/;
    cat b/c >'foo';
    test -d b/b;
    test -d a == 1

    : non-empty-dir
    :
    mkdir -p a/b;
    mkdir -p b/d;
    $* a b 2>- == 1

    : existing-file
    :
    mkdir a;
    touch b;
    $* a b 2>- == 1
  }

  : to-dir
  :
  mkdir a &!a/;
  mkdir b;
  $* a b/ &b/a/;
  test -d b/a;
  test -f a == 1
}

: symlink
:
: If we are not cross-testing let's test renaming symlynks from and over. 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')
    lns = ln -s a b
  else
    echo 'yes' >=a
    if cmd /C 'mklink b a' >- 2>- &?b && cat b >'yes'
      lns = cmd /C 'mklink b a' >-
    end

    jnc = cmd /C 'mklink /J b a' >-
  end

  : symlink
  :
  if! $empty($lns)
  {
    : file
    :
    {
      : from
      :
      : Make sure that if source is a symlink it refers the same target after
      : rename.
      :
      echo 'foo' >=a;
      $lns &!b;
      $* b c &c;
      test -f a;
      test -f b == 1;
      echo 'bar' >=a;
      cat c >'bar'

      : to
      :
      : Make sure that if destination is a symlink it is get overwritten and
      : it's target stays intact.
      :
      echo 'foo' >=a;
      $lns &b;
      echo 'bar' >=c &!c;
      $* c b;
      cat a >'foo';
      test -f c == 1;
      echo 'baz' >=a;
      cat b >'bar'

      : over-existing-dir
      :
      echo 'foo' >=a;
      $lns &b;
      mkdir c;
      $* b c 2>- == 1
    }

    : dir
    :
    {
      : from
      :
      : Make sure that if source is a symlink it refers the same target after
      : rename.
      :
      mkdir -p a;
      $lns &!b;
      $* b c &c;
      touch a/b;
      test -f c/b;
      test -d b == 1

      : to
      :
      : Make sure that if destination is a symlink it is get overwritten and
      : it's target stays intact.
      :
      mkdir -p a;
      $lns;
      echo 'foo' >=c &!c;
      $* c b &b;
      cat b >'foo';
      test -d a;
      test -f c == 1

      : over-existing-dir
      :
      mkdir a;
      $lns &b;
      mkdir c;
      $* b c 2>- == 1
    }
  }

  : junction
  :
  if! $empty($jnc)
  {
    : from
    :
    : Make sure that if source is a junction it refers the same target after
    : rename.
    :
    mkdir -p a;
    $jnc &!b;
    $* b c &c;
    touch a/b;
    test -f c/b;
    test -d b == 1

    : to
    :
    : Make sure that if destination is a junction it is get overwritten and
    : it's target stays intact.
    :
    mkdir -p a;
    $jnc;
    echo 'foo' >=c &!c;
    $* c b &b;
    cat b >'foo';
    test -d a;
    test -f c == 1

    : over-existing-dir
    :
    mkdir a;
    $jnc &b;
    mkdir c;
    $* b c 2>- == 1
  }
}

: different-fs
:
: Note that nested tests may fail for cross-testing as the directory path will
: unlikelly be usable on both host (build2 driver) and target (test driver)
: platforms.
:
if! $empty($config.libbutl.test.rename.dir)
{
  wd = $config.libbutl.test.rename.dir/libbutl-rename
  +rm -rf $wd
  +mkdir $wd

  : file
  :
  {
    : over-non-existing
    :
    {
      wd = "$wd/$@";
      mkdir -p $wd;
      b = $wd/b;

      echo 'foo' >=a &!a;
      $* a $b;
      cat $b >'foo';
      test -f a == 1
    }

    : over-file
    :
    {
      wd = "$wd/$@";
      mkdir -p $wd;
      b = $wd/b;

      touch $b;
      echo 'foo' >=a &!a;
      $* a $b;
      cat $b >'foo';
      test -f a == 1
    }
  }

  : dir
  :
  : Test that renaming directory to different fs/drive expectedly fails.
  :
  {
    wd = "$wd/$@";
    mkdir -p $wd;
    b = $wd/b;

    mkdir a;
    $* a $b 2>- == 1
  }

  -rm -rf $wd
}