diff options
Diffstat (limited to 'tdeabc/vcardparser/checkvcard.pl')
-rwxr-xr-x | tdeabc/vcardparser/checkvcard.pl | 73 |
1 files changed, 31 insertions, 42 deletions
diff --git a/tdeabc/vcardparser/checkvcard.pl b/tdeabc/vcardparser/checkvcard.pl index 67160ea4a..1360972e6 100755 --- a/tdeabc/vcardparser/checkvcard.pl +++ b/tdeabc/vcardparser/checkvcard.pl @@ -1,69 +1,58 @@ #!/usr/bin/perl +use utf8; +use strict; +use warnings; + if ( @ARGV != 1 ) { print STDERR "Missing arg: filename\n"; exit 1; } -$file = $ARGV[0]; +my $file = $ARGV[0]; +my $ref = "$file.ref"; -if ( !open( IN, "$file" ) ) { - print STDERR "Unable to open '$file'\n"; - exit 1; -} +my $options=""; +my $error=0; +my @prscont; +my @refcont; +open( IN, "<", $file ) || die ("Unable to open $file"); while( <IN> ) { - if (/^VERSION:(.*)$/ ) { - $version = $1; - if ( $version eq "2.1" ) { $options = "--vcard21"; } - } + if (/^VERSION:(.*)$/ ) { my $v = $1; $options = "--vcard21" if $v eq "2.1"; } } - close IN; -$ref = "$file.ref"; - -if ( !open( REF, "$ref" ) ) { - print STDERR "Unable to open $ref\n"; - exit 1; -} - +open( REF, "$ref" ) || die ("Unable to open $ref"); while( <REF> ) { - push @ref, $_; + next if $_ =~ /^UID/; + push @refcont , $_ ; } - close REF; -if ( !open( READ, "./testread $file $options 2> /dev/null |" ) ) { - print STDERR "Unable to open testread\n"; - exit 1; -} - -print "Checking '$file':\n"; - -$gotsomething = 0; -$error = 0; -$i = 0; +open( READ, "./testread $file $options 2> /dev/null |" ) || die ("Unable to open testread"); +print "Checking: $file "; while( <READ> ) { - $gotsomething = 1; - $out = $_; - $ref = @ref[$i++]; - - if ( $out ne $ref ) { - if ( $ref =~ /^UID/ && $out =~ /^UID/ ) { next; } - $error++; - print " Expected : $ref"; - print " Parser output : $out"; - } + next if $_ =~ /^UID/; + push @prscont , $_; } - close READ; -if ( $gotsomething == 0 ) { - print "\n FAILED: testread didn't output anything\n"; + +if ( $#refcont != $#prscont ) { + print "\n FAILED: ref size and parsed size mismatch.\n"; system "touch FAILED"; exit 1; } + +for (my $i=0; $i<=$#refcont; $i++) { + if ( $refcont[$i] ne $prscont[$i] ) { + $error++; + print "\n Expected : $refcont[$i]"; + print " Parser output : $prscont[$i]"; + } +} + if ( $error > 0 ) { print "\n FAILED: $error errors found.\n"; system "touch FAILED"; |