test/test_graph.rb in build-graph-0.0.1 vs test/test_graph.rb in build-graph-0.1.0
- old
+ new
@@ -20,12 +20,14 @@
require 'test/unit'
require 'build/graph'
require 'build/files'
-require 'build/system/pool'
+require 'process/group'
+require 'fileutils'
+
class TestGraph < Test::Unit::TestCase
# The graph node is created once, so a graph has a fixed number of nodes, which store per-vertex state and connectivity.
class Node < Build::Node
def initialize(graph, inputs, outputs, &update)
@update = update
@@ -47,18 +49,18 @@
end
end
# The task is the context in which a vertex is updated. Because nodes may initially create other nodes, it is also responsible for looking up and creating new nodes.
class Task < Build::Task
- def initialize(graph, walker, node, pool = nil)
+ def initialize(graph, walker, node, group = nil)
super(graph, walker, node)
- @pool = pool
+ @group = group
end
def wet?
- @pool# and @node.dirty?
+ @group# and @node.dirty?
end
def process(inputs, outputs, &block)
child_node = @graph.nodes.fetch([inputs, outputs]) do |key|
@graph.nodes[key] = Node.new(@graph, inputs, outputs, &block)
@@ -70,14 +72,14 @@
child_node.update!(@walker)
end
def run(*arguments)
if wet?
- status = @pool.run(*arguments)
+ status = @group.spawn(*arguments)
if status != 0
- raise CommandFailure.new(arguments, status)
+ raise RuntimeError.new(status)
end
end
end
def visit
@@ -86,12 +88,12 @@
end
end
end
class Graph < Build::Graph
- def initialize
- yield self
+ def initialize(&block)
+ @top = Node.new(self, Build::Files::NONE, Build::Files::NONE, &block)
super()
end
attr_accessor :top
@@ -99,41 +101,35 @@
def traverse!(walker)
@top.update!(walker)
end
def build_graph!
- puts "Building graph..."
-
super do |walker, node|
Task.new(self, walker, node)
end
end
def update!
- puts "Updating graph..."
+ group = Process::Group.new
- pool = Build::System::Pool.new
-
super do |walker, node|
- Task.new(self, walker, node, pool)
+ Task.new(self, walker, node, group)
end
- pool.wait
+ group.wait
end
end
def test_minimal_graph
test_glob = Build::Files::Glob.new(__dir__, "*.rb")
output_paths = Build::Files::Paths.new(__dir__, ["listing.txt"])
FileUtils.rm_f output_paths.to_a
- graph = Graph.new do |graph|
- graph.top = Node.new(graph, Build::Files::NONE, Build::Files::NONE) do
- process test_glob, output_paths do
- run("ls", "-la", *test_glob, :out => output_paths.first)
- end
+ graph = Graph.new do
+ process test_glob, output_paths do
+ run("ls", "-la", *test_glob, :out => output_paths.first)
end
end
graph.update!
@@ -142,7 +138,11 @@
graph.update!
assert_equal mtime, File.mtime(output_paths.first)
FileUtils.rm_f output_paths.to_a
+
+ #graph.nodes.each do |key, node|
+ # puts "#{node.status} #{node.inspect}"
+ #end
end
end