Add specs for tasks
This commit is contained in:
parent
c3121f17cf
commit
d11981d4b2
20
build_tests/tasks/tasks.rb
Normal file
20
build_tests/tasks/tasks.rb
Normal file
@ -0,0 +1,20 @@
|
||||
task "one" do
|
||||
puts "one"
|
||||
end
|
||||
|
||||
task "two", deps: ["one", "three"] do
|
||||
puts "two"
|
||||
end
|
||||
|
||||
task "three", desc: "Task three" do
|
||||
puts "three"
|
||||
end
|
||||
|
||||
task "four", desc: "Task four", params: [
|
||||
param("myparam", "defaultvalue", true, "My special parameter"),
|
||||
param("myp2", nil, false, "My parameter 2"),
|
||||
] do |task, params|
|
||||
puts "four"
|
||||
puts "myparam:" + params["myparam"].inspect
|
||||
puts "myp2:" + params["myp2"].inspect
|
||||
end
|
@ -31,7 +31,7 @@ module Rscons
|
||||
while argv.size > 0
|
||||
if argv[0].start_with?("-")
|
||||
valid_arg = false
|
||||
if argv[0] =~ /^--(\S+?)(?:=(.*))$/
|
||||
if argv[0] =~ /^--(\S+?)(?:=(.*))?$/
|
||||
param_name, value = $1, $2
|
||||
if param = Task[task].params[param_name]
|
||||
param.value = value || argv[0]
|
||||
|
@ -339,8 +339,11 @@ module Rscons
|
||||
# Perform configure action.
|
||||
def configure(configure_op)
|
||||
cdsl = ConfigureDsl.new(self, configure_op)
|
||||
Task["configure"].actions.each do |action|
|
||||
cdsl.instance_eval(&action)
|
||||
configure_task = Task["configure"]
|
||||
configure_task.actions.each do |action|
|
||||
cdsl.instance_eval do
|
||||
action[configure_task, configure_task.param_values]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -146,7 +146,7 @@ module Rscons
|
||||
Rscons.application.configure
|
||||
else
|
||||
@actions.each do |action|
|
||||
action[]
|
||||
action[self, param_values]
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -200,6 +200,18 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
# Get parameter values as a Hash.
|
||||
#
|
||||
# @return [Hash]
|
||||
# Parameter values.
|
||||
def param_values
|
||||
param_values = {}
|
||||
@params.each do |name, param|
|
||||
param_values[name] = param.value
|
||||
end
|
||||
param_values
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -2841,4 +2841,64 @@ EOF
|
||||
end
|
||||
end
|
||||
|
||||
it "executes the requested tasks in the requested order" do
|
||||
test_dir "tasks"
|
||||
result = run_rscons(args: %w[-f tasks.rb configure])
|
||||
result = run_rscons(args: %w[-f tasks.rb one three])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to eq "one\nthree\n"
|
||||
result = run_rscons(args: %w[-f tasks.rb three one])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to eq "three\none\n"
|
||||
end
|
||||
|
||||
it "executes the task's dependencies before the requested task" do
|
||||
test_dir "tasks"
|
||||
result = run_rscons(args: %w[-f tasks.rb configure])
|
||||
result = run_rscons(args: %w[-f tasks.rb two])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to eq "one\nthree\ntwo\n"
|
||||
end
|
||||
|
||||
it "does not execute a task more than once" do
|
||||
test_dir "tasks"
|
||||
result = run_rscons(args: %w[-f tasks.rb configure])
|
||||
result = run_rscons(args: %w[-f tasks.rb one two three])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to eq "one\nthree\ntwo\n"
|
||||
end
|
||||
|
||||
it "passes task arguments" do
|
||||
test_dir "tasks"
|
||||
result = run_rscons(args: %w[-f tasks.rb configure])
|
||||
result = run_rscons(args: %w[-f tasks.rb four])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to eq %[four\nmyparam:"defaultvalue"\nmyp2:nil\n]
|
||||
result = run_rscons(args: %w[-f tasks.rb four --myparam=cli-value --myp2 one])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to eq %[four\nmyparam:"cli-value"\nmyp2:"--myp2"\none\n]
|
||||
end
|
||||
|
||||
it "displays tasks and their arguments in the help info" do
|
||||
test_dir "tasks"
|
||||
result = run_rscons(args: %w[-f tasks.rb -h])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
verify_lines(lines(result.stdout), [
|
||||
"Tasks:",
|
||||
/\bthree\b\s+Task three/,
|
||||
/\bfour\b\s+Task four/,
|
||||
/--myparam=MYPARAM\s+My special parameter/,
|
||||
/--myp2\s+My parameter 2/,
|
||||
])
|
||||
expect(result.stdout).to_not match /^\s*one\b/
|
||||
expect(result.stdout).to_not match /^\s*two\b/
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user