
require 'tutil'

file "test_touch" do |t|
    sys.touch t.name
end

task :clean do
    sys.rm "test_touch"
end

task :create_target do
    sys.touch "target"
end

task :create_dep do
    sys.touch "dep"
end

file "target" => "dep" do |t|
    sys.touch t.name
end

file "t2" => ["dep1", "dep2"] do |t|
    sys.touch t.name
end

file "dep1" do |t|
    sys.touch t.name
end

file "dep2" do |t|
    sys.touch t.name
end

file "duplicate" do |t|
    sys.touch t.name
    sys.touch t.name + "1"
end

file "duplicate" do |t|
    sys.touch t.name
    sys.touch t.name + "2"
end

file "fallback" do
    # doesn't create our target...
    # so the next task with the same
    # name should be run
    sys.touch "fallback_"
end

file "fallback" do |t|
    sys.touch t.name
end

gen Directory, "dir/subdir"
task :path => "dir/subdir"

gen Directory, "dir/sub2" do |t|
    # This block should be called after the creation of the directory
    # `sub2' in `dir'.
    t.name == "dir/sub2" or t.fail
    sys.touch "#{t.name}/postprocess"
end

gen Directory, "dir/sub3" => "dep1" do |t|
    sys.touch "#{t.name}/postprocess"
end

file "tbe" => :dep1 do |t|
    sys.touch t.name
    timeout
end

enhance :tbe => "dep2" do |t|
    sys.touch "tbe2"
    timeout
end

# should generate warning because there is no existing task called
# "nothing" and create the task "nothing"
enhance :nothing

task :order do |t|
    sys.touch t.name + "1"
    timeout
end

task :order do |t|
    sys.touch t.name + "2"
    timeout
end

file "incdep" do |t|
    sys.touch t.name
end

file "inc" => "incdep" do |t|
    sys.touch t.name
end

gen Task, :task_one do |t|
    t.needed do
	!test ?f, "one_target"
    end
    t.act do
	sys.touch "one_target"
    end
end

gen Task, :task_two => :task_one do |t|
    t.act { print t.name }
end

task :force_clean do
    sys.rm_f %w(
	test_touch target dep dep1 dep2 t2
	duplicate duplicate1 duplicate2
	fallback fallback_ order1 order2
	tbe tbe2 inc incdep lt_target one_target
	).find_all { |e| test(?e, e) }
    sys.rm_rf %w(dir)
end

# vim:ft=ruby
