Yet even better swig assert.
Added more tests to std::vector for map. Added dup() function to containers. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9732 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
293750eaea
commit
aa3c28e230
4 changed files with 68 additions and 16 deletions
|
|
@ -28,18 +28,23 @@ def swig_assert_equal( a, b, scope = nil, msg = nil )
|
|||
ok = eval(check.to_s, scope)
|
||||
else
|
||||
ok = eval(check.to_s)
|
||||
msg = scope if !msg
|
||||
if !msg
|
||||
msg = scope
|
||||
scope = nil
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
raise
|
||||
end
|
||||
|
||||
unless ok
|
||||
raise SwigRubyError.new("FAILED CHECK: #{check} was #{eval(a)} #{msg}")
|
||||
valA = eval(a, scope)
|
||||
valB = eval(b, scope)
|
||||
raise SwigRubyError.new("FAILED EQUALITY: #{check} was #{valA} not #{valB}")
|
||||
end
|
||||
|
||||
if $VERBOSE
|
||||
$stdout.puts "\tPASSED #{check} #{msg}"
|
||||
$stdout.puts "\tPASSED EQUALITY #{check} #{msg}"
|
||||
end
|
||||
|
||||
return ok
|
||||
|
|
@ -54,12 +59,44 @@ end
|
|||
|
||||
|
||||
#
|
||||
# Asserts whether an expression runs properly
|
||||
# Asserts whether an expression runs properly and is true
|
||||
#
|
||||
# scope - optional Binding where to run the code
|
||||
# msg - optional additional message to print
|
||||
#
|
||||
def swig_assert( expr, scope = nil, msg = nil )
|
||||
begin
|
||||
if scope.kind_of? Binding
|
||||
ok = eval(expr.to_s, scope)
|
||||
else
|
||||
ok = eval(expr.to_s)
|
||||
msg = scope if !msg
|
||||
end
|
||||
rescue
|
||||
raise
|
||||
end
|
||||
|
||||
raise SwigRubyError.new("FAILED: #{expr.to_s} - #{e}") unless ok
|
||||
|
||||
if $VERBOSE
|
||||
$stdout.puts "\tPASSED #{expr} #{msg}"
|
||||
end
|
||||
rescue => e
|
||||
trace = e.backtrace[1..-1]
|
||||
$stderr.puts "#{trace[0,1]}: #{e}"
|
||||
if trace.size > 1
|
||||
$stderr.puts "\tfrom #{trace[1..-1].join("\n\t ")}"
|
||||
end
|
||||
exit(1)
|
||||
end
|
||||
|
||||
#
|
||||
# Asserts whether an expression runs properly
|
||||
#
|
||||
# scope - optional Binding where to run the code
|
||||
# msg - optional additional message to print
|
||||
#
|
||||
def swig_eval( expr, scope = nil, msg = nil )
|
||||
begin
|
||||
if scope.kind_of? Binding
|
||||
eval(expr.to_s, scope)
|
||||
|
|
@ -87,7 +124,7 @@ end
|
|||
# Given a set of lines as text, runs each of them, asserting them.
|
||||
# Lines that are of the form:
|
||||
# a == b are run with swig_assert_equal
|
||||
# others are run with swig_assert.
|
||||
# others are run with swig_eval.
|
||||
#
|
||||
# scope - optional Binding where to run the code
|
||||
# msg - optional additional message to print
|
||||
|
|
@ -95,10 +132,10 @@ end
|
|||
def swig_assert_each_line( lines, scope = nil, msg = nil )
|
||||
lines.split("\n").each do |line|
|
||||
next if line.empty? or line =~ /^\s*#.*/
|
||||
if line =~ /(.*)\s*==\s*(.*)/
|
||||
if line =~ /^\s*([^\s]*)\s*==\s*(.*)\s*$/
|
||||
swig_assert_equal($1, $2, scope, msg)
|
||||
else
|
||||
swig_assert(line, scope, msg)
|
||||
swig_eval(line, scope, msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue