Implemented SimpleBuilder and updated Environment#add_builder method to support it
This commit is contained in:
1 parent
e279959d79
commit
92d4dd8396
8 files changed
+129
-2
No files matched your search
@@ -249,6 +249,27 @@ describe Rscons do
|
||||
]
|
||||
end
|
||||
|
||||
it 'supports simple builders' do
|
||||
test_dir('json_to_yaml')
|
||||
Rscons::Environment.new do |env|
|
||||
require 'json'
|
||||
require 'yaml'
|
||||
env.add_builder(:JsonToYaml) do |target, sources, cache, env, vars|
|
||||
unless cache.up_to_date?(target, :JsonToYaml, sources, env)
|
||||
cache.mkdir_p(File.dirname(target))
|
||||
File.open(target, 'w') do |f|
|
||||
f.write(YAML.dump(JSON.load(IO.read(sources.first))))
|
||||
end
|
||||
cache.register_build(target, :JsonToYaml, sources, env)
|
||||
end
|
||||
target
|
||||
end
|
||||
env.JsonToYaml('foo.yml','foo.json')
|
||||
end
|
||||
expect(File.exists?('foo.yml')).to be_truthy
|
||||
expect(IO.read('foo.yml')).to eq("---\nkey: value\n")
|
||||
end
|
||||
|
||||
it 'cleans built files' do
|
||||
test_dir('build_dir')
|
||||
Rscons::Environment.new do |env|
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
module Rscons
|
||||
module Builders
|
||||
describe SimpleBuilder do
|
||||
let(:env) {Environment.new}
|
||||
|
||||
it "should create a new builder with the given name (as a symbol) and action" do
|
||||
builder = Rscons::Builders::SimpleBuilder.new(:Foo) { 0x1234 }
|
||||
expect(builder.name).to eq("Foo")
|
||||
expect(builder.run(1,2,3,4,5)).to eq(0x1234)
|
||||
end
|
||||
|
||||
it "should create a new builder with the given name (as a string) and action" do
|
||||
builder = Rscons::Builders::SimpleBuilder.new("Foo") { 0x1234 }
|
||||
expect(builder.name).to eq("Foo")
|
||||
expect(builder.run(1,2,3,4,5)).to eq(0x1234)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -72,6 +72,13 @@ module Rscons
|
||||
env.add_builder(Rscons::Builders::Object.new)
|
||||
expect(env.builders.keys).to eq ["Object"]
|
||||
end
|
||||
|
||||
it "adds a new simple builder to the list of builders" do
|
||||
env = Environment.new(exclude_builders: true)
|
||||
expect(env.builders.keys).to eq []
|
||||
env.add_builder(:Foo) {}
|
||||
expect(env.builders.keys).to eq ["Foo"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#get_build_fname" do
|
||||
|
||||
Reference in new issue
Block a user