Test a module version

The META6.json file has metadata for a Perl 6 module. But I like to also put things in the module file. I’d rather have some of that stuff with the code in case the metadata file goes missing as it might if you throw a .pm file in a directory rather than installing with zef. That means I forget to update one of them (it’s usually the META6.json).

I created a test file to check that the versions in META6.json. I’d been meaning to do this since I asked about it on Stackoverflow a long time ago:

use v6;

use Test;
use META6;

use File::Find;
constant package-name = 'File::Find';

my $module-version = File::Find.^ver;
ok $module-version.defined, 'Module specifies a version';
diag "Module version is $module-version";

my $meta-file = 'META6.json';
my $meta = META6.new: file => $meta-file;

my $meta-version = $meta.version;
ok $meta-version.defined, 'META6 specifies a version';
diag "META6 version is $meta-version";

is $meta-version, $module-version, 'META6 version matches module version';

done-testing();

The obvious next step is to make a program to update META6.json for me but so far this way is a lot less work. I have no plans to make this a module but someone else can if they like. If you do, gfldex’s You have to take what you can get might be helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *