rake-builder 0.9.2 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +13 -0
- data/lib/rake/builder/version.rb +2 -2
- data/lib/rake/microsecond_task.rb +2 -4
- data/spec/unit/compiler_spec.rb +10 -17
- data/spec/unit/rake/builder/autoconf/version_spec.rb +44 -56
- data/spec/unit/rake/builder/configure_ac_spec.rb +5 -10
- data/spec/unit/rake/builder/install_spec.rb +67 -56
- data/spec/unit/rake/builder/local_config_spec.rb +23 -34
- data/spec/unit/rake/builder/presenters/makefile/builder_presenter_spec.rb +22 -19
- data/spec/unit/rake/builder/presenters/makefile_am/builder_collection_presenter_spec.rb +8 -22
- data/spec/unit/rake/builder/presenters/makefile_am/builder_presenter_spec.rb +14 -23
- data/spec/unit/rake/builder/task_definers/builder_collection_task_definer_spec.rb +19 -10
- data/spec/unit/rake/builder/task_definers/builder_task_definer_spec.rb +77 -110
- data/spec/unit/rake/builder_spec.rb +76 -89
- data/spec/unit/rake/microsecond_task_spec.rb +35 -26
- data/spec/unit/rake/path_spec.rb +24 -11
- metadata +65 -81
@@ -15,27 +15,25 @@ describe Rake::Builder do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
let(:installer) do
|
18
|
-
|
19
|
-
'Rake::Builder::Installer',
|
20
|
-
:install => nil
|
21
|
-
)
|
18
|
+
double(Rake::Builder::Installer, install: nil, uninstall: nil)
|
22
19
|
end
|
23
20
|
|
24
21
|
before do
|
25
|
-
Rake::Path.
|
22
|
+
allow(Rake::Path).to receive(:find_files) { source_paths }
|
23
|
+
allow(builder).to receive(:system)
|
26
24
|
end
|
27
25
|
|
28
26
|
context '.create_autoconf' do
|
29
|
-
let(:version) {
|
30
|
-
let(:presenter) {
|
31
|
-
let(:configure_ac) {
|
27
|
+
let(:version) { double('Rake::Builder::Autoconf::Autoconf::Version', :decide => 'qux') }
|
28
|
+
let(:presenter) { double('Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter', :save => nil) }
|
29
|
+
let(:configure_ac) { double('Rake::Builder::ConfigureAc', :save => nil) }
|
32
30
|
|
33
31
|
before do
|
34
|
-
Rake::Builder::Autoconf::Version.
|
35
|
-
File.
|
36
|
-
File.
|
37
|
-
Rake::Builder::ConfigureAc.
|
38
|
-
Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter.
|
32
|
+
allow(Rake::Builder::Autoconf::Version).to receive(:new) { version }
|
33
|
+
allow(File).to receive(:exist?).with('configure.ac') { false }
|
34
|
+
allow(File).to receive(:exist?).with('Makefile.am') { false }
|
35
|
+
allow(Rake::Builder::ConfigureAc).to receive(:new) { configure_ac }
|
36
|
+
allow(Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter).to receive(:new) { presenter }
|
39
37
|
end
|
40
38
|
|
41
39
|
it 'fails if project_title is nil' do
|
@@ -44,16 +42,20 @@ describe Rake::Builder do
|
|
44
42
|
}.to raise_error(RuntimeError, 'Please supply a project_title parameter')
|
45
43
|
end
|
46
44
|
|
47
|
-
|
48
|
-
|
45
|
+
context 'if Version fails' do
|
46
|
+
before do
|
47
|
+
allow(Rake::Builder::Autoconf::Version).to receive(:new).and_raise('foo')
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
it 'fails' do
|
51
|
+
expect {
|
52
|
+
Rake::Builder.create_autoconf('foo', 'bar', 'baz')
|
53
|
+
}.to raise_error(RuntimeError, 'foo')
|
54
|
+
end
|
53
55
|
end
|
54
56
|
|
55
57
|
it 'fails if configure.ac exists' do
|
56
|
-
File.
|
58
|
+
allow(File).to receive(:exist?).with('configure.ac') { true }
|
57
59
|
|
58
60
|
expect {
|
59
61
|
Rake::Builder.create_autoconf('foo', 'bar', 'baz')
|
@@ -61,7 +63,7 @@ describe Rake::Builder do
|
|
61
63
|
end
|
62
64
|
|
63
65
|
it 'fails if Makefile.am exists' do
|
64
|
-
File.
|
66
|
+
allow(File).to receive(:exist?).with('Makefile.am') { true }
|
65
67
|
|
66
68
|
expect {
|
67
69
|
Rake::Builder.create_autoconf('foo', 'bar', 'baz')
|
@@ -69,13 +71,13 @@ describe Rake::Builder do
|
|
69
71
|
end
|
70
72
|
|
71
73
|
it 'creates configure.ac' do
|
72
|
-
Rake::Builder::ConfigureAc.
|
74
|
+
allow(Rake::Builder::ConfigureAc).to receive(:new) { configure_ac }
|
73
75
|
|
74
76
|
Rake::Builder.create_autoconf('foo', 'bar', 'baz')
|
75
77
|
end
|
76
78
|
|
77
79
|
it 'creates Makefile.am' do
|
78
|
-
Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter.
|
80
|
+
allow(Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter).to receive(:new) { presenter }
|
79
81
|
|
80
82
|
Rake::Builder.create_autoconf('foo', 'bar', 'baz')
|
81
83
|
end
|
@@ -107,7 +109,7 @@ describe Rake::Builder do
|
|
107
109
|
end
|
108
110
|
|
109
111
|
it 'remembers the Rakefile path' do
|
110
|
-
Rake::Path.
|
112
|
+
allow(Rake::Path).to receive(:find_files) { ['main.cpp'] }
|
111
113
|
here = File.dirname(File.expand_path(__FILE__))
|
112
114
|
|
113
115
|
builder = Rake::Builder.new {}
|
@@ -119,13 +121,12 @@ describe Rake::Builder do
|
|
119
121
|
context '#build' do
|
120
122
|
before do
|
121
123
|
@target_exists = [false, true]
|
122
|
-
File.
|
123
|
-
builder.stub(:system => nil)
|
124
|
+
allow(File).to receive(:exist?).with(builder.target) { @target_exists.shift }
|
124
125
|
`(exit 0)` # set $? to a successful Process::Status
|
125
126
|
end
|
126
127
|
|
127
128
|
it 'checks if the old target exists' do
|
128
|
-
File.
|
129
|
+
allow(File).to receive(:exist?).with(builder.target) { @target_exists.shift }
|
129
130
|
|
130
131
|
builder.build
|
131
132
|
end
|
@@ -133,7 +134,7 @@ describe Rake::Builder do
|
|
133
134
|
it 'deletes the old target' do
|
134
135
|
@target_exists = [true, true]
|
135
136
|
|
136
|
-
File.
|
137
|
+
allow(File).to receive(:unlink).with(builder.target)
|
137
138
|
|
138
139
|
builder.build
|
139
140
|
end
|
@@ -158,15 +159,14 @@ describe Rake::Builder do
|
|
158
159
|
context '#run' do
|
159
160
|
before do
|
160
161
|
@old_dir = Dir.pwd
|
161
|
-
Dir.
|
162
|
-
|
163
|
-
Dir.stub(:chdir).with(@old_dir)
|
162
|
+
allow(Dir).to receive(:chdir).with(builder.rakefile_path)
|
163
|
+
allow(Dir).to receive(:chdir).with(@old_dir)
|
164
164
|
# Run a successful command, so Process:Status $? gets set to success
|
165
165
|
`ls`
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'changes directory to the Rakefile path' do
|
169
|
-
Dir.
|
169
|
+
allow(Dir).to receive(:chdir).with(builder.rakefile_path)
|
170
170
|
|
171
171
|
capturing_output do
|
172
172
|
builder.run
|
@@ -174,27 +174,27 @@ describe Rake::Builder do
|
|
174
174
|
end
|
175
175
|
|
176
176
|
it 'runs the executable' do
|
177
|
-
builder.should_receive(:system).with('./' + builder.target, anything)
|
178
|
-
|
179
177
|
capturing_output do
|
180
178
|
builder.run
|
181
179
|
end
|
180
|
+
|
181
|
+
expect(builder).to have_received(:system).with('./' + builder.target, anything)
|
182
182
|
end
|
183
183
|
|
184
184
|
context 'target_parameters' do
|
185
185
|
let(:target_parameters) { %w(--ciao) }
|
186
186
|
|
187
187
|
it 'are passed as command line options to the target' do
|
188
|
-
builder.should_receive(:system).with("./#{builder.target} --ciao", anything)
|
189
|
-
|
190
188
|
capturing_output do
|
191
189
|
builder.run
|
192
190
|
end
|
191
|
+
|
192
|
+
expect(builder).to have_received(:system).with("./#{builder.target} --ciao", anything)
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
196
|
it 'outputs the stdout results, then the stderr results' do
|
197
|
-
builder.
|
197
|
+
allow(builder).to receive(:system) do |command|
|
198
198
|
$stdout.puts 'standard output'
|
199
199
|
$stderr.puts 'error output'
|
200
200
|
end
|
@@ -208,7 +208,7 @@ describe Rake::Builder do
|
|
208
208
|
end
|
209
209
|
|
210
210
|
it 'raises and error is the program does not run successfully' do
|
211
|
-
builder.
|
211
|
+
allow(builder).to receive(:system) { `(exit 1)` } # set $? to a failing Process::Status
|
212
212
|
|
213
213
|
expect {
|
214
214
|
builder.run
|
@@ -216,18 +216,18 @@ describe Rake::Builder do
|
|
216
216
|
end
|
217
217
|
|
218
218
|
it 'restores the preceding working directory, even after errors' do
|
219
|
-
builder.
|
220
|
-
|
221
|
-
Dir.should_receive(:chdir).with(@old_dir)
|
219
|
+
allow(builder).to receive(:system).and_raise('foo')
|
222
220
|
|
223
221
|
builder.run rescue nil
|
222
|
+
|
223
|
+
expect(Dir).to have_received(:chdir).with(@old_dir)
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
227
|
context '#clean' do
|
228
228
|
it 'checks if files exist' do
|
229
229
|
exists = []
|
230
|
-
File.
|
230
|
+
allow(File).to receive(:exist?) { |file| exists << file; false }
|
231
231
|
|
232
232
|
builder.clean
|
233
233
|
|
@@ -236,8 +236,8 @@ describe Rake::Builder do
|
|
236
236
|
|
237
237
|
it 'deletes generated files' do
|
238
238
|
deletes = []
|
239
|
-
File.
|
240
|
-
File.
|
239
|
+
allow(File).to receive(:exist?) { true }
|
240
|
+
allow(File).to receive(:unlink) { |file| deletes << file }
|
241
241
|
|
242
242
|
builder.clean
|
243
243
|
|
@@ -267,7 +267,7 @@ describe Rake::Builder do
|
|
267
267
|
|
268
268
|
context '#target' do
|
269
269
|
it "defaults to 'a.out'" do
|
270
|
-
Rake::Path.
|
270
|
+
allow(Rake::Path).to receive(:find_files) { ['main.cpp'] }
|
271
271
|
|
272
272
|
builder = Rake::Builder.new {}
|
273
273
|
|
@@ -296,7 +296,7 @@ describe Rake::Builder do
|
|
296
296
|
['libshared.so', :shared_library],
|
297
297
|
].each do |name, type|
|
298
298
|
it "recognises '#{name}' as '#{type}'" do
|
299
|
-
Rake::Path.
|
299
|
+
allow(Rake::Path).to receive(:find_files) { ['file'] }
|
300
300
|
|
301
301
|
builder = Rake::Builder.new { |b| b.target = name }
|
302
302
|
|
@@ -322,17 +322,17 @@ describe Rake::Builder do
|
|
322
322
|
|
323
323
|
context '#source_files' do
|
324
324
|
it 'finds files with the .cpp extension' do
|
325
|
-
Rake::Path.
|
325
|
+
allow(Rake::Path).to receive(:find_files).with(anything, 'cpp') { ['a.cpp'] }
|
326
326
|
|
327
327
|
builder
|
328
328
|
end
|
329
329
|
|
330
330
|
it 'should allow configuration of source extension' do
|
331
|
-
Rake::Path.should_receive(:find_files).with(anything, 'cc').and_return(['a.cc'])
|
332
|
-
|
333
331
|
Rake::Builder.new do |b|
|
334
332
|
b.source_file_extension = 'cc'
|
335
333
|
end
|
334
|
+
|
335
|
+
expect(Rake::Path).to have_received(:find_files).with(anything, 'cc') { ['a.cc'] }
|
336
336
|
end
|
337
337
|
end
|
338
338
|
|
@@ -362,15 +362,15 @@ describe Rake::Builder do
|
|
362
362
|
|
363
363
|
context '#create_makedepend_file' do
|
364
364
|
before do
|
365
|
-
builder.
|
365
|
+
allow(builder).to receive(:system).with('which makedepend >/dev/null') do
|
366
366
|
`(exit 0)` # set $? to a successful Process::Status
|
367
367
|
end
|
368
368
|
|
369
|
-
builder.
|
369
|
+
allow(builder).to receive(:system).with(/makedepend -f-/, anything)
|
370
370
|
end
|
371
371
|
|
372
372
|
it 'fails if makedepend is missing' do
|
373
|
-
builder.
|
373
|
+
allow(builder).to receive(:system).with('which makedepend >/dev/null') do
|
374
374
|
`(exit 1)` # set $? to a successful Process::Status
|
375
375
|
end
|
376
376
|
|
@@ -380,9 +380,9 @@ describe Rake::Builder do
|
|
380
380
|
end
|
381
381
|
|
382
382
|
it 'calls makedepend' do
|
383
|
-
builder.should_receive(:system).with(/makedepend -f-/, anything)
|
384
|
-
|
385
383
|
builder.create_makedepend_file
|
384
|
+
|
385
|
+
expect(builder).to have_received(:system).with(/makedepend -f-/, anything)
|
386
386
|
end
|
387
387
|
end
|
388
388
|
|
@@ -398,13 +398,7 @@ describe Rake::Builder do
|
|
398
398
|
end
|
399
399
|
|
400
400
|
before do
|
401
|
-
File.
|
402
|
-
end
|
403
|
-
|
404
|
-
it 'opens the file' do
|
405
|
-
File.should_receive(:read).with(builder.makedepend_file).and_return(content)
|
406
|
-
|
407
|
-
builder.load_makedepend
|
401
|
+
allow(File).to receive(:read).with(builder.makedepend_file) { content }
|
408
402
|
end
|
409
403
|
|
410
404
|
it 'returns a map of sources to headers' do
|
@@ -421,7 +415,7 @@ describe Rake::Builder do
|
|
421
415
|
let(:config_include_paths) { ['/path/one', '/path/two'] }
|
422
416
|
let(:config_compilation_options) { ['opt1', 'opt2'] }
|
423
417
|
let(:local_config) do
|
424
|
-
|
418
|
+
double(
|
425
419
|
'Rake::Builder::LocalConfig',
|
426
420
|
:load => nil,
|
427
421
|
:include_paths => config_include_paths,
|
@@ -429,14 +423,15 @@ describe Rake::Builder do
|
|
429
423
|
)
|
430
424
|
end
|
431
425
|
|
432
|
-
before { Rake::Builder::LocalConfig.
|
426
|
+
before { allow(Rake::Builder::LocalConfig).to receive(:new) { local_config } }
|
433
427
|
|
434
428
|
it 'loads local config' do
|
435
|
-
Rake::Builder::LocalConfig.
|
436
|
-
with(/\.rake-builder/)
|
437
|
-
local_config.should_receive(:load).with()
|
429
|
+
allow(Rake::Builder::LocalConfig).to receive(:new).
|
430
|
+
with(/\.rake-builder/) { local_config }
|
438
431
|
|
439
432
|
builder.load_local_config
|
433
|
+
|
434
|
+
expect(local_config).to have_received(:load).with(no_args)
|
440
435
|
end
|
441
436
|
|
442
437
|
it 'adds include paths' do
|
@@ -458,7 +453,7 @@ describe Rake::Builder do
|
|
458
453
|
|
459
454
|
context '#create_local_config' do
|
460
455
|
let(:compiler) do
|
461
|
-
|
456
|
+
double(
|
462
457
|
'Compiler',
|
463
458
|
:default_include_paths => [],
|
464
459
|
:missing_headers => [],
|
@@ -466,7 +461,7 @@ describe Rake::Builder do
|
|
466
461
|
)
|
467
462
|
end
|
468
463
|
let(:local_config) do
|
469
|
-
|
464
|
+
double(
|
470
465
|
'Rake::Builder::LocalConfig',
|
471
466
|
:include_paths= => nil,
|
472
467
|
:save => nil
|
@@ -474,39 +469,28 @@ describe Rake::Builder do
|
|
474
469
|
end
|
475
470
|
|
476
471
|
before do
|
477
|
-
Compiler::Base.
|
478
|
-
Rake::Builder::LocalConfig.
|
479
|
-
end
|
480
|
-
|
481
|
-
it 'gets extra paths for missing headers' do
|
482
|
-
compiler.should_receive(:missing_headers).
|
483
|
-
with(['./include'], source_paths).
|
484
|
-
and_return([])
|
485
|
-
|
486
|
-
builder.create_local_config
|
472
|
+
allow(Compiler::Base).to receive(:for).with(:gcc) { compiler }
|
473
|
+
allow(Rake::Builder::LocalConfig).to receive(:new) { local_config }
|
487
474
|
end
|
488
475
|
|
489
476
|
it 'saves a LocalConfig' do
|
490
|
-
local_config.should_receive(:save)
|
491
|
-
|
492
477
|
builder.create_local_config
|
478
|
+
|
479
|
+
expect(local_config).to have_received(:save)
|
493
480
|
end
|
494
481
|
end
|
495
482
|
|
496
483
|
context '#install' do
|
497
|
-
before { Rake::Builder::Installer.
|
484
|
+
before { allow(Rake::Builder::Installer).to receive(:new) { installer } }
|
498
485
|
|
499
486
|
it 'installs the target' do
|
500
|
-
Rake::Builder::Installer.should_receive(:new).and_return(installer)
|
501
|
-
installer.should_receive(:install).with(builder.target, anything)
|
502
|
-
|
503
487
|
builder.install
|
488
|
+
|
489
|
+
expect(Rake::Builder::Installer).to have_received(:new) { installer }
|
504
490
|
end
|
505
491
|
|
506
492
|
it 'installs headers for static libraries' do
|
507
|
-
|
508
|
-
File.should_receive(:file?).with('header.h').and_return(true)
|
509
|
-
installer.should_receive(:install).with('header.h', anything)
|
493
|
+
allow(File).to receive(:file?).with('header.h') { true }
|
510
494
|
|
511
495
|
builder = Rake::Builder.new do |b|
|
512
496
|
b.target = 'libthe_static_library.a'
|
@@ -514,18 +498,21 @@ describe Rake::Builder do
|
|
514
498
|
end
|
515
499
|
|
516
500
|
builder.install
|
501
|
+
|
502
|
+
expect(installer).to have_received(:install).with(builder.target, anything)
|
503
|
+
expect(installer).to have_received(:install).with('header.h', anything)
|
517
504
|
end
|
518
505
|
end
|
519
506
|
|
520
507
|
context '#uninstall' do
|
521
|
-
before { Rake::Builder::Installer.
|
508
|
+
before { allow(Rake::Builder::Installer).to receive(:new) { installer } }
|
522
509
|
|
523
510
|
it 'uninstalls' do
|
524
511
|
installed_path = File.join(builder.install_path, builder.target_basename)
|
525
|
-
installer.should_receive(:uninstall).with(installed_path)
|
526
512
|
|
527
513
|
builder.uninstall
|
514
|
+
|
515
|
+
expect(installer).to have_received(:uninstall).with(installed_path)
|
528
516
|
end
|
529
517
|
end
|
530
518
|
end
|
531
|
-
|
@@ -2,61 +2,70 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Rake::Microsecond::DirectoryTask do
|
4
4
|
let(:path) { '/a/path' }
|
5
|
-
|
6
|
-
|
7
|
-
task.stub(:mkdir_p => nil)
|
8
|
-
task
|
9
|
-
end
|
5
|
+
|
6
|
+
subject { described_class.define_task(path) }
|
10
7
|
|
11
8
|
before do
|
9
|
+
allow(subject).to receive(:mkdir_p)
|
12
10
|
Rake::Task.clear
|
13
11
|
end
|
14
12
|
|
15
13
|
context '#needed?' do
|
16
|
-
let(:
|
17
|
-
let(:
|
18
|
-
let(:
|
19
|
-
let(:
|
20
|
-
let(:
|
14
|
+
let(:directory_task) { instance_double(Rake::Microsecond::DirectoryTask) }
|
15
|
+
let(:file_task) { instance_double(Rake::FileTask, timestamp: file_timestamp) }
|
16
|
+
let(:needed_task) { double(Rake::Task, needed?: true) }
|
17
|
+
let(:unneeded_task) { double(Rake::Task, needed?: false) }
|
18
|
+
let(:directory_mtime) { 33 }
|
19
|
+
let(:file_timestamp) { directory_mtime + 1 }
|
21
20
|
|
22
21
|
context 'when the directory exists' do
|
22
|
+
let(:exists) { true }
|
23
|
+
let(:stat) { double(mtime: directory_mtime) }
|
24
|
+
|
23
25
|
before do
|
24
|
-
File.
|
25
|
-
File.
|
26
|
+
allow(File).to receive(:directory?) { exists }
|
27
|
+
allow(File).to receive(:stat) { stat }
|
28
|
+
allow(Rake.application).to receive(:[]).with(:directory_task) { directory_task }
|
29
|
+
allow(directory_task).to receive(:is_a?).with(described_class) { true }
|
30
|
+
allow(Rake.application).to receive(:[]).with(:file_task) { file_task }
|
31
|
+
allow(file_task).to receive(:is_a?).with(Rake::FileTask) { true }
|
32
|
+
allow(file_task).to receive(:is_a?).with(described_class) { false }
|
33
|
+
allow(Rake.application).to receive(:[]).with(:needed) { needed_task }
|
34
|
+
allow(Rake.application).to receive(:[]).with(:unneeded) { unneeded_task }
|
26
35
|
end
|
27
36
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
37
|
+
context 'if a prerequisite FileTask is more recent' do
|
38
|
+
|
39
|
+
it 'is needed' do
|
40
|
+
subject.enhance([:file_task])
|
32
41
|
|
33
|
-
|
42
|
+
expect(subject).to be_needed
|
43
|
+
end
|
34
44
|
end
|
35
45
|
|
36
46
|
it 'true if a prerequisite non-FileTask is needed?' do
|
37
|
-
|
47
|
+
subject.enhance([:needed])
|
38
48
|
|
39
|
-
expect(
|
49
|
+
expect(subject).to be_needed
|
40
50
|
end
|
41
51
|
|
42
52
|
it 'false otherwise' do
|
43
|
-
|
44
|
-
unneeded_task.stub(:needed? => false)
|
53
|
+
subject.enhance([:unneeded])
|
45
54
|
|
46
|
-
expect(
|
55
|
+
expect(subject).to_not be_needed
|
47
56
|
end
|
48
57
|
end
|
49
58
|
end
|
50
59
|
|
51
60
|
context '#execute' do
|
52
|
-
let(:
|
61
|
+
let(:now) { 12345 }
|
53
62
|
|
54
63
|
it 'memorizes the directory creation time including fractional seconds' do
|
55
|
-
Time.
|
64
|
+
allow(Time).to receive(:now) { now }
|
56
65
|
|
57
|
-
|
66
|
+
subject.execute
|
58
67
|
|
59
|
-
expect(
|
68
|
+
expect(subject.timestamp).to eq(now)
|
60
69
|
end
|
61
70
|
end
|
62
71
|
end
|