aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/ant/apache-ant-1.9.6/src/etc/testcases/taskdefs/optional/unix/symlink.xml
blob: f039a622faab95cab6b4ca1d6bf521d26e6c7866 (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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<!--

/*
 * Since the initial version of this file was deveolped on the clock on
 * an NSF grant I should say the following boilerplate:
 *
 * This material is based upon work supported by the National Science
 * Foundaton under Grant No. EIA-0196404. Any opinions, findings, and
 * conclusions or recommendations expressed in this material are those
 * of the author and do not necessarily reflect the views of the
 * National Science Foundation.
 */

-->

<project name="symlink-test" basedir="." default="all">

  <!-- 
       Since the symlink task and some of these targets rely on
       calls to exec, it may be possible for the JVM to outrun the 
       execution of the command line  system calls, so this value is
       the number of seconds we give the operating system to
       catch up before executing a task that depends on the 
       completion of previous tasks. This delay is also added to
       the end of each target so junit doesn't go testing things
       before they have finnished (hopefully). Tweak if needed.
  -->

  <property name="delay" value="0"/>
 
  <import file="../../../buildfiletest-base.xml"/>

  <target name="setUp">
    <mkdir dir="${output}" />
  </target>


  <target name="all"
              depends="setUp, test-single, test-delete, test-record, test-recreate, tearDown"/>
        
  <!-- test for action = single -->
  <!-- 
    Creates:
         File: ${output}/symlink.test
         Link: ${output}/singletest
  -->
  <target name="test-single">
    <touch file="${output}/symlink.test"/>
    <symlink resource="${output}/symlink.test" 
             link="${output}/singletest" 
             failonerror="yes"/>
    <sleep seconds="${delay}"/> <!-- make sure OS has time to catch up -->
    <available file="${output}/symlink.test" 
               property="test.single.file.created"/>
    <available file="${output}/singletest" 
               property="test.single.link.created"/>
  </target>



  <!-- test for action = delete  (no calls to command line so no sleep) -->

  <!-- 
    Creates:
         (none)
    Deletes:
         Link: ${output}/singletest
  -->

  <target name="test-delete">
    <touch file="${output}/symlink.test"/>
    <symlink resource="${output}/symlink.test" 
             link="${output}/singletest" 
             failonerror="yes"/>
    <sleep seconds="${delay}"/> <!-- make sure OS has time to catch up -->

    <symlink action="delete" link="${output}/singletest" failonerror="yes"/>
    <symlink action="delete" link="${output}/symlink.test" failonerror="no"/>
    <sleep seconds="${delay}"/> <!-- make sure OS has time to catch up -->

    <available file="${output}/symlink.test" 
               property="test.delete.file.still.there"/>
    <available file="${output}/singletest" 
               property="test.delete.link.still.there"
               value="ERROR: link deletion failed"/>
    
  </target>



  <!-- test for action = record -->

  <!-- 
    Creates:
         Dir:  ${output}/symtest1
         Dir:  ${output}/symtest1/symtest2
         Dir:  ${output}/symtest1/symtest3
         File: ${output}/symtest1/file1
         File: ${output}/symtest1/symtest2/file2
         File: ${output}/symtest1/symtest3/fileA
         File: ${output}/symtest1/symtest3/fileB
         File: ${output}/symtest1/symtest3/fileC
         Link: ${output}/symtest1/link1==>${output}/symtest1/file1
         Link: ${output}/symtest1/link2==>${output}/symtest1/symtest2/file2
         Link: ${output}/symtest1/symtest2/link3==>
                                           ${output}/symtest1/symtest2/file2
         Link: ${output}/symtest1/dirlink==>${output}/symtest1/symtest3
         Link: ${output}/symtest1/dirlink2==>${output}/symtest1/symtest3
         Link: ${output}/symtest1/dirlink3==>${output}/symtest1/symtest3
         File: ${output}/symtest1/recorded.links
         File: ${output}/symtest1/symtest2/recorded.links
    Deletes:
         (none)
  -->

  <target name="test-record">

    <mkdir dir="${output}/symtest1"/>
    <mkdir dir="${output}/symtest1/symtest2"/>
    <mkdir dir="${output}/symtest1/symtest3"/>
    <touch file="${output}/symtest1/file1"/>
    <touch file="${output}/symtest1/symtest2/file2"/>

    <touch file="${output}/symtest1/symtest3/fileA"/>
    <touch file="${output}/symtest1/symtest3/fileB"/>
    <touch file="${output}/symtest1/symtest3/fileC"/>

    <symlink resource="${output}/symtest1/file1" 
             link="${output}/symtest1/link1" 
             failonerror="no" />
    <symlink resource="${output}/symtest1/symtest2/file2" 
             link="${output}/symtest1/link2" 
             failonerror="no" />
    <symlink resource="${output}/symtest1/symtest2/file2" 
             link="${output}/symtest1/symtest2/link3" 
             failonerror="no" />
    <symlink resource="${output}/symtest1/symtest3"
             link="${output}/symtest1/dirlink"
             failonerror="no" />
    <symlink resource="${output}/symtest1/symtest3" 
             link="${output}/symtest1/dirlink2"
             failonerror="no"/>
    <symlink resource="${output}/symtest1/symtest3" 
             link="${output}/symtest1/dirlink3"
             failonerror="no"/>

    <sleep seconds="${delay}"/> <!-- make sure OS has time to catch up -->

    <symlink action="record" linkfilename="recorded.links">
       <fileset dir="${output}/symtest1" includes="**/**"/>
    </symlink>

    <sleep seconds="${delay}"/> <!-- make sure OS has time to catch up -->

    <!-- Test to see if the directories were created -->

    <available file="${output}/symtest1"
               type="dir"
               property="test.record.dir1.created"/>

    <available file="${output}/symtest1/symtest2"
               type="dir"
               property="test.record.dir2.created"/>

    <available file="${output}/symtest1/symtest3"
               type="dir"
               property="test.record.dir3.created"/>

    <!-- Test to see if the Files were created -->

    <available file="${output}/symtest1/file1"
               property="test.record.file1.created"/>

    <available file="${output}/symtest1/symtest2/file2"
               property="test.record.file2.created"/>

    <available file="${output}/symtest1/symtest3/fileA"
               property="test.record.fileA.created"/>

    <available file="${output}/symtest1/symtest3/fileB"
               property="test.record.fileB.created"/>

    <available file="${output}/symtest1/symtest3/fileC"
               property="test.record.fileC.created"/>

    <!-- Test to see if the links were created -->

    <available file="${output}/symtest1/link1"
               property="test.record.link1.created"/>

    <available file="${output}/symtest1/link2"
               property="test.record.link2.created"/>

    <available file="${output}/symtest1/symtest2/link3"
               property="test.record.link3.created"/>

    <available file="${output}/symtest1/dirlink"
               property="test.record.dirlink.created"/>

    <!-- this is redundant for this test, but used in the recreate test -->

    <available file="${output}/symtest1/dirlink2" 
               property="test.record.dirlink2.created"/>

    <!-- Test to see if the linkfiles were created -->

    <available file="${output}/symtest1/recorded.links"
               property="test.record.dir1.recorded"/>

    <available file="${output}/symtest1/symtest2/recorded.links"
               property="test.record.dir2.recorded"/>

    <!-- THIS should not be set -->

    <available file="${output}/symtest1/symtest3/recorded.links"
               property="test.record.dir3.recorded"
               value="ERROR: symtest3/recorded.links should not exist"/>


  </target>

  <!-- test for action = recreate -->

  <!-- 
    Deletes:
         Link: ${output}/symtest1/link1==>${output}/symtest1/file1
         Link: ${output}/symtest1/link2==>${output}/symtest1/symtest2/file2
         Link: ${output}/symtest1/symtest2/link3==>
                                           ${output}/symtest1/symtest2/file2
         Link: ${output}/symtest1/dirlink==>${output}/symtest1/symtest3
         Link: ${output}/symtest1/dirlink3==>${output}/symtest1/symtest3

    Creates
         Link: ${output}/symtest1/dirlink3==>${output}/symtest1/symtest2

    Recreates:
         Link: ${output}/symtest1/link1==>${output}/symtest1/file1
         Link: ${output}/symtest1/link2==>${output}/symtest1/symtest2/file2
         Link: ${output}/symtest1/symtest2/link3==>
                                           ${output}/symtest1/symtest2/file2
         Link: ${output}/symtest1/dirlink==>${output}/symtest1/symtest3

    Should Change:
         Link: ${output}/symtest1/dirlink3==>${output}/symtest1/symtest2
               to
               ${output}/symtest1/dirlink3==>${output}/symtest1/symtest3

    Should Not Create (bug 25181):
         Link: ${output}/symtest1/symtest3/dirlink2==>${output}/symtest1/symtest3
  -->

  <target name="test-recreate" depends="test-record">

    <symlink action="delete" link="${output}/symtest1/link1"/>
    <symlink action="delete" link="${output}/symtest1/link2"/>
    <symlink action="delete" link="${output}/symtest1/symtest2/link3"/>
    <symlink action="delete" link="${output}/symtest1/dirlink"/>
    <!-- dirlink2 intentionally not deleted to test bug 25181 -->
    <symlink action="delete" link="${output}/symtest1/dirlink3"/>

    <sleep seconds="${delay}"/>  <!-- make sure OS has time to catch up -->

    <symlink resource="${output}/symtest1/symtest2" 
             link="${output}/symtest1/dirlink3"
             failonerror="no"/>

    <sleep seconds="${delay}"/>  <!-- make sure OS has time to catch up -->

    <available file="${output}/symtest1/link1"
               property="test.recreate.link1.not.removed"
               value="ERROR: rm -f symtest1/link1 failed"/>

    <available file="${output}/symtest1/link2"
               property="test.recreate.link2.not.removed"
               value="ERROR: rm -f symtest1/link2 failed"/>

    <available file="${output}/symtest1/symtest2/link3"
               property="test.recreate.link3.not.removed"
               value="ERROR: rm -f symtest1/symtest2/link3 failed"/>

     <available file="${output}/symtest1/zdirlink"
               property="test.recreate.zdirlink.not.removed"
               value="ERROR: rm -f symtest1/zdirlink failed"/>

    <sleep seconds="${delay}"/>  <!-- make sure OS has time to do the execs -->

    <symlink action="recreate">
      <fileset dir="${output}/symtest1" includes="**/recorded.links"/>
    </symlink>

    <sleep seconds="${delay}"/>  <!-- make sure OS has time to catch up -->

    <available file="${output}/symtest1/link1"
               property="test.recreate.link1.recreated"/>

    <available file="${output}/symtest1/link2"
               property="test.recreate.link2.recreated"/>

    <available file="${output}/symtest1/symtest2/link3"
               property="test.recreate.link3.recreated"/>

    <available file="${output}/symtest1/dirlink"
               property="test.recreate.dirlink.recreated"/>

    <!-- this should not get set -->
    <available file="${output}/symtest1/symtest3/symtest3" 
               property="test.recreate.dirlink2.recreated.twice"
               value="ERROR: dirlink2 was created a second time (bug 25181)"/>

    <touch file="${output}/symtest1/dirlink3/WhereAmI"/>

    <sleep seconds="${delay}"/>  <!-- make sure OS has time to do the execs -->

    <available file="${output}/symtest1/symtest3/WhereAmI" 
               property="test.recreate.dirlink3.was.altered"/>
  </target>


  <!-- actually tests the symlink methods in FileUtils, but this
       testfixture already has all the necessary envirnment in place
       -->
  <target name="test-fileutils" depends="setUp">
      <mkdir dir="${output}/dir1"/>
      <mkdir dir="${output}/dir2"/>
      <touch file="${output}/file1"/>
      <touch file="${output}/file2"/>
      <symlink link="${output}/dir.there" resource="${output}/dir1"/>
      <symlink link="${output}/dir.notthere" resource="${output}/dir2"/>
      <symlink link="${output}/file.there" resource="${output}/file1"/>
      <symlink link="${output}/file.notthere" resource="${output}/file2"/>
      <delete dir="${output}/dir2"/>
      <delete file="${output}/file2"/>
  </target>


</project>