aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/move-test.xml
blob: 9acac749349038416129374de2e5ab8d31029d36 (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
<?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.
-->
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
  <import file="../antunit-base.xml" />

  <target name="test-move-caseonly">
    <!-- this test is inspired by bugzilla 41948 -->
    <!-- Especially interesting if executed on case-insensitive file systems -->
    <mkdir dir="${output}"/>
    <touch file="${output}/abc"/>
    <move file="${output}/abc" tofile="${output}/aBc"/>
    <fileset dir="${output}" id="myfs">
      <include name="aBc"/>
    </fileset>
    <pathconvert refid="myfs" property="myproperty" setonempty="false"/>
    <au:assertPropertySet name="myproperty" message="abc was not renamed aBc"/>
  </target>

  <target name="test-regex-mapper"
          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=18656">
    <mkdir dir="${input}/AAA/foo"/>
    <touch file="${input}/AAA/foo/bar.txt"/>
    <mkdir dir="${input}/foo/AAA"/>
    <touch file="${input}/foo/bar.txt"/>
    <touch file="${input}/foo/AAA/bar.txt"/>
    <mkdir dir="${input}/foo/bar"/>
    <touch file="${input}/foo/bar/AAA.txt"/>
    <touch file="${input}/foo/bar/baz.txt"/>

    <mkdir dir="${output}"/>

    <move todir="${output}">
      <fileset dir="${input}"/>
      <firstmatchmapper>
        <regexpmapper from="(.*)AAA(.*)" to="\1BBB\2"/>
        <identitymapper/>
      </firstmatchmapper>
    </move>

    <au:assertFileExists file="${output}/BBB/foo/bar.txt"/>
    <au:assertFileExists file="${output}/foo/bar.txt"/>
    <au:assertFileExists file="${output}/foo/BBB/bar.txt"/>
    <au:assertFileExists file="${output}/foo/bar/BBB.txt"/>
    <au:assertFileExists file="${output}/foo/bar/baz.txt"/>
  </target>

  <target name="testNotModifiedSelector"
          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43574"
          >
    <mkdir dir="${input}/images"/>
    <mkdir dir="${input}/cache"/>
    <touch file="${input}/images/foo.jpg"/>
    <mkdir dir="${output}"/>
    <selector id="cache.selector">
      <not>
        <modified update="true"
                  seldirs="false"
                  cache="propertyfile"
                  algorithm="digest"
                  comparator="equal">
          <param name="cache.cachefile"
                 value="${input}/cache/cache.properties"/>
          <param name="algorithm.algorithm" value="MD5"/>
        </modified>
      </not>
    </selector>
    <au:assertFileDoesntExist file="${input}/cache/cache.properties"/>
    <move todir="${output}" overwrite="true">
      <fileset dir="${input}/images">
        <include name="*.jpg" />
        <selector refid="cache.selector" />
      </fileset>
    </move>
    <au:assertFileExists file="${input}/cache/cache.properties"/>
    <au:assertFileExists file="${input}/images/foo.jpg"/>
    <au:assertFileDoesntExist file="${output}/foo.jpg"/>
    <move todir="${output}" overwrite="true">
      <fileset dir="${input}/images">
        <include name="*.jpg" />
        <selector refid="cache.selector" />
      </fileset>
    </move>
    <au:assertFileDoesntExist file="${input}/images/foo.jpg"/>
    <au:assertFileExists file="${output}/foo.jpg"/>
  </target>

  <target name="testOverwriteIsTrueByDefault">
    <mkdir dir="${input}"/>
    <mkdir dir="${output}"/>
    <echo file="${input}/x.txt">X</echo>
    <sleep seconds="2"/>
    <echo file="${output}/y.txt">Y</echo>
    <move file="${input}/x.txt" tofile="${output}/y.txt"/>
    <au:assertFileDoesntExist file="${input}/x.txt"/>
    <au:assertResourceContains resource="${output}/y.txt"
                               value="X"/>
  </target>

  <target name="testOverwriteIsHonored"
          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47755">
    <mkdir dir="${input}"/>
    <mkdir dir="${output}"/>
    <echo file="${input}/x.txt">X</echo>
    <sleep seconds="2"/>
    <echo file="${output}/y.txt">Y</echo>
    <move file="${input}/x.txt" tofile="${output}/y.txt" overwrite="false"/>
    <au:assertFileExists file="${input}/x.txt"/>
    <au:assertResourceContains resource="${output}/y.txt"
                               value="Y"/>
  </target>

  <!-- stolen from ../types/readwrite-test.xml - create a read-only file -->
  <property name="file" value="testfile"/>
  <condition property="unix">
    <os family="unix"/>
  </condition>
  <target name="createTestdir">
    <mkdir dir="${output}"/>
    <mkdir dir="${input}"/>
    <touch file="${output}/${file}"/>
  </target>
  <target name="makeFileUnwritable"
          depends="createTestdir,makeFileUnwritable-Unix,makeFileUnwritable-Windows"/>
  <target name="makeFileUnwritable-Unix" id="unix">
    <chmod file="${output}/${file}" perm="444"/>
  </target>
  <target name="makeFileUnwritable-Windows" unless="unix">
    <attrib file="${output}/${file}" readonly="true"/>
  </target>

  <target name="testMoveOverReadOnlyFile" depends="makeFileUnwritable">
    <sleep seconds="2"/>
    <touch file="${input}/${file}"/>
    <au:expectfailure
        expectedMessage="can't replace read-only destination file ">
      <move toDir="${output}">
        <fileset dir="${input}"/>
      </move>
    </au:expectfailure>
  </target>

  <target name="testFilteredMoveOverReadOnlyFile" depends="makeFileUnwritable">
    <sleep seconds="2"/>
    <touch file="${input}/${file}"/>
    <au:expectfailure
        expectedMessage="can't write to read-only destination file ">
      <move toDir="${output}">
        <fileset dir="${input}"/>
        <filterset>
          <filter token="foo" value="bar"/>
        </filterset>
      </move>
    </au:expectfailure>
  </target>

  <target name="testMoveOverReadOnlyFileWithOverwrite"
          depends="makeFileUnwritable">
    <touch file="${input}/${file}"/>
    <au:expectfailure
        expectedMessage="can't replace read-only destination file ">
      <move toDir="${output}" overwrite="true">
        <fileset dir="${input}"/>
      </move>
    </au:expectfailure>
  </target>

  <target name="testFilteredMoveOverReadOnlyFileWithOverwrite"
          depends="makeFileUnwritable">
    <touch file="${input}/${file}"/>
    <au:expectfailure
        expectedMessage="can't write to read-only destination file ">
      <move toDir="${output}" overwrite="true">
        <fileset dir="${input}"/>
        <filterset>
          <filter token="foo" value="bar"/>
        </filterset>
      </move>
    </au:expectfailure>
  </target>

  <target name="testForcedMoveOverReadOnlyFile" depends="makeFileUnwritable">
    <sleep seconds="2"/>
    <touch file="${input}/${file}"/>
    <move toDir="${output}" force="true">
      <fileset dir="${input}"/>
    </move>
  </target>

  <target name="testForcedFilteredMoveOverReadOnlyFile"
          depends="makeFileUnwritable">
    <sleep seconds="2"/>
    <touch file="${input}/${file}"/>
    <move toDir="${output}" force="true">
      <fileset dir="${input}"/>
      <filterset>
        <filter token="foo" value="bar"/>
      </filterset>
    </move>
  </target>

  <target name="testForcedMoveOverReadOnlyFileWithOverwrite"
          depends="makeFileUnwritable">
    <touch file="${input}/${file}"/>
    <move toDir="${output}" overwrite="true" force="true">
      <fileset dir="${input}"/>
    </move>
  </target>

  <target name="testForcedFilteredMoveOverReadOnlyFileWithOverwrite"
          depends="makeFileUnwritable">
    <touch file="${input}/${file}"/>
    <move toDir="${output}" overwrite="true" force="true">
      <fileset dir="${input}"/>
      <filterset>
        <filter token="foo" value="bar"/>
      </filterset>
    </move>
  </target>
</project>