Add and improve Ruby test cases in the context of nesting and namespaces

This is done in preparation for adding namespace support to the Ruby
part of SWIG. Some existing test cases were reorganized or duplicated
for flat/nonflat nesting. For some a Ruby test script was added.
Finally the ruby/Makefile.in was improved so that for test cases
without an explicit test script, the generated wrapper library will
be loaded by the Ruby interpreter to ensure loading works fine.
This commit is contained in:
Thomas Reitmayr 2020-12-12 22:09:56 +01:00
commit 7963445048
38 changed files with 1109 additions and 37 deletions

View file

@ -0,0 +1,51 @@
#!/usr/bin/env ruby
#
# This test implementation is directly derived from its Python counterpart.
#
require 'swig_assert'
# helper class for comparing version strings
class Version
attr_reader :array
def initialize(s)
@array = s.split('.').map { |e| e.to_i }
end
def <(rhs)
a = @array.clone
b = rhs.array.clone
a << 0 while a.size < b.size
b << 0 while b.size < a.size
(a <=> b) < 0
end
end
if Object.const_defined?(:Warning) && Warning.respond_to?(:warn)
# suppressing warnings like this only works for Ruby 2.4 and later
module CustomWarningFilter
def warn(*args)
msg = args[0]
if msg =~ /[Aa]lready initialized constant Preproc::A[56]/ ||
msg =~ /invalid name .?__GMP_HAVE_/
# ignore
else
super
end
end
end
Warning.extend CustomWarningFilter
end
require 'preproc'
swig_assert_equal('Preproc::endif', '1', binding)
swig_assert_equal('Preproc::define', '1', binding)
swig_assert_equal('Preproc::ddefined', '1', binding)
swig_assert_equal('2 * Preproc::One', 'Preproc::Two', binding)
swig_assert_equal('Preproc::methodX(99)', '199', binding)
t1 = Preproc::TcxMessageTest
t2 = Preproc::TcxMessageBug