mruby-mtest icon indicating copy to clipboard operation
mruby-mtest copied to clipboard

How to include RegExp?

Open hlogmans opened this issue 9 years ago • 4 comments

In mrbtest I get the Skip exception about Regexp not being included:

mtest_unit.rb:183: assert_match is not defined, because Regexp is not impl. (MTest::Skip)

In the gem I'm creating I have the line spec.add_dependency('mruby-pcre-regexp', :mgem => 'mruby-pcre-regexp')

And in the build spec for test I have this gem included, too.

In the pcre-regexp gem this line is included: Regexp = PcreRegexp unless Object.const_defined?(:Regexp)

What needs to be done more to have Regexp available in mruby-mtest?

hlogmans avatar Feb 11 '16 13:02 hlogmans

Maybe you need to add_dependency before add_dependency-ing mruby-mtest mrbgem since mruby-mtest needs to be loaded after mruby-pcre-regexp mrbgem.

take-cheeze avatar Feb 18 '16 14:02 take-cheeze

The pcre-regexp gem seems to register RegExp instead of Regexp. But others do register the correct one, but I am still unable to fix the warning. And thus probably not able to use regexp. Maybe the author did use something specific?

hlogmans avatar Mar 11 '16 12:03 hlogmans

Then you should redefine the constant to RegExp, like Regexp = RegExp, in the gem.

Perhaps the maintainer would accept this patch, but it's not anything we can fix in mruby-mtest.

zzak avatar Jun 09 '16 05:06 zzak

The problem comes from mruby-test, nothing can be done about it in mruby-mtest.

mruby-test runs each gem's tests in a separate mruby VM. The gem's tests are only initialized with declared dependencies and mruby-mtest doesn't have a dependency on any regular expression gem. When the tests are bundled together in your other application mruby-mtest still won't have access to any regular expression libraries. You will always see skips.

Since there are multiple regular expression libraries available (PCRE and Onigmo) mruby-mtest shouldn't be forced to choose one.

I think this issue should be closed.

drbrain avatar Dec 14 '16 21:12 drbrain