Created
September 7, 2020 16:18
-
-
Save LadyAleena/47b8a71884c2cdf0f4a38f33caded508 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use feature qw(say); | |
use File::Find; | |
use Path::Tiny qw(path); | |
my $dir = shift; | |
my @modules; | |
sub wanted { | |
my $file = $_ =~/\.pm$/ ? $File::Find::name : undef; | |
push @modules, $file if $file; | |
} | |
find(\&wanted, $dir); | |
for my $file (sort @modules) { | |
my $bare_file = $file; | |
$bare_file =~ s/^mods\/lib\/(.+)\.pm$/$1/; | |
my $module = $bare_file; | |
$module =~ s/\//::/g; | |
my $out_file = $bare_file; | |
$out_file =~ s/\//-/g; | |
$out_file =~ s/^(.+)$/mods\/t\/00-$1\.t/; | |
my $version; | |
my $fh; | |
open($fh, '<', $file) || die $!; | |
while (my $line = <$fh>) { | |
chomp($line); | |
if ($line =~ /^use v(.+)$/) { | |
$version = $line; | |
last | |
} | |
} | |
close($fh); | |
say "$bare_file"; | |
my $lines = write_test($module, $version); | |
open($fh, ">:encoding(UTF-8)", $out_file) || die $!; | |
print $fh, $lines; | |
} | |
sub write_test { | |
my ($module, $version) = @_; | |
my $test = qq(#!perl | |
use strict; | |
use warnings; | |
$version | |
use Test::More; | |
BEGIN { | |
use_ok( \'$module\' ) | |
or die "$module is not available\\n"; | |
} | |
diag( "Testing $module \$${module}::VERSION, Perl \$], \$^X" ); | |
done_testing(); | |
); | |
return $test; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment