diff --git a/Examples/test-suite/ruby/swig_assert.rb b/Examples/test-suite/ruby/swig_assert.rb index a941fc13b..f2bcec766 100755 --- a/Examples/test-suite/ruby/swig_assert.rb +++ b/Examples/test-suite/ruby/swig_assert.rb @@ -8,19 +8,30 @@ # +# +# Exception raised when some swig binding test fails +# class SwigRubyError < RuntimeError 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 ) begin 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 - raise SwigAssertError.new("Wrong assert: #{check} - #{e}") + raise end unless ok @@ -42,19 +53,25 @@ rescue => e 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 if scope.kind_of? Binding - eval(condition.to_s, scope) + eval(expr.to_s, scope) else - eval(condition.to_s) - msg = scope + eval(expr.to_s) + msg = scope if !msg end rescue => e - raise SwigAssertError.new("Wrong assert: #{condition.to_s} - #{e}") + raise SwigRubyError.new("Wrong assert: #{expr.to_s} - #{e}") end if $VERBOSE - $stdout.puts "\tPASSED #{condition} #{msg}" + $stdout.puts "\tPASSED #{expr} #{msg}" end rescue => e trace = e.backtrace[1..-1] @@ -66,6 +83,15 @@ rescue => e 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 ) lines.split("\n").each do |line| next if line.empty? or line =~ /^\s*#.*/ diff --git a/Lib/ruby/ruby.swg b/Lib/ruby/ruby.swg index 2fc372732..d572267fc 100644 --- a/Lib/ruby/ruby.swg +++ b/Lib/ruby/ruby.swg @@ -53,11 +53,6 @@ * ------------------------------------------------------------ */ %include -/* ------------------------------------------------------------ - * The Ruby classes, for C++ - * ------------------------------------------------------------ */ -%include - /* ------------------------------------------------------------ * Warnings for Ruby keywords * ------------------------------------------------------------ */ diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg index d45f662e0..142b407bf 100644 --- a/Lib/ruby/rubyclasses.swg +++ b/Lib/ruby/rubyclasses.swg @@ -41,10 +41,12 @@ namespace swig { VALUE to_s() const; }; + %exception GC_VALUE {}; + %apply VALUE {GC_VALUE}; /* For input */ - %typemap(in,noblock=1) GC_VALUE* (GC_VALUE r), GC_VALUE& (GC_VALUE r) { + %typemap(in,noblock=1) GC_VALUE* (GC_VALUE r), GC_VALUE& (GC_VALUE r) { r = $input; $1 = &r; } diff --git a/Lib/ruby/rubystdcommon.swg b/Lib/ruby/rubystdcommon.swg index 552926029..e7fd461e6 100644 --- a/Lib/ruby/rubystdcommon.swg +++ b/Lib/ruby/rubystdcommon.swg @@ -1,3 +1,9 @@ + +/* ------------------------------------------------------------ + * The Ruby classes, for C++ + * ------------------------------------------------------------ */ +%include + %fragment("StdTraits","header",fragment="StdTraitsCommon") {