+ # Need to default. This behaviour is consistent with previous behaviour,
+ # as the equivalent of this code used to be run at the top level, hence
+ # would happen (unconditionally) before import() was called.
+ unless ($setopt) {
+ if (-f 't/TEST' && -f 'MANIFEST' && -d 'lib' && -d 'ext') {
+ # We're being run from the top level. Try to change directory, and
+ # set things up correctly. This is a 90% solution, but for
+ # hand-running tests, that's good enough
+ if ($0 =~ s!^((?:ext|dist|cpan)[\\/][^\\/]+)[\\/](.*\.t)$!$2!) {
+ # Looks like a test in ext.
+ $chdir = $1;
+ @INC = @up_2_t;
+ $setopt = 1;
+ $^X =~ s!^\.([\\/])!..$1..$1!;
+ } else {
+ $chdir = 't';
+ @INC = '../lib';
+ $setopt = $0 =~ m!^lib/!;
+ }
+ } else {
+ # (likely) we're being run by t/TEST or t/harness, and we're a test
+ # in t/
+ if (defined &DynaLoader::boot_DynaLoader) {
+ @INC = '../lib';
+ }
+ else {
+ # miniperl/minitest
+ # t/TEST does not supply -I../lib, so buildcustomize.pl is
+ # not automatically included.
+ unshift @INC, '../lib';
+ do "../lib/buildcustomize.pl";
+ }