Skip to content

Commit

Permalink
add NoFunctionError
Browse files Browse the repository at this point in the history
  • Loading branch information
quix committed Sep 7, 2008
1 parent 93d2c23 commit 4ad9cf5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
2 changes: 1 addition & 1 deletion install.rb
@@ -1,3 +1,3 @@
$LOAD_PATH.unshift "./contrib/quix/lib"
require 'quix/simpleinstaller'
require 'quix/simple_installer'
Quix::SimpleInstaller.new.run
16 changes: 10 additions & 6 deletions lib/comp_tree/driver.rb
Expand Up @@ -214,15 +214,19 @@ def check_circular(name)
# <tt>:fork</tt> -- (boolean) Whether to fork each computation
# node into its own process.
#
# <tt>:wait_interval</tt> -- (seconds) (Obscure) How long to
# wait after an IPC failure.
#
# <tt>:timeout</tt> -- (seconds) (Obscure) Give up after this
# period of persistent IPC failures.
#
# Defaults options are taken from Driver::DEFAULTS.
#
def compute(name, opts = nil)
#
# Undocumented options:
#
# <tt>:wait_interval</tt> -- (seconds) (Obscure) How long to
# wait after an IPC failure.
#
# <tt>:timeout</tt> -- (seconds) (Obscure) Give up after this
# period of persistent IPC failures.
#

abort_on_exception {
compute_private(name, opts || Hash.new)
}
Expand Down
3 changes: 3 additions & 0 deletions lib/comp_tree/error.rb
Expand Up @@ -20,5 +20,8 @@ class RedefinitionError < Base ; end

# A Cyclic graph was detected.
class CircularError < Base ; end

# No function was defined for this node.
class NoFunctionError < Base ; end
end
end
4 changes: 4 additions & 0 deletions lib/comp_tree/node.rb
Expand Up @@ -113,6 +113,10 @@ def trace_compute #:nodoc:
# already acquired.
#
def compute #:nodoc:
unless defined?(@function) and @function
raise Error::NoFunctionError,
"No function was defined for node '#{@name.inspect}'"
end
@function.call(*@children_results)
end

Expand Down
45 changes: 35 additions & 10 deletions test/test_exception.rb
Expand Up @@ -7,6 +7,11 @@
require 'quix/config'
require 'test/unit'

#
# Mean workaround using separate processes due to assert_raise causing
# problems with threads.
#

module CompTree
class TestRaises < Test::Unit::TestCase
HERE = File.dirname(__FILE__)
Expand All @@ -25,15 +30,29 @@ def test_1
puts "skipping #{File.basename(__FILE__)}."
else
[true, false].each { |use_fork|
assert(!system(::Quix::Config.ruby_executable, "-e", code(use_fork)))
assert_match(%r!CompTreeTestError!, File.read(OUTPUT_FILE))
File.unlink(OUTPUT_FILE) # leave when exception raised above
[true, false].each { |define_all|
assert(
!system(
::Quix::Config.ruby_executable,
"-e",
code(use_fork, define_all)))

output = File.read(OUTPUT_FILE)

if define_all
assert_match(%r!CompTreeTestError!, output)
else
assert_match(%r!NoFunctionError!, output)
end

File.unlink(OUTPUT_FILE) # leave when exception raised above
}
}
end
end

def code(use_fork)
%Q{
def code(use_fork, define_all)
%Q(
$LOAD_PATH.unshift '#{LIB_DIR}'
require 'comp_tree'
require 'open3'
Expand All @@ -45,19 +64,25 @@ class CompTreeTestError < Exception ; end
|width, height, offset|
width*height - offset
}
driver.define(:width, :border) { |border|
2 + border
}
driver.define(:height, :border) { |border|
3 + border
}
) +
if define_all
%Q(
driver.define(:border) {
raise CompTreeTestError
}
)
else
""
end +
%Q(
driver.define(:offset) {
7
}
Expand All @@ -68,7 +93,7 @@ class CompTreeTestError < Exception ; end
:area, :threads => 99, :fork => #{use_fork.inspect})
}
}
}
)
end
end
end

0 comments on commit 4ad9cf5

Please sign in to comment.