In Test-MockObject-1.09, I have discovered a bug where the fake_module
method in Test::MockObject incorrectly croaks that a module is already
loaded.
Tested on the following Perl versions / platforms:
v5.12.3 built for x86_64-linux-thread-multi
v5.10.0 built for aix
I have not tried with more recent versions of Test::MockObject, but I
have inspected the code for them and I believe it is still a bug in the
most recent versions.
I have attached sample code that triggers the bug.
To fix the bug, the check_class_loaded method should ignore symbol table
entries when looking through the symbol table. That is, if it is
looking in %Foo:: it should ignore %Foo::Bar:: and only croak if there
are other entries in the symbol table.
It may be desirable to use the "loaded" method in Class::Inspector for
this check, since it already incorporates that logic.
Subject: | bug.pl |
#!/usr/bin/perl
use strict;
use warnings;
use Test::MockObject;
# Create something in Foo::Bar. Test::MockObject will see this symbol table
# entry and croak. This can also be done by a "use Foo::Bar" (assuming that is
# a valid module).
sub Foo::Bar::Test() { 1 }
# Now try to mock Foo. This will croak: "No mocked subs for loaded module
# 'Foo' at bug.pl line 14"
Test::MockObject->fake_module('Foo');