|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use lib 'lib'; |
| 4 | +use feature qw(say); |
| 5 | +use Data::Dumper; |
| 6 | +$Data::Dumper::Sortkeys = 1; |
| 7 | +use File::Basename; |
| 8 | +use File::Find::Rule; |
| 9 | +use File::Slurper 'read_text'; |
| 10 | +use File::Spec; |
| 11 | +use Getopt::Long; |
| 12 | +use Test::Exception; |
| 13 | +use Test::More; |
| 14 | +use YAML::XS qw(LoadFile); |
| 15 | +use utf8; |
| 16 | +use feature "unicode_strings"; |
| 17 | + |
| 18 | +# nicer output for diag and failures, see |
| 19 | +# http://perldoc.perl.org/Test/More.html#CAVEATS-and-NOTES |
| 20 | +my $builder = Test::More->builder; |
| 21 | +binmode $builder->output, ":encoding(UTF-8)"; |
| 22 | +binmode $builder->failure_output, ":encoding(UTF-8)"; |
| 23 | +binmode $builder->todo_output, ":encoding(UTF-8)"; |
| 24 | + |
| 25 | +my $af_path = dirname(__FILE__) . '/../../address-formatting'; |
| 26 | + |
| 27 | +my $compfile = $af_path . '/conf/components.yaml'; |
| 28 | +my $verbose = 0; |
| 29 | + |
| 30 | +GetOptions( |
| 31 | + 'verbose' => \$verbose, |
| 32 | +); |
| 33 | + |
| 34 | +ok(1); |
| 35 | + |
| 36 | +if (-e $compfile) { |
| 37 | + |
| 38 | + note("found components: $compfile"); |
| 39 | + ok(1, 'found components yaml file'); |
| 40 | + #my $text = read_text($compfile); |
| 41 | + #say STDERR $text; |
| 42 | + |
| 43 | + # go through the components file |
| 44 | + # make a list of all components and aliases |
| 45 | + my %found_components; |
| 46 | + |
| 47 | + my @comps = LoadFile($compfile); |
| 48 | + foreach my $rh_comp (@comps){ |
| 49 | + foreach my $k (keys %$rh_comp){ |
| 50 | + if ($k eq 'name'){ |
| 51 | + $found_components{$rh_comp->{name}}++; |
| 52 | + } |
| 53 | + elsif ($k eq 'aliases'){ |
| 54 | + my $ra_aliases = $rh_comp->{aliases}; |
| 55 | + foreach my $alias (@$ra_aliases){ |
| 56 | + $found_components{$alias}++; |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + # did we have any more than once? |
| 63 | + foreach my $c (keys %found_components){ |
| 64 | + ok($found_components{$c} == 1, "only found $c once"); |
| 65 | + } |
| 66 | + #say STDERR Dumper \@comps; |
| 67 | +} |
| 68 | + |
| 69 | +done_testing(); |
| 70 | + |
| 71 | +1; |
0 commit comments