bee 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/tc_bee_build.rb DELETED
@@ -1,216 +0,0 @@
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_listener'
20
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
21
- require 'bee'
22
-
23
- # Test case for console formatter.
24
- class TestBeeBuild < TmpTestCase
25
-
26
- def test_load
27
- # try loading a build file that doesn't exist
28
- begin
29
- Bee::Build::load('foo')
30
- flunk "Build file should not have been found!"
31
- rescue Bee::Util::BuildError
32
- expected = "Build file 'foo' not found"
33
- actual = $!.message
34
- assert_equal(expected, actual)
35
- end
36
- # try loading a build file that is a directory
37
- begin
38
- Bee::Build::load('.')
39
- flunk "Build file may not be a directory!"
40
- rescue Bee::Util::BuildError
41
- expected = "Build file '.' is not a file"
42
- actual = $!.message
43
- assert_equal(expected, actual)
44
- end
45
- # try running a build that should never fail
46
- build_file = File.join(@tmp_dir, 'build.yml')
47
- begin
48
- source = '- target: test
49
- script:
50
- - print: "Hello World!"'
51
- File.open(build_file, 'w') {|file| file.write(source)}
52
- listener = TestBuildListener.new
53
- build = Bee::Build::load(build_file)
54
- build.run('', listener)
55
- ensure
56
- File.delete(build_file)
57
- end
58
- # try loading a build file with YAML syntax error
59
- begin
60
- source =
61
- '- target: test
62
- script: \"test\"'
63
- File.open(build_file, 'w') {|file| file.write(source)}
64
- build = Bee::Build::load(build_file)
65
- flunk "Should fail to parse YAML file!"
66
- rescue Bee::Util::BuildError
67
- expected = "YAML syntax error in build file: syntax error on line 1, " +
68
- "col 10: ` script: \\\"test\\\"'"
69
- actual = $!.message
70
- assert_equal(expected, actual)
71
- ensure
72
- File.delete(build_file)
73
- end
74
- # try loading a build file that is a YAML string
75
- begin
76
- source = 'foo'
77
- File.open(build_file, 'w') {|file| file.write(source)}
78
- build = Bee::Build::load(build_file)
79
- flunk "Build object must be a list!"
80
- rescue Bee::Util::BuildError
81
- expected = "Build must be a list"
82
- actual = $!.message
83
- assert_equal(expected, actual)
84
- ensure
85
- File.delete(build_file)
86
- end
87
- end
88
-
89
- def test_initialize
90
- # try loading a build object (resulting from loading YAML file) that is not
91
- # a list
92
- begin
93
- Bee::Build.new(Object.new, nil)
94
- flunk "Build object must be a list!"
95
- rescue Bee::Util::BuildError
96
- expected = "Build must be a list"
97
- actual = $!.message
98
- assert_equal(expected, actual)
99
- end
100
- # try loading a build object with two build info entries
101
- object = [{'build' => 'test'}, {'build' => 'test'}]
102
- begin
103
- Bee::Build.new(object, nil)
104
- flunk "Build can't have duplicate info entries!"
105
- rescue Bee::Util::BuildError
106
- expected = "Duplicate build info"
107
- actual = $!.message
108
- assert_equal(expected, actual)
109
- end
110
- # try loading a build object defining a context
111
- context_file = 'context.rb'
112
- context_path = File.join(@tmp_dir, context_file)
113
- context_source = 'def test
114
- set_property(:tested, true)
115
- end'
116
- File.open(context_path, 'w') {|file| file.write(context_source)}
117
- object = [{'build' => 'test', 'context' => context_file},
118
- {'target' => 'test', 'script' => [{'rb' => 'test'}]}]
119
- listener = TestBuildListener.new
120
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
121
- build.run('', listener)
122
- assert(build.context.get_property(:tested))
123
- assert(listener.started)
124
- assert(listener.finished)
125
- assert(!listener.errors)
126
- # try loading a buggy context
127
- context_file = 'context.rb'
128
- context_path = File.join(@tmp_dir, context_file)
129
- context_source = 'def test end'
130
- File.open(context_path, 'w') {|file| file.write(context_source)}
131
- object = [{'build' => 'test', 'context' => context_file},
132
- {'target' => 'test', 'script' => [{'rb' => 'test'}]}]
133
- listener = TestBuildListener.new
134
- begin
135
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
136
- flunk "Should have raised a BuildError"
137
- rescue Bee::Util::BuildError
138
- assert_match(/Error loading context 'context.rb': compile error/,
139
- $!.message)
140
- end
141
- # load a build defining properties
142
- object = [{'properties' => [{'foo' => 'bar'}]}]
143
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
144
- assert_equal(build.context.get_property(:foo), 'bar')
145
- # load a build defining duplicate properties
146
- object = [{'properties' => [{'foo' => 'bar'}, {'foo' => 'bar'}]}]
147
- begin
148
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
149
- rescue Bee::Util::BuildError
150
- assert_equal("Property 'foo' was already defined", $!.message)
151
- end
152
- # load a build with unknown entry
153
- object = [{'foo' => 'bar'}]
154
- begin
155
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
156
- rescue Bee::Util::BuildError
157
- assert_match("Unknown entry:", $!.message)
158
- end
159
- # try running a buggy build with a listener
160
- object = [{'target' => 'test', 'script' => [{'foo' => 'bar'}]}]
161
- listener = TestBuildListener.new
162
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
163
- build.run('', listener)
164
- assert(listener.started)
165
- assert(!listener.finished)
166
- assert(listener.errors)
167
- # try running a buggy build without a listener
168
- object = [{'target' => 'test', 'script' => [{'foo' => 'bar'}]}]
169
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
170
- begin
171
- build.run('', nil)
172
- rescue Bee::Util::BuildError
173
- assert_equal("Task 'foo' not found in package 'default'", $!.message)
174
- end
175
- # try running a build with dependencies
176
- target1 = {'target' => 'test1',
177
- 'script' => [{'rb' => 'set_property(:foo, "bar")'}]}
178
- target2 = {'target' => 'test2', 'depends' => 'test1'}
179
- object = [target2, target1]
180
- listener = TestBuildListener.new
181
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
182
- build.run('', listener)
183
- assert(listener.started)
184
- assert(listener.finished)
185
- assert(!listener.errors)
186
- assert_equal(['test1', 'test2'],
187
- listener.targets.collect {|target| target.name})
188
- # run a task with two keys
189
- object = [{'target' => 'test',
190
- 'script' => [{'foo' => 'bar', 'spam' => 'eggs'}]}]
191
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
192
- begin
193
- build.run('', nil)
194
- rescue Bee::Util::BuildError
195
- assert_equal("A task entry must be a Hash with a single key", $!.message)
196
- end
197
- # run a buggy Ruby script
198
- object = [{'target' => 'test', 'script' => [{'rb' => 'bar'}]}]
199
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
200
- begin
201
- build.run('', nil)
202
- rescue Bee::Util::BuildError
203
- assert_match(/Error running Ruby script/, $!.message)
204
- end
205
- # run a buggy Ruby script (with bad property reference)
206
- object = [{'target' => 'test', 'script' => [{'print' => :bar}]}]
207
- build = Bee::Build.new(object, File.join(@tmp_dir, 'build.yml'))
208
- begin
209
- build.run('', nil)
210
- rescue Bee::Util::BuildError
211
- assert_match(/Property 'bar' was not set/,
212
- $!.message)
213
- end
214
- end
215
-
216
- end
@@ -1,106 +0,0 @@
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
- require 'stringio'
19
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
20
- require 'bee_console'
21
- $:.unshift(File.dirname(__FILE__))
22
- require 'tmp_test_case'
23
-
24
- # Test context.
25
- class TestBeeConsole < TmpTestCase
26
-
27
- def test_parse_command_line
28
- ARGV.replace(['-h', '-b', '-k', 'foo', '-t', '-v', '-s', 'bar', '-f', 'spam', 'eggs'])
29
- actual = Bee::Console.parse_command_line
30
- expected = [true, true, true, 'foo', true, true, 'bar', 'spam', false, ['eggs']]
31
- assert_equal(expected, actual)
32
- end
33
-
34
- def test_start_command_line
35
- stdout = $stdout
36
- stderr = $stderr
37
- output = StringIO.new
38
- $stdout = $stderr = output
39
- begin
40
- # nominal case starting a build from command line
41
- build_file = 'test.yml'
42
- build_path = File.join(@tmp_dir, build_file)
43
- source = '- target: test
44
- script: "cd ."'
45
- File.open(build_path, 'w') {|file| file.write(source)}
46
- ARGV.replace(['-f', build_path])
47
- Bee::Console.start_command_line
48
- # error parsing command line arguments
49
- ARGV.replace(['-z'])
50
- begin
51
- Bee::Console.start_command_line
52
- flunk "Command line parsing should have failed"
53
- rescue SystemExit => e
54
- assert_equal(Bee::Console::EXIT_PARSING_CMDLINE, e.status)
55
- end
56
- # help command
57
- ARGV.replace(['-h'])
58
- Bee::Console.start_command_line
59
- # build help
60
- build_file = 'test.yml'
61
- build_path = File.join(@tmp_dir, build_file)
62
- source = '- target: test
63
- script: "cd ."'
64
- File.open(build_path, 'w') {|file| file.write(source)}
65
- ARGV.replace(['-f', build_path, '-b'])
66
- Bee::Console.start_command_line
67
- # task help
68
- ARGV.replace(['-k', 'print'])
69
- Bee::Console.start_command_line
70
- # task help
71
- ARGV.replace(['-k', '?'])
72
- Bee::Console.start_command_line
73
- # error task help
74
- ARGV.replace(['-k', 'foo'])
75
- begin
76
- Bee::Console.start_command_line
77
- flunk "Should have failed"
78
- rescue Exception
79
- end
80
- # template generation
81
- build_file = 'test.yml'
82
- build_path = File.join(@tmp_dir, build_file)
83
- File.delete(build_path)
84
- build_path = File.join(build_path)
85
- ARGV.replace(['-f', build_path, '-t'])
86
- Bee::Console.start_command_line
87
- # template generation with a build file that already exists
88
- begin
89
- build_file = 'test.yml'
90
- build_path = File.join(@tmp_dir, build_file)
91
- build_path = File.join(build_path)
92
- ARGV.replace(['-f', build_path, '-t'])
93
- Bee::Console.start_command_line
94
- flunk "Template generation should have failed"
95
- rescue SystemExit => e
96
- assert_equal(Bee::Console::EXIT_BUILD_ERROR, e.status)
97
- end
98
- # test unknown internal error
99
- # TODO
100
- ensure
101
- $stdout = stdout
102
- $stderr = stderr
103
- end
104
- end
105
-
106
- end
@@ -1,81 +0,0 @@
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
- require 'bee_console'
21
-
22
- # Test case for console formatter.
23
- class TestBeeConsoleFormatter < Test::Unit::TestCase
24
-
25
- # Test default target title formatting.
26
- def test_format_target_default
27
- expected = "#{'-'*72} TEST --"
28
- formatter = Bee::Console::Formatter.new('ll:80')
29
- target = Bee::Target.new({ 'target' => 'TEST' }, nil)
30
- actual = formatter.format_target(target)
31
- assert_equal(expected, actual)
32
- end
33
-
34
- # Test target title formatting with colorization.
35
- def test_format_target
36
- expected = "\e[1;31;42m#{'#'*64} TEST ##\e[0m"
37
- style = {
38
- :line_character => '#',
39
- :line_length => 72,
40
- :target_style => :bright,
41
- :target_foreground => :red,
42
- :target_background => :green
43
- }
44
- formatter = Bee::Console::Formatter.new(style)
45
- target = Bee::Target.new({ 'target' => 'TEST' }, nil)
46
- actual = formatter.format_target(target)
47
- assert_equal(expected, actual)
48
- end
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
-
81
- end
@@ -1,84 +0,0 @@
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