Skip to content

Instantly share code, notes, and snippets.

@alexm
Created September 30, 2014 18:20
Show Gist options
  • Save alexm/bead30b6f5efed8d75b8 to your computer and use it in GitHub Desktop.
Save alexm/bead30b6f5efed8d75b8 to your computer and use it in GitHub Desktop.
Check Act templates for missing strings
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use Test::More;
die "usage: $0 file1 file2\n" unless @ARGV == 2;
my ($file1, $file2) = @ARGV;
sub parse_file
{
my ( $file, $loc_ref, $tt_ref ) = @_;
open my $fd, '<', $file;
my $content = do { local $/; <$fd> };
close $fd;
$loc_ref->{$1}++ while $content =~ /(\{\{.*?\}\})/mg;
$tt_ref->{$1}++ while $content =~ /(\[%.*?%\])/mg;
}
parse_file( $file1, \my %loc1, \my %tt1 );
parse_file( $file2, \my %loc2, \my %tt2 );
is_deeply( \%loc2, \%loc1, 'loc' );
is_deeply( \%tt2, \%tt1, 'tt' );
done_testing();
@alexm
Copy link
Author

alexm commented Sep 30, 2014

Usage:

$ cd ~/svn/barcelona2104
$ ./check-template ~/git/Act/templates/talk/add actdocs/templates/talk/add
not ok 1 - loc
#   Failed test 'loc'
#   at ./check-template line 28.
#     Structures begin differing at:
#          $got->{{{Duration}}} = '2'
#     $expected->{{{Duration}}} = '1'
not ok 2 - tt
#   Failed test 'tt'
#   at ./check-template line 29.
#     Structures begin differing at:
#          $got->{[% END %]} = '22'
#     $expected->{[% END %]} = '20'
1..2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment