tesler 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- aaaaaaaaaaaaaa
1
+ aaaaaaaaaaaaaa
@@ -1,325 +1,347 @@
1
- require 'helper'
2
-
3
- class TestTesler < Test::Unit::TestCase
4
- def setup
5
- # reinitialize tesler
6
- reset_config
7
-
8
- # assign a mock of the standar output to tesler
9
- @output = Output.new
10
- Tesler::Config.output = @output
11
- end
12
-
13
- should "copy files" do
14
- # We delete the destination if it exists
15
- FileUtils.rm_r("test/dest/1") if File.exists?("test/dest/1")
16
-
17
- directory 'test\dest\1' do
18
- copy 'test\src\file1'
19
- copy 'test\src\file2'
20
- copy 'test\src\subdir1\file4'
21
-
22
- directory 'subdir1' do
23
- copy 'test\src\file3'
24
- copy 'test\src\subdir1\file5'
25
-
26
- directory 'subdir3' do
27
- copy 'test\src\file1'
28
- end
29
- end
30
-
31
- copy 'test\src\file2', :directory => 'subdir4'
32
- end
33
-
34
- assert File.exists?("test/dest/1/file1")
35
- assert File.exists?("test/dest/1/file2")
36
- assert File.exists?("test/dest/1/file4")
37
- assert File.exists?("test/dest/1/subdir1/file3")
38
- assert File.exists?("test/dest/1/subdir1/file5")
39
- assert File.exists?("test/dest/1/subdir1/subdir3/file1")
40
- assert File.exists?("test/dest/1/subdir4/file2")
41
- end
42
-
43
- should "copy entire directories" do
44
- # We delete the destination if it exists
45
- FileUtils.rm_r("test/dest/2") if File.exists?("test/dest/2")
46
-
47
- directory 'test\dest\2' do
48
- copy 'test\src\subdir2'
49
- end
50
-
51
- assert File.exists?("test/dest/2/subdir2")
52
- end
53
-
54
- should "support the renaming of the files and directories which are copied" do
55
- # We delete the destination if it exists
56
- FileUtils.rm_r("test/dest/3") if File.exists?("test/dest/3")
57
-
58
- directory 'test\dest\3' do
59
- directory 'subdir1' do
60
- directory 'subdir3' do
61
- copy 'test\src\file1', :rename => 'file1_renamed'
62
- end
63
- end
64
-
65
- copy 'test\src\subdir2', :rename => 'subdir2_renamed'
66
- end
67
-
68
- assert File.exists?("test/dest/3/subdir1/subdir3/file1_renamed")
69
- assert File.exists?("test/dest/3/subdir2_renamed")
70
- end
71
-
72
- should "support regular expressions on the filenames" do
73
- # We delete the destination if it exists
74
- FileUtils.rm_r("test/dest/4") if File.exists?("test/dest/4")
75
-
76
- directory 'test\dest\4' do
77
- directory 'subdir1' do
78
- directory 'subdir3' do
79
- copy 'test\src\*.test'
80
- end
81
- end
82
-
83
- copy 'test\src\reg_*.test'
84
- copy 'test\src\reg_*.test', :directory => 'subdir2'
85
- end
86
-
87
- assert File.exists?("test/dest/4/subdir1/subdir3/noreg_1.test")
88
- assert File.exists?("test/dest/4/subdir1/subdir3/noreg_2.test")
89
- assert File.exists?("test/dest/4/subdir1/subdir3/reg_1.test")
90
- assert File.exists?("test/dest/4/subdir1/subdir3/reg_2.test")
91
- assert File.exists?("test/dest/4/subdir1/subdir3/reg_3.test")
92
- assert File.exists?("test/dest/4/reg_1.test")
93
- assert File.exists?("test/dest/4/reg_2.test")
94
- assert File.exists?("test/dest/4/reg_3.test")
95
- assert File.exists?("test/dest/4/subdir2/reg_1.test")
96
- assert File.exists?("test/dest/4/subdir2/reg_2.test")
97
- assert File.exists?("test/dest/4/subdir2/reg_3.test")
98
- end
99
-
100
- should "log its actions" do
101
- # We delete the destination if it exists
102
- FileUtils.rm_r("test/dest/5") if File.exists?("test/dest/5")
103
-
104
- directory 'test\dest\5' do
105
- copy 'test\src\file1'
106
- copy 'test\src\file2'
107
- copy 'test\src\subdir1\file4'
108
-
109
- directory 'subdir1' do
110
- copy 'test\src\file3'
111
- copy 'test\src\subdir1\file5'
112
-
113
- directory 'subdir3' do
114
- copy 'test\src\file1'
115
- copy 'test\src\file2', :rename => 'file2_renamed'
116
- copy 'test\src\*.test'
117
- end
118
- end
119
-
120
- copy 'test\src\subdir2'
121
- copy 'test\src\subdir2', :rename => 'subdir2_renamed'
122
- copy 'test\src\reg_*.test'
123
- copy 'test\src\file2', :directory => 'subdir4'
124
- end
125
-
126
- messages = @output.messages.map { |m| m.strip }
127
- assert_match /(create|exists)\ttest\/dest\/5/, messages[0]
128
- assert_equal "copy\ttest/src/file1\ttest/dest/5/file1", messages[1]
129
- assert_equal "copy\ttest/src/file2\ttest/dest/5/file2", messages[2]
130
- assert_equal "copy\ttest/src/subdir1/file4\ttest/dest/5/file4", messages[3]
131
- assert_match /(create|exists)\ttest\/dest\/5\/subdir1/, messages[4]
132
- assert_equal "copy\ttest/src/file3\ttest/dest/5/subdir1/file3", messages[5]
133
- assert_equal "copy\ttest/src/subdir1/file5\ttest/dest/5/subdir1/file5", messages[6]
134
- assert_match /(create|exists)\ttest\/dest\/5\/subdir1\/subdir3/, messages[7]
135
- assert_equal "copy\ttest/src/file1\ttest/dest/5/subdir1/subdir3/file1", messages[8]
136
- assert_equal "copy\ttest/src/file2\ttest/dest/5/subdir1/subdir3/file2_renamed", messages[9]
137
- assert_equal "copy\ttest/src/noreg_1.test\ttest/dest/5/subdir1/subdir3/noreg_1.test", messages[10]
138
- assert_equal "copy\ttest/src/noreg_2.test\ttest/dest/5/subdir1/subdir3/noreg_2.test", messages[11]
139
- assert_equal "copy\ttest/src/reg_1.test\ttest/dest/5/subdir1/subdir3/reg_1.test", messages[12]
140
- assert_equal "copy\ttest/src/reg_2.test\ttest/dest/5/subdir1/subdir3/reg_2.test", messages[13]
141
- assert_equal "copy\ttest/src/reg_3.test\ttest/dest/5/subdir1/subdir3/reg_3.test", messages[14]
142
- assert_equal "copy\ttest/src/subdir2\ttest/dest/5/subdir2", messages[15]
143
- assert_equal "copy\ttest/src/subdir2\ttest/dest/5/subdir2_renamed", messages[16]
144
- assert_equal "copy\ttest/src/reg_1.test\ttest/dest/5/reg_1.test", messages[17]
145
- assert_equal "copy\ttest/src/reg_2.test\ttest/dest/5/reg_2.test", messages[18]
146
- assert_equal "copy\ttest/src/reg_3.test\ttest/dest/5/reg_3.test", messages[19]
147
- assert_equal "copy\ttest/src/file2\ttest/dest/5/subdir4/file2", messages[20]
148
- end
149
-
150
- should "copy files" do
151
- assert File.exists?("test/dest")
152
- assert File.exists?("test/dest/file1")
153
- assert File.exists?("test/dest/file2")
154
- assert File.exists?("test/dest/file4")
155
- assert File.exists?("test/dest/subdir1")
156
- assert File.exists?("test/dest/subdir1/file3")
157
- assert File.exists?("test/dest/subdir1/file5")
158
- assert File.exists?("test/dest/subdir1/subdir3")
159
- assert File.exists?("test/dest/subdir1/subdir3/file8")
160
- assert File.exists?("test/dest/subdir1/subdir3/renamed")
161
- assert File.exists?("test/dest/subdir2")
162
- assert File.exists?("test/dest/renamed")
163
-
164
- assert File.exists?("test/dest/6")
165
- assert File.exists?("test/dest/6/file1")
166
- assert File.exists?("test/dest/6/file2")
167
- assert File.exists?("test/dest/6/file4")
168
- assert File.exists?("test/dest/6/subdir1")
169
- assert File.exists?("test/dest/6/subdir1/file3")
170
- assert File.exists?("test/dest/6/subdir1/file5")
171
- assert File.exists?("test/dest/6/subdir1/subdir3")
172
- assert File.exists?("test/dest/6/subdir1/subdir3/file1")
173
- assert File.exists?("test/dest/6/subdir1/subdir3/file2_renamed")
174
- assert File.exists?("test/dest/6/subdir2")
175
- assert File.exists?("test/dest/6/subdir2_renamed")
176
- assert File.exists?("test/dest/6/subdir1/subdir3/noreg_1.test")
177
- assert File.exists?("test/dest/6/subdir1/subdir3/noreg_2.test")
178
- assert File.exists?("test/dest/6/subdir1/subdir3/reg_1.test")
179
- assert File.exists?("test/dest/6/subdir1/subdir3/reg_2.test")
180
- assert File.exists?("test/dest/6/subdir1/subdir3/reg_3.test")
181
- assert File.exists?("test/dest/6/reg_1.test")
182
- assert File.exists?("test/dest/6/reg_2.test")
183
- assert File.exists?("test/dest/6/reg_3.test")
184
-
185
- messages = @output.messages.map { |m| m.strip }
186
- assert_match messages[0], /(create|exists)\ttest\/dest/
187
- assert_equal messages[1], "copy\ttest/dest/file1"
188
- assert_equal messages[2], "copy\ttest/dest/file2"
189
- assert_equal messages[3], "copy\ttest/dest/file4"
190
- assert_match messages[4], /(create|exists)\ttest\/dest\/subdir1/
191
- assert_equal messages[5], "copy\ttest/dest/subdir1/file3"
192
- assert_equal messages[6], "copy\ttest/dest/subdir1/file5"
193
- assert_match messages[7], /(create|exists)\ttest\/dest\/subdir1\/subdir3/
194
- assert_equal messages[8], "copy\ttest/dest/subdir1/subdir3/file8"
195
- assert_equal messages[9], "copy\ttest/dest/subdir1/subdir3/renamed"
196
- assert_equal messages[10], "copy\ttest/dest/subdir2"
197
- assert_equal messages[11], "copy\ttest/dest/renamed"
198
- end
199
-
200
- should "be able to run in test mode" do
201
- # We delete the destination if it exists
202
- FileUtils.rm_r("test/dest/7") if File.exists?("test/dest/7")
203
-
204
- # when running in test mode, the files are not copied but the logger displays the results
205
- run_in_test_mode
206
- source_directory 'test\src'
207
-
208
- directory 'test\dest\7' do
209
- copy 'file1'
210
- copy 'file2'
211
- copy 'subdir1\file4'
212
-
213
- directory 'subdir1' do
214
- copy 'file3'
215
- copy 'subdir1\file5'
216
-
217
- directory 'subdir3' do
218
- copy 'file1'
219
- copy 'file2', :rename => 'file2_renamed'
220
- copy '*.test'
221
- end
222
- end
223
-
224
- copy 'subdir2'
225
- copy 'subdir2', :rename => 'subdir2_renamed'
226
- copy 'reg_*.test'
227
- end
228
-
229
- assert !File.exists?("test/dest/7")
230
- assert !File.exists?("test/dest/7/file1")
231
- assert !File.exists?("test/dest/7/file2")
232
- assert !File.exists?("test/dest/7/file4")
233
- assert !File.exists?("test/dest/7/subdir1")
234
- assert !File.exists?("test/dest/7/subdir1/file3")
235
- assert !File.exists?("test/dest/7/subdir1/file5")
236
- assert !File.exists?("test/dest/7/subdir1/subdir3")
237
- assert !File.exists?("test/dest/7/subdir1/subdir3/file1")
238
- assert !File.exists?("test/dest/7/subdir1/subdir3/file2_renamed")
239
- assert !File.exists?("test/dest/7/subdir2")
240
- assert !File.exists?("test/dest/7/subdir2_renamed")
241
- assert !File.exists?("test/dest/7/subdir1/subdir3/noreg_1.test")
242
- assert !File.exists?("test/dest/7/subdir1/subdir3/noreg_2.test")
243
- assert !File.exists?("test/dest/7/subdir1/subdir3/reg_1.test")
244
- assert !File.exists?("test/dest/7/subdir1/subdir3/reg_2.test")
245
- assert !File.exists?("test/dest/7/subdir1/subdir3/reg_3.test")
246
- assert !File.exists?("test/dest/7/reg_1.test")
247
- assert !File.exists?("test/dest/7/reg_2.test")
248
- assert !File.exists?("test/dest/7/reg_3.test")
249
-
250
- messages = @output.messages.map { |m| m.strip }
251
- assert_match /(create|exists)\ttest\/dest\/7/, messages[0]
252
- assert_equal "copy\ttest/src/file1\ttest/dest/7/file1", messages[1]
253
- assert_equal "copy\ttest/src/file2\ttest/dest/7/file2", messages[2]
254
- assert_equal "copy\ttest/src/subdir1/file4\ttest/dest/7/file4", messages[3]
255
- assert_match /(create|exists)\ttest\/dest\/7\/subdir1/, messages[4]
256
- assert_equal "copy\ttest/src/file3\ttest/dest/7/subdir1/file3", messages[5]
257
- assert_equal "copy\ttest/src/subdir1/file5\ttest/dest/7/subdir1/file5", messages[6]
258
- assert_match /(create|exists)\ttest\/dest\/7\/subdir1\/subdir3/, messages[7]
259
- assert_equal "copy\ttest/src/file1\ttest/dest/7/subdir1/subdir3/file1", messages[8]
260
- assert_equal "copy\ttest/src/file2\ttest/dest/7/subdir1/subdir3/file2_renamed", messages[9]
261
- assert_equal "copy\ttest/src/noreg_1.test\ttest/dest/7/subdir1/subdir3/noreg_1.test", messages[10]
262
- assert_equal "copy\ttest/src/noreg_2.test\ttest/dest/7/subdir1/subdir3/noreg_2.test", messages[11]
263
- assert_equal "copy\ttest/src/reg_1.test\ttest/dest/7/subdir1/subdir3/reg_1.test", messages[12]
264
- assert_equal "copy\ttest/src/reg_2.test\ttest/dest/7/subdir1/subdir3/reg_2.test", messages[13]
265
- assert_equal "copy\ttest/src/reg_3.test\ttest/dest/7/subdir1/subdir3/reg_3.test", messages[14]
266
- assert_equal "copy\ttest/src/subdir2\ttest/dest/7/subdir2", messages[15]
267
- assert_equal "copy\ttest/src/subdir2\ttest/dest/7/subdir2_renamed", messages[16]
268
- assert_equal "copy\ttest/src/reg_1.test\ttest/dest/7/reg_1.test", messages[17]
269
- assert_equal "copy\ttest/src/reg_2.test\ttest/dest/7/reg_2.test", messages[18]
270
- assert_equal "copy\ttest/src/reg_3.test\ttest/dest/7/reg_3.test", messages[19]
271
- end
272
-
273
- should "log when it can't find a source file" do
274
- # We delete the destination if it exists
275
- FileUtils.rm_r("test/dest/8") if File.exists?("test/dest/8")
276
-
277
- source_directory 'test\src'
278
-
279
- directory 'test\dest\8' do
280
- copy 'unknown_file'
281
- end
282
-
283
- assert File.exists?("test/dest/8")
284
- messages = @output.messages.map { |m| m.strip }
285
- assert_match /(create|exists)\ttest\/dest\/8/, messages[0]
286
- assert_equal "not found\ttest/src/unknown_file", messages[1]
287
- end
288
-
289
- should "detect and replace environment variables" do
290
- # We delete the destination if it exists
291
- FileUtils.rm_r("test/dest/9") if File.exists?("test/dest/9")
292
-
293
- # create a new environment variable
294
- ENV['TESLER_TEST'] = File.dirname(__FILE__)
295
-
296
- directory '%TESLER_TEST%\dest\9' do
297
- copy '%TESLER_TEST%\src\file1'
298
- copy '%TESLER_TEST%\src\*.test'
299
- end
300
-
301
- assert File.exists?("test/dest/9")
302
- assert File.exists?("test/dest/9/file1")
303
- assert File.exists?("test/dest/9/noreg_1.test")
304
- assert File.exists?("test/dest/9/noreg_2.test")
305
- assert File.exists?("test/dest/9/reg_1.test")
306
- assert File.exists?("test/dest/9/reg_2.test")
307
- assert File.exists?("test/dest/9/reg_3.test")
308
- end
309
-
310
- should "log when it can't find a source file's directory (regular expressions case only)" do
311
- # We delete the destination if it exists
312
- FileUtils.rm_r("test/dest/10") if File.exists?("test/dest/10")
313
-
314
- source_directory 'unknown\src'
315
-
316
- directory 'test\dest\10' do
317
- copy '*.file'
318
- end
319
-
320
- assert File.exists?("test/dest/10")
321
- messages = @output.messages.map { |m| m.strip }
322
- assert_match /(create|exists)\ttest\/dest\/10/, messages[0]
323
- assert_equal "not found\tunknown/src", messages[1]
324
- end
325
- end
1
+ require 'helper'
2
+
3
+ class TestTesler < Test::Unit::TestCase
4
+ def setup
5
+ # reinitialize tesler
6
+ reset_config
7
+
8
+ # assign a mock of the standar output to tesler
9
+ @output = Output.new
10
+ Tesler::Config.output = @output
11
+ end
12
+
13
+ should "copy files" do
14
+ # We delete the destination if it exists
15
+ FileUtils.rm_r("test/dest/1") if File.exists?("test/dest/1")
16
+
17
+ directory 'test\dest\1' do
18
+ copy 'test\src\file1'
19
+ copy 'test\src\file2'
20
+ copy 'test\src\subdir1\file4'
21
+
22
+ directory 'subdir1' do
23
+ copy 'test\src\file3'
24
+ copy 'test\src\subdir1\file5'
25
+
26
+ directory 'subdir3' do
27
+ copy 'test\src\file1'
28
+ end
29
+ end
30
+
31
+ copy 'test\src\file2', :directory => 'subdir4'
32
+ end
33
+
34
+ assert File.exists?("test/dest/1/file1")
35
+ assert File.exists?("test/dest/1/file2")
36
+ assert File.exists?("test/dest/1/file4")
37
+ assert File.exists?("test/dest/1/subdir1/file3")
38
+ assert File.exists?("test/dest/1/subdir1/file5")
39
+ assert File.exists?("test/dest/1/subdir1/subdir3/file1")
40
+ assert File.exists?("test/dest/1/subdir4/file2")
41
+ end
42
+
43
+ should "copy entire directories" do
44
+ # We delete the destination if it exists
45
+ FileUtils.rm_r("test/dest/2") if File.exists?("test/dest/2")
46
+
47
+ directory 'test\dest\2' do
48
+ copy 'test\src\subdir2'
49
+ end
50
+
51
+ assert File.exists?("test/dest/2/subdir2")
52
+ end
53
+
54
+ should "support the renaming of the files and directories which are copied" do
55
+ # We delete the destination if it exists
56
+ FileUtils.rm_r("test/dest/3") if File.exists?("test/dest/3")
57
+
58
+ directory 'test\dest\3' do
59
+ directory 'subdir1' do
60
+ directory 'subdir3' do
61
+ copy 'test\src\file1', :rename => 'file1_renamed'
62
+ end
63
+ end
64
+
65
+ copy 'test\src\subdir2', :rename => 'subdir2_renamed'
66
+ end
67
+
68
+ assert File.exists?("test/dest/3/subdir1/subdir3/file1_renamed")
69
+ assert File.exists?("test/dest/3/subdir2_renamed")
70
+ end
71
+
72
+ should "support regular expressions on the filenames" do
73
+ # We delete the destination if it exists
74
+ FileUtils.rm_r("test/dest/4") if File.exists?("test/dest/4")
75
+
76
+ directory 'test\dest\4' do
77
+ directory 'subdir1' do
78
+ directory 'subdir3' do
79
+ copy 'test\src\*.test'
80
+ end
81
+ end
82
+
83
+ copy 'test\src\reg_*.test'
84
+ copy 'test\src\reg_*.test', :directory => 'subdir2'
85
+ end
86
+
87
+ assert File.exists?("test/dest/4/subdir1/subdir3/noreg_1.test")
88
+ assert File.exists?("test/dest/4/subdir1/subdir3/noreg_2.test")
89
+ assert File.exists?("test/dest/4/subdir1/subdir3/reg_1.test")
90
+ assert File.exists?("test/dest/4/subdir1/subdir3/reg_2.test")
91
+ assert File.exists?("test/dest/4/subdir1/subdir3/reg_3.test")
92
+ assert File.exists?("test/dest/4/reg_1.test")
93
+ assert File.exists?("test/dest/4/reg_2.test")
94
+ assert File.exists?("test/dest/4/reg_3.test")
95
+ assert File.exists?("test/dest/4/subdir2/reg_1.test")
96
+ assert File.exists?("test/dest/4/subdir2/reg_2.test")
97
+ assert File.exists?("test/dest/4/subdir2/reg_3.test")
98
+ end
99
+
100
+ should "log its actions" do
101
+ # We delete the destination if it exists
102
+ FileUtils.rm_r("test/dest/5") if File.exists?("test/dest/5")
103
+
104
+ directory 'test\dest\5' do
105
+ copy 'test\src\file1'
106
+ copy 'test\src\file2'
107
+ copy 'test\src\subdir1\file4'
108
+
109
+ directory 'subdir1' do
110
+ copy 'test\src\file3'
111
+ copy 'test\src\subdir1\file5'
112
+
113
+ directory 'subdir3' do
114
+ copy 'test\src\file1'
115
+ copy 'test\src\file2', :rename => 'file2_renamed'
116
+ copy 'test\src\*.test'
117
+ end
118
+ end
119
+
120
+ copy 'test\src\subdir2'
121
+ copy 'test\src\subdir2', :rename => 'subdir2_renamed'
122
+ copy 'test\src\reg_*.test'
123
+ copy 'test\src\file2', :directory => 'subdir4'
124
+ end
125
+
126
+ messages = @output.messages.map { |m| m.strip }
127
+ assert_match /(create|exists)\ttest\/dest\/5/, messages[0]
128
+ assert_equal "copy\ttest/src/file1\ttest/dest/5/file1", messages[1]
129
+ assert_equal "copy\ttest/src/file2\ttest/dest/5/file2", messages[2]
130
+ assert_equal "copy\ttest/src/subdir1/file4\ttest/dest/5/file4", messages[3]
131
+ assert_match /(create|exists)\ttest\/dest\/5\/subdir1/, messages[4]
132
+ assert_equal "copy\ttest/src/file3\ttest/dest/5/subdir1/file3", messages[5]
133
+ assert_equal "copy\ttest/src/subdir1/file5\ttest/dest/5/subdir1/file5", messages[6]
134
+ assert_match /(create|exists)\ttest\/dest\/5\/subdir1\/subdir3/, messages[7]
135
+ assert_equal "copy\ttest/src/file1\ttest/dest/5/subdir1/subdir3/file1", messages[8]
136
+ assert_equal "copy\ttest/src/file2\ttest/dest/5/subdir1/subdir3/file2_renamed", messages[9]
137
+ assert_equal "copy\ttest/src/noreg_1.test\ttest/dest/5/subdir1/subdir3/noreg_1.test", messages[10]
138
+ assert_equal "copy\ttest/src/noreg_2.test\ttest/dest/5/subdir1/subdir3/noreg_2.test", messages[11]
139
+ assert_equal "copy\ttest/src/reg_1.test\ttest/dest/5/subdir1/subdir3/reg_1.test", messages[12]
140
+ assert_equal "copy\ttest/src/reg_2.test\ttest/dest/5/subdir1/subdir3/reg_2.test", messages[13]
141
+ assert_equal "copy\ttest/src/reg_3.test\ttest/dest/5/subdir1/subdir3/reg_3.test", messages[14]
142
+ assert_equal "copy\ttest/src/subdir2\ttest/dest/5/subdir2", messages[15]
143
+ assert_equal "copy\ttest/src/subdir2\ttest/dest/5/subdir2_renamed", messages[16]
144
+ assert_equal "copy\ttest/src/reg_1.test\ttest/dest/5/reg_1.test", messages[17]
145
+ assert_equal "copy\ttest/src/reg_2.test\ttest/dest/5/reg_2.test", messages[18]
146
+ assert_equal "copy\ttest/src/reg_3.test\ttest/dest/5/reg_3.test", messages[19]
147
+ assert_equal "copy\ttest/src/file2\ttest/dest/5/subdir4/file2", messages[20]
148
+ end
149
+
150
+ should "allow to set a default src directory" do
151
+ # We delete the destination if it exists
152
+ FileUtils.rm_r("test/dest/6") if File.exists?("test/dest/6")
153
+
154
+ # when a source directory is set then all the files are copied from it
155
+ source_directory 'test\src'
156
+
157
+ directory 'test\dest\6' do
158
+ copy 'file1'
159
+ copy 'file2'
160
+ copy 'subdir1\file4'
161
+
162
+ directory 'subdir1' do
163
+ copy 'file3'
164
+ copy 'subdir1\file5'
165
+
166
+ directory 'subdir3' do
167
+ copy 'file1'
168
+ copy 'file2', :rename => 'file2_renamed'
169
+ copy '*.test'
170
+ end
171
+ end
172
+
173
+ copy 'subdir2'
174
+ copy 'subdir2', :rename => 'subdir2_renamed'
175
+ copy 'reg_*.test'
176
+ end
177
+
178
+ assert File.exists?("test/dest/6")
179
+ assert File.exists?("test/dest/6/file1")
180
+ assert File.exists?("test/dest/6/file2")
181
+ assert File.exists?("test/dest/6/file4")
182
+ assert File.exists?("test/dest/6/subdir1")
183
+ assert File.exists?("test/dest/6/subdir1/file3")
184
+ assert File.exists?("test/dest/6/subdir1/file5")
185
+ assert File.exists?("test/dest/6/subdir1/subdir3")
186
+ assert File.exists?("test/dest/6/subdir1/subdir3/file1")
187
+ assert File.exists?("test/dest/6/subdir1/subdir3/file2_renamed")
188
+ assert File.exists?("test/dest/6/subdir2")
189
+ assert File.exists?("test/dest/6/subdir2_renamed")
190
+ assert File.exists?("test/dest/6/subdir1/subdir3/noreg_1.test")
191
+ assert File.exists?("test/dest/6/subdir1/subdir3/noreg_2.test")
192
+ assert File.exists?("test/dest/6/subdir1/subdir3/reg_1.test")
193
+ assert File.exists?("test/dest/6/subdir1/subdir3/reg_2.test")
194
+ assert File.exists?("test/dest/6/subdir1/subdir3/reg_3.test")
195
+ assert File.exists?("test/dest/6/reg_1.test")
196
+ assert File.exists?("test/dest/6/reg_2.test")
197
+ assert File.exists?("test/dest/6/reg_3.test")
198
+
199
+ messages = @output.messages.map { |m| m.strip }
200
+ assert_match /(create|exists)\ttest\/dest\/6/, messages[0]
201
+ assert_equal "copy\ttest/src/file1\ttest/dest/6/file1", messages[1]
202
+ assert_equal "copy\ttest/src/file2\ttest/dest/6/file2", messages[2]
203
+ assert_equal "copy\ttest/src/subdir1/file4\ttest/dest/6/file4", messages[3]
204
+ assert_match /(create|exists)\ttest\/dest\/6\/subdir1/, messages[4]
205
+ assert_equal "copy\ttest/src/file3\ttest/dest/6/subdir1/file3", messages[5]
206
+ assert_equal "copy\ttest/src/subdir1/file5\ttest/dest/6/subdir1/file5", messages[6]
207
+ assert_match /(create|exists)\ttest\/dest\/6\/subdir1\/subdir3/, messages[7]
208
+ assert_equal "copy\ttest/src/file1\ttest/dest/6/subdir1/subdir3/file1", messages[8]
209
+ assert_equal "copy\ttest/src/file2\ttest/dest/6/subdir1/subdir3/file2_renamed", messages[9]
210
+ assert_equal "copy\ttest/src/noreg_1.test\ttest/dest/6/subdir1/subdir3/noreg_1.test", messages[10]
211
+ assert_equal "copy\ttest/src/noreg_2.test\ttest/dest/6/subdir1/subdir3/noreg_2.test", messages[11]
212
+ assert_equal "copy\ttest/src/reg_1.test\ttest/dest/6/subdir1/subdir3/reg_1.test", messages[12]
213
+ assert_equal "copy\ttest/src/reg_2.test\ttest/dest/6/subdir1/subdir3/reg_2.test", messages[13]
214
+ assert_equal "copy\ttest/src/reg_3.test\ttest/dest/6/subdir1/subdir3/reg_3.test", messages[14]
215
+ assert_equal "copy\ttest/src/subdir2\ttest/dest/6/subdir2", messages[15]
216
+ assert_equal "copy\ttest/src/subdir2\ttest/dest/6/subdir2_renamed", messages[16]
217
+ assert_equal "copy\ttest/src/reg_1.test\ttest/dest/6/reg_1.test", messages[17]
218
+ assert_equal "copy\ttest/src/reg_2.test\ttest/dest/6/reg_2.test", messages[18]
219
+ assert_equal "copy\ttest/src/reg_3.test\ttest/dest/6/reg_3.test", messages[19]
220
+ end
221
+
222
+ should "be able to run in test mode" do
223
+ # We delete the destination if it exists
224
+ FileUtils.rm_r("test/dest/7") if File.exists?("test/dest/7")
225
+
226
+ # when running in test mode, the files are not copied but the logger displays the results
227
+ run_in_test_mode
228
+ source_directory 'test\src'
229
+
230
+ directory 'test\dest\7' do
231
+ copy 'file1'
232
+ copy 'file2'
233
+ copy 'subdir1\file4'
234
+
235
+ directory 'subdir1' do
236
+ copy 'file3'
237
+ copy 'subdir1\file5'
238
+
239
+ directory 'subdir3' do
240
+ copy 'file1'
241
+ copy 'file2', :rename => 'file2_renamed'
242
+ copy '*.test'
243
+ end
244
+ end
245
+
246
+ copy 'subdir2'
247
+ copy 'subdir2', :rename => 'subdir2_renamed'
248
+ copy 'reg_*.test'
249
+ end
250
+
251
+ assert !File.exists?("test/dest/7")
252
+ assert !File.exists?("test/dest/7/file1")
253
+ assert !File.exists?("test/dest/7/file2")
254
+ assert !File.exists?("test/dest/7/file4")
255
+ assert !File.exists?("test/dest/7/subdir1")
256
+ assert !File.exists?("test/dest/7/subdir1/file3")
257
+ assert !File.exists?("test/dest/7/subdir1/file5")
258
+ assert !File.exists?("test/dest/7/subdir1/subdir3")
259
+ assert !File.exists?("test/dest/7/subdir1/subdir3/file1")
260
+ assert !File.exists?("test/dest/7/subdir1/subdir3/file2_renamed")
261
+ assert !File.exists?("test/dest/7/subdir2")
262
+ assert !File.exists?("test/dest/7/subdir2_renamed")
263
+ assert !File.exists?("test/dest/7/subdir1/subdir3/noreg_1.test")
264
+ assert !File.exists?("test/dest/7/subdir1/subdir3/noreg_2.test")
265
+ assert !File.exists?("test/dest/7/subdir1/subdir3/reg_1.test")
266
+ assert !File.exists?("test/dest/7/subdir1/subdir3/reg_2.test")
267
+ assert !File.exists?("test/dest/7/subdir1/subdir3/reg_3.test")
268
+ assert !File.exists?("test/dest/7/reg_1.test")
269
+ assert !File.exists?("test/dest/7/reg_2.test")
270
+ assert !File.exists?("test/dest/7/reg_3.test")
271
+
272
+ messages = @output.messages.map { |m| m.strip }
273
+ assert_match /(create|exists)\ttest\/dest\/7/, messages[0]
274
+ assert_equal "copy\ttest/src/file1\ttest/dest/7/file1", messages[1]
275
+ assert_equal "copy\ttest/src/file2\ttest/dest/7/file2", messages[2]
276
+ assert_equal "copy\ttest/src/subdir1/file4\ttest/dest/7/file4", messages[3]
277
+ assert_match /(create|exists)\ttest\/dest\/7\/subdir1/, messages[4]
278
+ assert_equal "copy\ttest/src/file3\ttest/dest/7/subdir1/file3", messages[5]
279
+ assert_equal "copy\ttest/src/subdir1/file5\ttest/dest/7/subdir1/file5", messages[6]
280
+ assert_match /(create|exists)\ttest\/dest\/7\/subdir1\/subdir3/, messages[7]
281
+ assert_equal "copy\ttest/src/file1\ttest/dest/7/subdir1/subdir3/file1", messages[8]
282
+ assert_equal "copy\ttest/src/file2\ttest/dest/7/subdir1/subdir3/file2_renamed", messages[9]
283
+ assert_equal "copy\ttest/src/noreg_1.test\ttest/dest/7/subdir1/subdir3/noreg_1.test", messages[10]
284
+ assert_equal "copy\ttest/src/noreg_2.test\ttest/dest/7/subdir1/subdir3/noreg_2.test", messages[11]
285
+ assert_equal "copy\ttest/src/reg_1.test\ttest/dest/7/subdir1/subdir3/reg_1.test", messages[12]
286
+ assert_equal "copy\ttest/src/reg_2.test\ttest/dest/7/subdir1/subdir3/reg_2.test", messages[13]
287
+ assert_equal "copy\ttest/src/reg_3.test\ttest/dest/7/subdir1/subdir3/reg_3.test", messages[14]
288
+ assert_equal "copy\ttest/src/subdir2\ttest/dest/7/subdir2", messages[15]
289
+ assert_equal "copy\ttest/src/subdir2\ttest/dest/7/subdir2_renamed", messages[16]
290
+ assert_equal "copy\ttest/src/reg_1.test\ttest/dest/7/reg_1.test", messages[17]
291
+ assert_equal "copy\ttest/src/reg_2.test\ttest/dest/7/reg_2.test", messages[18]
292
+ assert_equal "copy\ttest/src/reg_3.test\ttest/dest/7/reg_3.test", messages[19]
293
+ end
294
+
295
+ should "log when it can't find a source file" do
296
+ # We delete the destination if it exists
297
+ FileUtils.rm_r("test/dest/8") if File.exists?("test/dest/8")
298
+
299
+ source_directory 'test\src'
300
+
301
+ directory 'test\dest\8' do
302
+ copy 'unknown_file'
303
+ end
304
+
305
+ assert File.exists?("test/dest/8")
306
+ messages = @output.messages.map { |m| m.strip }
307
+ assert_match /(create|exists)\ttest\/dest\/8/, messages[0]
308
+ assert_equal "not found\ttest/src/unknown_file", messages[1]
309
+ end
310
+
311
+ should "detect and replace environment variables" do
312
+ # We delete the destination if it exists
313
+ FileUtils.rm_r("test/dest/9") if File.exists?("test/dest/9")
314
+
315
+ # create a new environment variable
316
+ ENV['TESLER_TEST'] = File.dirname(__FILE__)
317
+
318
+ directory '%TESLER_TEST%\dest\9' do
319
+ copy '%TESLER_TEST%\src\file1'
320
+ copy '%TESLER_TEST%\src\*.test'
321
+ end
322
+
323
+ assert File.exists?("test/dest/9")
324
+ assert File.exists?("test/dest/9/file1")
325
+ assert File.exists?("test/dest/9/noreg_1.test")
326
+ assert File.exists?("test/dest/9/noreg_2.test")
327
+ assert File.exists?("test/dest/9/reg_1.test")
328
+ assert File.exists?("test/dest/9/reg_2.test")
329
+ assert File.exists?("test/dest/9/reg_3.test")
330
+ end
331
+
332
+ should "log when it can't find a source file's directory (regular expressions case only)" do
333
+ # We delete the destination if it exists
334
+ FileUtils.rm_r("test/dest/10") if File.exists?("test/dest/10")
335
+
336
+ source_directory 'unknown\src'
337
+
338
+ directory 'test\dest\10' do
339
+ copy '*.file'
340
+ end
341
+
342
+ assert File.exists?("test/dest/10")
343
+ messages = @output.messages.map { |m| m.strip }
344
+ assert_match /(create|exists)\ttest\/dest\/10/, messages[0]
345
+ assert_equal "not found\tunknown/src", messages[1]
346
+ end
347
+ end