fix the version update test and update some versions
[imager-graph.git] / t / x90cmp_version.t
CommitLineData
e26d9fde
TC
1#!perl
2# inspired by perl's cmpVERSION
3use strict;
4use warnings;
5use Test::More;
6use ExtUtils::MakeMaker;
7use File::Spec::Functions 'devnull';
8
9-d ".git"
10 or plan skip_all => "Not a git tree";
11
12chomp(my $base_tag = `git describe --abbrev=0`);
13
14my @changed = grep /\.pm$/ && m(/),
15 `git diff --name-only $base_tag --diff-filter=ACMRTUXB`;
16
17chomp @changed;
18
172d0769 19plan tests => scalar @changed;
e26d9fde
TC
20
21my @need_update;
22for my $file (@changed) {
23 my $orig_content = get_file_from_git($file, $base_tag);
24 my $orig_version = eval { MM->parse_version(\$orig_content) };
25 my $curr_version = eval { MM->parse_version($file) };
26
27 if ($curr_version ne "undef" && $orig_version ne "undef") {
172d0769 28 cmp_ok($curr_version, '>', $orig_version, "$file - out of date");
e26d9fde
TC
29 }
30 elsif ($orig_version ne "undef") {
172d0769 31 fail("$file - version was removed");
e26d9fde
TC
32 }
33 elsif ($curr_version eq "undef") {
172d0769
TC
34 fail("$file - has no version");
35 }
36 else {
37 pass($file);
e26d9fde
TC
38 }
39}
40
e26d9fde
TC
41sub get_file_from_git {
42 my ($file, $tag) = @_;
43 local $/;
44 my $null = devnull();
45 return scalar `git --no-pager show $tag:$file 2>$null`;
46}