Moved the GC_VALUE class over to rubystdcommon

so that it will only get added when STL is used.

Documented swig_assert interface.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9731 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Gonzalo Garramuno 2007-05-01 01:21:26 +00:00
commit 293750eaea
4 changed files with 46 additions and 17 deletions

View file

@ -8,19 +8,30 @@
# #
#
# Exception raised when some swig binding test fails
#
class SwigRubyError < RuntimeError class SwigRubyError < RuntimeError
end end
class SwigAssertError < StandardError
end
#
# Asserts whether a and b are equal.
#
# scope - optional Binding where to run the code
# msg - optional additional message to print
#
def swig_assert_equal( a, b, scope = nil, msg = nil ) def swig_assert_equal( a, b, scope = nil, msg = nil )
begin begin
check = "#{a} == #{b}" check = "#{a} == #{b}"
ok = eval(check, scope) if scope.kind_of? Binding
ok = eval(check.to_s, scope)
else
ok = eval(check.to_s)
msg = scope if !msg
end
rescue => e rescue => e
raise SwigAssertError.new("Wrong assert: #{check} - #{e}") raise
end end
unless ok unless ok
@ -42,19 +53,25 @@ rescue => e
end end
def swig_assert( condition, scope = nil, msg = nil ) #
# Asserts whether an expression runs properly
#
# scope - optional Binding where to run the code
# msg - optional additional message to print
#
def swig_assert( expr, scope = nil, msg = nil )
begin begin
if scope.kind_of? Binding if scope.kind_of? Binding
eval(condition.to_s, scope) eval(expr.to_s, scope)
else else
eval(condition.to_s) eval(expr.to_s)
msg = scope msg = scope if !msg
end end
rescue => e rescue => e
raise SwigAssertError.new("Wrong assert: #{condition.to_s} - #{e}") raise SwigRubyError.new("Wrong assert: #{expr.to_s} - #{e}")
end end
if $VERBOSE if $VERBOSE
$stdout.puts "\tPASSED #{condition} #{msg}" $stdout.puts "\tPASSED #{expr} #{msg}"
end end
rescue => e rescue => e
trace = e.backtrace[1..-1] trace = e.backtrace[1..-1]
@ -66,6 +83,15 @@ rescue => e
end 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.
#
# scope - optional Binding where to run the code
# msg - optional additional message to print
#
def swig_assert_each_line( lines, scope = nil, msg = nil ) def swig_assert_each_line( lines, scope = nil, msg = nil )
lines.split("\n").each do |line| lines.split("\n").each do |line|
next if line.empty? or line =~ /^\s*#.*/ next if line.empty? or line =~ /^\s*#.*/

View file

@ -53,11 +53,6 @@
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
%include <rubyopers.swg> %include <rubyopers.swg>
/* ------------------------------------------------------------
* The Ruby classes, for C++
* ------------------------------------------------------------ */
%include <rubyclasses.swg>
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* Warnings for Ruby keywords * Warnings for Ruby keywords
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */

View file

@ -41,6 +41,8 @@ namespace swig {
VALUE to_s() const; VALUE to_s() const;
}; };
%exception GC_VALUE {};
%apply VALUE {GC_VALUE}; %apply VALUE {GC_VALUE};
/* For input */ /* For input */

View file

@ -1,3 +1,9 @@
/* ------------------------------------------------------------
* The Ruby classes, for C++
* ------------------------------------------------------------ */
%include <rubyclasses.swg>
%fragment("StdTraits","header",fragment="StdTraitsCommon") %fragment("StdTraits","header",fragment="StdTraitsCommon")
{ {