bee 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/bin/bee +16 -0
- data/bin/bee.bat +32 -0
- data/lib/bee.rb +165 -170
- data/lib/bee_console.rb +90 -87
- data/lib/bee_task.rb +149 -0
- data/lib/bee_task_default.rb +525 -0
- data/lib/bee_util.rb +230 -0
- data/test/tc_bee_build.rb +216 -0
- data/test/tc_bee_console.rb +106 -0
- data/test/tc_bee_console_formatter.rb +38 -3
- data/test/tc_bee_context.rb +84 -0
- data/test/tc_bee_task_default.rb +467 -0
- data/test/tc_bee_util.rb +85 -0
- data/test/test_build.rb +26 -0
- data/test/test_build_listener.rb +60 -0
- data/test/tmp_test_case.rb +58 -0
- data/test/ts_bee.rb +1 -1
- metadata +35 -8
- data/lib/bee_default_context.rb +0 -475
- data/test/tc_bee_default_tasks.rb +0 -298
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# Copyright 2006 Michel Casabianca <
|
3
|
+
# Copyright 2006-2007 Michel Casabianca <michel.casabianca@gmail.com>
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
# you may not use this file except in compliance with the License.
|
@@ -16,18 +16,22 @@
|
|
16
16
|
|
17
17
|
require 'test/unit'
|
18
18
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
19
|
+
require 'bee'
|
19
20
|
require 'bee_console'
|
20
21
|
|
22
|
+
# Test case for console formatter.
|
21
23
|
class TestBeeConsoleFormatter < Test::Unit::TestCase
|
22
24
|
|
25
|
+
# Test default target title formatting.
|
23
26
|
def test_format_target_default
|
24
27
|
expected = "#{'-'*72} TEST --"
|
25
|
-
formatter = Bee::Console::Formatter.new(
|
28
|
+
formatter = Bee::Console::Formatter.new('ll:80')
|
26
29
|
target = Bee::Target.new({ 'target' => 'TEST' }, nil)
|
27
30
|
actual = formatter.format_target(target)
|
28
31
|
assert_equal(expected, actual)
|
29
32
|
end
|
30
|
-
|
33
|
+
|
34
|
+
# Test target title formatting with colorization.
|
31
35
|
def test_format_target
|
32
36
|
expected = "\e[1;31;42m#{'#'*64} TEST ##\e[0m"
|
33
37
|
style = {
|
@@ -43,4 +47,35 @@ class TestBeeConsoleFormatter < Test::Unit::TestCase
|
|
43
47
|
assert_equal(expected, actual)
|
44
48
|
end
|
45
49
|
|
50
|
+
def test_format_task
|
51
|
+
expected = '- foo: bar'
|
52
|
+
task = {'foo' => 'bar'}
|
53
|
+
formatter = Bee::Console::Formatter.new('')
|
54
|
+
actual = formatter.format_task(task)
|
55
|
+
assert_equal(expected, actual)
|
56
|
+
expected = '- rb: bar'
|
57
|
+
task = {'rb' => 'bar'}
|
58
|
+
actual = formatter.format_task(task)
|
59
|
+
assert_equal(expected, actual)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_help_build
|
63
|
+
expected = "- Build: \"test\"
|
64
|
+
Description: Test description
|
65
|
+
- Properties:
|
66
|
+
- base: \"#{Dir.pwd}\"
|
67
|
+
- foo: \"bar\"
|
68
|
+
- test: \"test\"
|
69
|
+
- Targets:
|
70
|
+
- test: Test description
|
71
|
+
- Default: test"
|
72
|
+
object = [{'build' => 'test', 'description' => 'Test description'},
|
73
|
+
{'properties' => [{'test' => 'test'}, {'foo' => 'bar'}]},
|
74
|
+
{'target' => 'test', 'description' => 'Test description'}]
|
75
|
+
build = Bee::Build.new(object, nil)
|
76
|
+
formatter = Bee::Console::Formatter.new(nil)
|
77
|
+
actual = formatter.help_build(build)
|
78
|
+
assert_equal(expected, actual)
|
79
|
+
end
|
80
|
+
|
46
81
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2006-2007 Michel Casabianca <michel.casabianca@gmail.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
19
|
+
require 'bee'
|
20
|
+
|
21
|
+
# Test context.
|
22
|
+
class TestBeeContext < Test::Unit::TestCase
|
23
|
+
|
24
|
+
# Initialize a context.
|
25
|
+
def setup
|
26
|
+
@context = Bee::Context.new
|
27
|
+
end
|
28
|
+
|
29
|
+
# Test object evaluation.
|
30
|
+
def test_evaluate_object
|
31
|
+
# nil: must evaluate to nil
|
32
|
+
expected = nil
|
33
|
+
actual = @context.evaluate_object(expected)
|
34
|
+
assert_equal(expected, actual)
|
35
|
+
# string: return value with property references replaced
|
36
|
+
expected = "This is a test!"
|
37
|
+
actual = @context.evaluate_object(expected)
|
38
|
+
assert_equal(expected, actual)
|
39
|
+
@context.set_property(:foo, 'bar')
|
40
|
+
expected = 'This is bar!'
|
41
|
+
actual = @context.evaluate_object('This is #{foo}!')
|
42
|
+
assert_equal(expected, actual)
|
43
|
+
# symbol: replace with property value
|
44
|
+
expected = 'bar'
|
45
|
+
actual = @context.evaluate_object(:foo)
|
46
|
+
assert_equal(expected, actual)
|
47
|
+
# array: return array with elements evaluated
|
48
|
+
expected = [1, 2, 3]
|
49
|
+
actual = @context.evaluate_object([1, 2, 3])
|
50
|
+
assert_equal(expected, actual)
|
51
|
+
expected = ['a', 'b', 'bar']
|
52
|
+
actual = @context.evaluate_object(['a', 'b', :foo])
|
53
|
+
assert_equal(expected, actual)
|
54
|
+
# hash: return hash with keys and values evaluated
|
55
|
+
expected = { 1 => 'bar', 'bar' => 2 }
|
56
|
+
actual = @context.evaluate_object({ 1 => :foo, '#{foo}' => 2 })
|
57
|
+
assert_equal(expected, actual)
|
58
|
+
# complex: symbol referencing an array
|
59
|
+
expected = [1, 2, 3]
|
60
|
+
@context.set_property('int', 3)
|
61
|
+
@context.set_property('array', [1, 2, :int])
|
62
|
+
actual = @context.evaluate_object(:array)
|
63
|
+
assert_equal(expected, actual)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Test property access
|
67
|
+
def test_set
|
68
|
+
# nominal case
|
69
|
+
@context.set_property(:foo, 'bar')
|
70
|
+
assert_equal(@context.get_property(:foo), 'bar')
|
71
|
+
# error case
|
72
|
+
begin
|
73
|
+
@context.set_property('123', 'foo')
|
74
|
+
flunk "Property setting should have failed"
|
75
|
+
rescue
|
76
|
+
end
|
77
|
+
begin
|
78
|
+
@context.get_property('^^^^^123')
|
79
|
+
flunk "Property getting should have failed"
|
80
|
+
rescue
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,467 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2006-2007 Michel Casabianca <michel.casabianca@gmail.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
$:.unshift(File.join(File.dirname(__FILE__)))
|
18
|
+
require 'tmp_test_case'
|
19
|
+
require 'test_build'
|
20
|
+
require 'test_build_listener'
|
21
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
22
|
+
require 'bee'
|
23
|
+
require 'bee_task_default'
|
24
|
+
require 'fileutils'
|
25
|
+
|
26
|
+
# Test default bee tasks.
|
27
|
+
class TestBeeDefaultTasks < TmpTestCase
|
28
|
+
|
29
|
+
# Run before any test: create a context object and load tasks in it.
|
30
|
+
def setup
|
31
|
+
super
|
32
|
+
@context = Bee::Context.new
|
33
|
+
@listener = TestBuildListener.new
|
34
|
+
@build = TestBuild.new(@context, @listener)
|
35
|
+
@package = Bee::Task::Default.new(@build)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Test task print.
|
39
|
+
def test_task_print
|
40
|
+
@package.print('TEST')
|
41
|
+
assert_equal("TEST\n", @listener.output)
|
42
|
+
@listener.output = ''
|
43
|
+
@package.print(['foo', 'bar'])
|
44
|
+
assert_equal("[\"foo\", \"bar\"]\n", @listener.output)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Test task cat.
|
48
|
+
def test_task_cat
|
49
|
+
path = File.join(@tmp_dir, 'test.txt')
|
50
|
+
File.open(path, 'w') {|file| file.write('TEST')}
|
51
|
+
@package.cat(path)
|
52
|
+
assert_equal("TEST\n", @listener.output)
|
53
|
+
@listener.output = ''
|
54
|
+
begin
|
55
|
+
@package.cat('foo')
|
56
|
+
flunk "Cat should have failed"
|
57
|
+
rescue
|
58
|
+
assert_equal("File 'foo' not found", $!.message)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Test task cd.
|
63
|
+
def test_task_cd
|
64
|
+
working_dir = File.expand_path(File.dirname(__FILE__))
|
65
|
+
# test nominal case
|
66
|
+
@package.cd(@tmp_dir)
|
67
|
+
expected = @tmp_dir
|
68
|
+
actual = Dir.getwd
|
69
|
+
assert_equal(expected, actual)
|
70
|
+
# test changing to a directory that doesn't exists
|
71
|
+
begin
|
72
|
+
dir = File.join(@tmp_dir, 'lkjqzcjv')
|
73
|
+
@package.cd(dir)
|
74
|
+
flunk "Should have raised an Errno::ENOENT"
|
75
|
+
rescue Errno::ENOENT
|
76
|
+
end
|
77
|
+
# test bad arguments
|
78
|
+
begin
|
79
|
+
@package.cd(Object.new)
|
80
|
+
flunk "Should have raised a BuildError"
|
81
|
+
rescue Bee::Util::BuildError
|
82
|
+
expected = 'cd parameter is a String'
|
83
|
+
actual = $!.message
|
84
|
+
assert_equal(expected, actual)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Test task mkdir.
|
89
|
+
def test_task_mkdir
|
90
|
+
# nominal case with a single recursive dir
|
91
|
+
dir = File.join(@tmp_dir, 'foo', 'bar')
|
92
|
+
@package.mkdir(dir)
|
93
|
+
expected = true
|
94
|
+
actual = File.exists?(dir) and File.directory?(dir)
|
95
|
+
assert_equal(expected, actual)
|
96
|
+
# nominal case with a list of directories
|
97
|
+
dirs = [File.join(@tmp_dir, 'toto'), File.join(@tmp_dir, 'titi')]
|
98
|
+
@package.mkdir(dirs)
|
99
|
+
found = Dir.entries(@tmp_dir)
|
100
|
+
assert(found.member?('toto'))
|
101
|
+
assert(found.member?('titi'))
|
102
|
+
# error case
|
103
|
+
dir = Object.new
|
104
|
+
begin
|
105
|
+
@package.mkdir(dir)
|
106
|
+
flunk "Should have raised a BuildError"
|
107
|
+
rescue Bee::Util::BuildError => e
|
108
|
+
expected = 'mkdir parameter must a String or an array of Strings'
|
109
|
+
actual = $!.message
|
110
|
+
assert_equal(expected, actual)
|
111
|
+
end
|
112
|
+
# another error case
|
113
|
+
dirs = [File.join(@tmp_dir, 'foo'), Object.new]
|
114
|
+
begin
|
115
|
+
@package.mkdir(dirs)
|
116
|
+
flunk "Should have raised a BuildError"
|
117
|
+
rescue Bee::Util::BuildError => e
|
118
|
+
expected = 'mkdir parameter must a String or an array of Strings'
|
119
|
+
actual = $!.message
|
120
|
+
assert_equal(expected, actual)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Test task cp.
|
125
|
+
def test_task_cp
|
126
|
+
# nominal case for a src and dest file
|
127
|
+
includes = File.join(@tmp_dir, 'file.txt')
|
128
|
+
create_file(includes)
|
129
|
+
dest = File.join(@tmp_dir, 'dest.txt')
|
130
|
+
@package.cp({ 'includes' => includes, 'dest' => dest })
|
131
|
+
assert_file(dest, includes)
|
132
|
+
# nominal case for src files and destination directory
|
133
|
+
clean_tmp
|
134
|
+
includes2 = File.join(@tmp_dir, 'file2.txt')
|
135
|
+
dest = File.join(@tmp_dir, 'dir')
|
136
|
+
create_file(includes)
|
137
|
+
create_file(includes2)
|
138
|
+
FileUtils.makedirs(dest)
|
139
|
+
@package.cp({ 'includes' => [includes, includes2], 'dest' => dest })
|
140
|
+
assert_file(File.join(dest, 'file.txt'), includes)
|
141
|
+
assert_file(File.join(dest, 'file2.txt'), includes2)
|
142
|
+
# nominal case for src and dest directory
|
143
|
+
clean_tmp
|
144
|
+
includes = File.join(@tmp_dir, 'dir')
|
145
|
+
dest = File.join(@tmp_dir, 'todir')
|
146
|
+
FileUtils.makedirs(includes)
|
147
|
+
FileUtils.makedirs(dest)
|
148
|
+
file1 = File.join(includes, 'file1.txt')
|
149
|
+
file2 = File.join(includes, 'file2.txt')
|
150
|
+
create_file(file1)
|
151
|
+
create_file(file2)
|
152
|
+
@package.cp({ 'includes' => includes, 'dest' => dest })
|
153
|
+
assert_file(File.join(dest, 'dir', 'file1.txt'), file1)
|
154
|
+
assert_file(File.join(dest, 'dir', 'file2.txt'), file2)
|
155
|
+
# error case: dest must be a string
|
156
|
+
clean_tmp
|
157
|
+
includes = File.join(@tmp_dir, 'dir')
|
158
|
+
dest = ['foo', 'bar']
|
159
|
+
begin
|
160
|
+
@package.cp({ 'includes' => includes, 'dest' => dest })
|
161
|
+
flunk "Should have failed because dest must be a string"
|
162
|
+
rescue
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Test task mv.
|
167
|
+
def test_task_mv
|
168
|
+
# nominal case for a src and dest file
|
169
|
+
includes = File.join(@tmp_dir, 'src.txt')
|
170
|
+
create_file(includes)
|
171
|
+
dest = File.join(@tmp_dir, 'dest.txt')
|
172
|
+
@package.mv({ 'includes' => includes, 'dest' => dest })
|
173
|
+
assert_file(dest, includes)
|
174
|
+
assert(!File.exists?(File.join(@tmp_dir, includes)))
|
175
|
+
# nominal case with two source files
|
176
|
+
clean_tmp
|
177
|
+
includes = File.join(@tmp_dir, 'src.txt')
|
178
|
+
includes2 = File.join(@tmp_dir, 'src2.txt')
|
179
|
+
dest = File.join(@tmp_dir, 'dir')
|
180
|
+
create_file(includes)
|
181
|
+
create_file(includes2)
|
182
|
+
FileUtils.makedirs(dest)
|
183
|
+
@package.mv({ 'includes' => File.join(@tmp_dir, '*.txt'), 'dest' => dest })
|
184
|
+
assert_file(File.join(dest, 'src.txt'), includes)
|
185
|
+
assert_file(File.join(dest, 'src2.txt'), includes2)
|
186
|
+
assert(!File.exists?(includes))
|
187
|
+
assert(!File.exists?(includes2))
|
188
|
+
# nominal case with directory for src and dest
|
189
|
+
clean_tmp
|
190
|
+
includes = File.join(@tmp_dir, 'dir1')
|
191
|
+
dest = File.join(@tmp_dir, 'dir2')
|
192
|
+
FileUtils.makedirs(includes)
|
193
|
+
create_file(File.join(includes, 'test.txt'))
|
194
|
+
@package.mv({ 'includes' => includes, 'dest' => dest })
|
195
|
+
assert(File.exists?(dest))
|
196
|
+
assert(File.directory?(dest))
|
197
|
+
assert_file(File.join(dest, 'test.txt'), File.join(includes, 'test.txt'))
|
198
|
+
assert(!File.exists?(includes))
|
199
|
+
# error case: dest must be a string
|
200
|
+
clean_tmp
|
201
|
+
includes = File.join(@tmp_dir, 'src.txt')
|
202
|
+
dest = ['foo', 'bar']
|
203
|
+
begin
|
204
|
+
@package.mv({ 'includes' => includes, 'dest' => dest })
|
205
|
+
flunk "Should have failed because dest must be a string"
|
206
|
+
rescue
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# Test task rm.
|
211
|
+
def test_task_rm
|
212
|
+
# nominal case with a glob
|
213
|
+
file = File.join(@tmp_dir, 'test.txt')
|
214
|
+
create_file(file)
|
215
|
+
@package.rm(File.join(@tmp_dir, file))
|
216
|
+
assert(!File.exists?(File.join(@tmp_dir, file)))
|
217
|
+
# nominal case with two globs and three files
|
218
|
+
clean_tmp
|
219
|
+
file1 = File.join(@tmp_dir, 'test1.txt')
|
220
|
+
file2 = File.join(@tmp_dir, 'test2.txt')
|
221
|
+
file3 = File.join(@tmp_dir, 'test3.log')
|
222
|
+
create_file(file1)
|
223
|
+
create_file(file2)
|
224
|
+
create_file(file3)
|
225
|
+
@package.rm([File.join(@tmp_dir, '**/*.txt'),
|
226
|
+
File.join(@tmp_dir, '**/*.log')])
|
227
|
+
assert(!File.exists?(file1))
|
228
|
+
assert(!File.exists?(file2))
|
229
|
+
assert(!File.exists?(file3))
|
230
|
+
# error case: parameter must be a string or array of strings
|
231
|
+
clean_tmp
|
232
|
+
begin
|
233
|
+
@package.rm({ 'foo' => 'bar' })
|
234
|
+
flunk "Shound have failed because parameter must be a string or array"
|
235
|
+
rescue
|
236
|
+
end
|
237
|
+
begin
|
238
|
+
@package.rm(['foo', { 'foo' => 'bar' }])
|
239
|
+
flunk "Shound have failed because parameter must be a string or array"
|
240
|
+
rescue
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
# Test task rmdir.
|
245
|
+
def test_task_rmdir
|
246
|
+
# nominal case with one dir
|
247
|
+
dir = File.join(@tmp_dir, 'dir')
|
248
|
+
FileUtils.makedirs(dir)
|
249
|
+
@package.rmdir(dir)
|
250
|
+
assert(!File.exists?(dir))
|
251
|
+
# nominal case with two dirs
|
252
|
+
clean_tmp
|
253
|
+
dir1 = File.join(@tmp_dir, 'dir1')
|
254
|
+
dir2 = File.join(@tmp_dir, 'dir2')
|
255
|
+
FileUtils.makedirs(dir1)
|
256
|
+
FileUtils.makedirs(dir2)
|
257
|
+
@package.rmdir([dir1, dir2])
|
258
|
+
assert(!File.exists?(dir1))
|
259
|
+
assert(!File.exists?(dir2))
|
260
|
+
# error case: parameter must be a string or array of strings
|
261
|
+
clean_tmp
|
262
|
+
begin
|
263
|
+
@package.rmdir({ 'foo' => 'bar' })
|
264
|
+
flunk "Shound have failed because parameter must be a string or array"
|
265
|
+
rescue
|
266
|
+
end
|
267
|
+
begin
|
268
|
+
@package.rmdir(['foo', { 'foo' => 'bar' }])
|
269
|
+
flunk "Shound have failed because parameter must be a string or array"
|
270
|
+
rescue
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
# Test task find.
|
275
|
+
def test_task_find
|
276
|
+
file1 = File.join(@tmp_dir, 'file1.txt')
|
277
|
+
file2 = File.join(@tmp_dir, 'file2.txt')
|
278
|
+
dir = File.join(@tmp_dir, 'dir')
|
279
|
+
file3 = File.join(dir, 'file3.txt')
|
280
|
+
create_file(file1)
|
281
|
+
create_file(file2)
|
282
|
+
FileUtils.makedirs(dir)
|
283
|
+
create_file(file3)
|
284
|
+
@package.find({ 'includes' => "#{File.join(@tmp_dir, '**/*.txt')}",
|
285
|
+
'property' => 'list'})
|
286
|
+
list = @context.get_property('list').sort
|
287
|
+
expected = [file1, file2, file3].sort
|
288
|
+
assert_equal(expected, list)
|
289
|
+
end
|
290
|
+
|
291
|
+
# Test task test.
|
292
|
+
def test_task_test
|
293
|
+
# TODO: write a test when test task fixed.
|
294
|
+
end
|
295
|
+
|
296
|
+
# Test task erb.
|
297
|
+
def test_task_erb
|
298
|
+
# nominal case in property
|
299
|
+
@context.set_property('test', 'TEST')
|
300
|
+
source = 'This is a <%= test %>'
|
301
|
+
@package.erb({ 'source' => source, 'property' => 'result' })
|
302
|
+
actual = @context.get_property(:result)
|
303
|
+
expected = 'This is a TEST'
|
304
|
+
assert_equal(expected, actual)
|
305
|
+
# nominal case in property
|
306
|
+
file = File.join(@tmp_dir, 'file.txt')
|
307
|
+
@package.erb({ 'source' => source, 'dest' => file })
|
308
|
+
actual = File.read(file)
|
309
|
+
expected = 'This is a TEST'
|
310
|
+
assert_equal(expected, actual)
|
311
|
+
# error case: source parameter must be a string
|
312
|
+
begin
|
313
|
+
@package.erb({ 'source' => [source], 'property' => 'result' })
|
314
|
+
flunk "should have failed because source parameter must be a string"
|
315
|
+
rescue
|
316
|
+
end
|
317
|
+
# error case: src parameter must be a string
|
318
|
+
begin
|
319
|
+
@package.erb({ 'src' => [source], 'property' => 'result' })
|
320
|
+
flunk "should have failed because src parameter must be a string"
|
321
|
+
rescue
|
322
|
+
end
|
323
|
+
# error case: dest parameter must be a string
|
324
|
+
begin
|
325
|
+
@package.erb({ 'src' => 'src', 'dest' => ['dest'] })
|
326
|
+
flunk "should have failed"
|
327
|
+
rescue
|
328
|
+
end
|
329
|
+
# error case: property parameter must be a string
|
330
|
+
begin
|
331
|
+
@package.erb({ 'src' => 'src', 'property' => ['result'] })
|
332
|
+
flunk "should have failed"
|
333
|
+
rescue
|
334
|
+
end
|
335
|
+
# error case: at least src or source parameter
|
336
|
+
begin
|
337
|
+
@package.erb({ 'dest' => 'dest' })
|
338
|
+
flunk "should have failed"
|
339
|
+
rescue
|
340
|
+
end
|
341
|
+
# error case: at least dest or property parameter
|
342
|
+
begin
|
343
|
+
@package.erb({ 'src' => 'src' })
|
344
|
+
flunk "should have failed"
|
345
|
+
rescue
|
346
|
+
end
|
347
|
+
# error case: error in erb source
|
348
|
+
source = 'This is a test <%= foo %>'
|
349
|
+
begin
|
350
|
+
@package.erb({ 'source' => source, 'property' => 'result' })
|
351
|
+
flunk "should have failed"
|
352
|
+
rescue
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
# Test task erb.
|
357
|
+
def test_task_rdoc
|
358
|
+
includes = __FILE__
|
359
|
+
dest = File.join(@tmp_dir, 'rdoc')
|
360
|
+
options = '-q'
|
361
|
+
@package.rdoc({'includes' => includes,
|
362
|
+
'dest' => dest,
|
363
|
+
'options' => options})
|
364
|
+
assert(File.exists?(File.join(dest, 'index.html')))
|
365
|
+
# error case: dest must be a string
|
366
|
+
begin
|
367
|
+
@package.rdoc({'includes' => includes, 'dest' => [dest]})
|
368
|
+
flunk "Should have failed"
|
369
|
+
rescue
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
# Test task zip.
|
374
|
+
def test_task_zip
|
375
|
+
file1 = File.join(@tmp_dir, 'file1.txt')
|
376
|
+
file2 = File.join(@tmp_dir, 'file2.txt')
|
377
|
+
File.open(file1, 'w') {|file| file.write('File 1')}
|
378
|
+
File.open(file2, 'w') {|file| file.write('File 2')}
|
379
|
+
includes = "#{@tmp_dir}/*.txt"
|
380
|
+
dest = File.join(@tmp_dir, 'test.zip')
|
381
|
+
@package.zip({'includes' => includes, 'dest' => dest, 'prefix' => 'test'})
|
382
|
+
# error case: dest must be a string
|
383
|
+
begin
|
384
|
+
@package.zip({'includes' => includes, 'dest' => [dest]})
|
385
|
+
flunk "Shoud have failed"
|
386
|
+
rescue
|
387
|
+
end
|
388
|
+
# error case: prefix must be a string
|
389
|
+
begin
|
390
|
+
@package.zip({'includes' => includes,
|
391
|
+
'dest' => dest,
|
392
|
+
'prefix' => ['test']})
|
393
|
+
flunk "Shoud have failed"
|
394
|
+
rescue
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
# Test task tar.
|
399
|
+
def test_task_tar
|
400
|
+
file1 = File.join(@tmp_dir, 'file1.txt')
|
401
|
+
file2 = File.join(@tmp_dir, 'file2.txt')
|
402
|
+
File.open(file1, 'w') {|file| file.write('File 1')}
|
403
|
+
File.open(file2, 'w') {|file| file.write('File 2')}
|
404
|
+
includes = "#{@tmp_dir}/*.txt"
|
405
|
+
dest = File.join(@tmp_dir, 'test.zip')
|
406
|
+
@package.tar({'includes' => includes, 'dest' => dest})
|
407
|
+
# error case: dest must be a string
|
408
|
+
begin
|
409
|
+
@package.tar({'includes' => includes, 'dest' => [dest]})
|
410
|
+
flunk "Shoud have failed"
|
411
|
+
rescue
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
# Test task gzip.
|
416
|
+
def test_task_gzip
|
417
|
+
src = File.join(@tmp_dir, 'file.txt')
|
418
|
+
File.open(src, 'w') {|file| file.write('File')}
|
419
|
+
dest = File.join(@tmp_dir, 'file.gzip')
|
420
|
+
@package.gzip({'src' => src, 'dest' => dest})
|
421
|
+
# error case: dest must be a string
|
422
|
+
begin
|
423
|
+
@package.gzip({'src' => file, 'dest' => [dest]})
|
424
|
+
flunk "Shoud have failed"
|
425
|
+
rescue
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
# Test task targz.
|
430
|
+
def test_task_targz
|
431
|
+
file1 = File.join(@tmp_dir, 'file1.txt')
|
432
|
+
file2 = File.join(@tmp_dir, 'file2.txt')
|
433
|
+
File.open(file1, 'w') {|file| file.write('File 1')}
|
434
|
+
File.open(file2, 'w') {|file| file.write('File 2')}
|
435
|
+
includes = "#{@tmp_dir}/*.txt"
|
436
|
+
dest = File.join(@tmp_dir, 'test.zip')
|
437
|
+
@package.targz({'includes' => includes, 'dest' => dest})
|
438
|
+
# error case: dest must be a string
|
439
|
+
begin
|
440
|
+
@package.targz({'includes' => includes, 'dest' => [dest]})
|
441
|
+
flunk "Shoud have failed"
|
442
|
+
rescue
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
private
|
447
|
+
|
448
|
+
# Clean temporary directory.
|
449
|
+
def clean_tmp
|
450
|
+
FileUtils.rm_rf(@tmp_dir)
|
451
|
+
FileUtils.makedirs(@tmp_dir)
|
452
|
+
end
|
453
|
+
|
454
|
+
# Create a given file in tmp directory with its name as contents.
|
455
|
+
# - name: file name, relative to temporary directory.
|
456
|
+
def create_file(name)
|
457
|
+
File.open(name, 'w') { |file| file.write(name) }
|
458
|
+
end
|
459
|
+
|
460
|
+
# Assert file exists and test its contents.
|
461
|
+
def assert_file(file, contents)
|
462
|
+
assert(File.exists?(file))
|
463
|
+
text = File.read(file)
|
464
|
+
assert_equal(contents, text)
|
465
|
+
end
|
466
|
+
|
467
|
+
end
|