76 lines
2.2 KiB
Ruby
76 lines
2.2 KiB
Ruby
require 'fileutils'
|
|
|
|
describe Rscons do
|
|
FileUtils.rm_rf('build_test')
|
|
|
|
def setup_testdir(files, &blk)
|
|
FileUtils.mkdir_p('build_test')
|
|
files.each do |fname|
|
|
src = "spec/build_items/#{fname}"
|
|
dst = "build_test/#{fname}"
|
|
FileUtils.mkdir_p(File.dirname(dst))
|
|
FileUtils.cp_r(src, dst)
|
|
end
|
|
Dir.chdir('build_test', &blk)
|
|
FileUtils.rm_rf('build_test')
|
|
end
|
|
|
|
def clear_cache
|
|
Rscons::Cache.open.clear
|
|
end
|
|
|
|
before do
|
|
$stdout.stub(:puts) { nil }
|
|
clear_cache
|
|
end
|
|
|
|
###########################################################################
|
|
# Build Tests
|
|
###########################################################################
|
|
|
|
it 'builds a C program with one source file' do
|
|
setup_testdir(['simple.c']) do
|
|
env = Rscons::Environment.new
|
|
env.Program('simple', 'simple.c')
|
|
File.exist?('simple.o').should be_true
|
|
`./simple`.should =~ /This is a simple C program/
|
|
end
|
|
end
|
|
|
|
it 'supports short echo mode' do
|
|
$stdout.should_receive(:puts).once.with('CC simple.o')
|
|
$stdout.should_receive(:puts).once.with('LD simple')
|
|
setup_testdir(['simple.c']) do
|
|
env = Rscons::Environment.new(echo: :short)
|
|
env.Program('simple', 'simple.c')
|
|
File.exist?('simple.o').should be_true
|
|
`./simple`.should =~ /This is a simple C program/
|
|
end
|
|
end
|
|
|
|
it 'does not rebuild the program if no sources changed' do
|
|
$stdout.should_receive(:puts).once.with('gcc -c -o simple.o simple.c')
|
|
$stdout.should_receive(:puts).once.with('gcc -o simple simple.o')
|
|
setup_testdir(['simple.c']) do
|
|
env = Rscons::Environment.new
|
|
env.Program('simple', 'simple.c')
|
|
env.Program('simple', 'simple.c')
|
|
end
|
|
end
|
|
|
|
it 'rebuilds the application when the source file changes' do
|
|
setup_testdir(['simple.c']) do
|
|
env = Rscons::Environment.new
|
|
env.Program('simple', 'simple.c')
|
|
`./simple`.should =~ /This is a simple C program/
|
|
c = File.read('simple.c')
|
|
File.open('simple.c', 'w') do |fh|
|
|
fh.puts c.sub('simple', 'modified')
|
|
end
|
|
clear_cache
|
|
env.Program('simple', 'simple.c')
|
|
`./simple`.should =~ /This is a modified C program/
|
|
end
|
|
end
|
|
end
|