# use "*_t" for basename of this file.
# symlink to *-<perl version string to test>.t.
# e.g.,
#   "20-foo-v5.5.3.t"
#   "20-bar-5.005_003"
#   "20-bar-v5.005003"
# will test varieties of the same perl version string.

use 5.006;
use version;

use Test::More;
use Test::Deep;

use File::Basename  qw( basename    );
use FindBin         qw( $Bin        );

my $madness = 'Module::FromPerlVer';
my $v_dir   = "$Bin/version";

note "Test sandbox: '$v_dir'";

SKIP:
{
    my $base    = basename $0, '.t';

    my ( $perl_v )
    =  do
    {
        my $i   = rindex $base, '-';
        substr $base, ++$i
    }
    or 
    skip "Botched test: no perl version in '$base'.", 1;

    note "Testing perl version: '$perl_v'.";

    version->parse( $perl_v )->numify
    or skip "Botched test: non-parsable '$perl_v' ($base).";

    -d $v_dir
    or skip "Botched test: missing '$v_dir'";

    local $ENV{ PERL_VERSION } = $perl_v;

    use_ok $madness => qw( use_dir 1 )
    or BAIL_OUT "$madness is not usable.";

    for my $prefix ( $madness->source_prefix )
    {
        my $expect  = './t/version';

        is $prefix, $expect, "Source prefix: '$found' ($expect)";
    }

    for my $found ( scalar $madness->source_files )
    {
        @$found
        ? pass 'Found source files in version directory'
        : fail 'Missing source files for cleanup'
        ;

        note "Source files:\n", explain $found;

        ok -e , "Found: '$_'"
        for @$found;
    }

    eval
    {
        $madness->cleanup;

        pass "Survived cleanup.";
    }
    or 
    fail "Failed cleanup: $@";
}

done_testing;
__END__
