]> granicus.if.org Git - fortune-mod/commitdiff
Convert from shell to perl.
authorShlomi Fish <shlomif@shlomifish.org>
Thu, 8 Dec 2016 14:56:15 +0000 (16:56 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Thu, 8 Dec 2016 14:56:15 +0000 (16:56 +0200)
fortune-mod/tests/t/check-cookies.t

index 4ceb4b94b53eb8ca74c81b7533657a753329cd07..601b5580be01782e0f4495b150817ab19754080d 100644 (file)
@@ -3,15 +3,43 @@
 use strict;
 use warnings;
 
+use IO::All qw/ io /;
+use List::MoreUtils qw/ any /;
+
 use Test::More tests => 1;
 
+sub check_file
+{
+    my ($fn) = @_;
+    my @l = io->file($fn)->utf8->chomp->getlines;
+
+    if ($l[-1] ne '%')
+    {
+        return  "Fortune cookie file does not end in a single %";
+    }
+    if (any { length($_) > 80 } @l)
+    {
+        return "Fortune cookie file contains a line longer than 78 characters";
+    }
+    if (any { /\r/ } @l)
+    {
+        return "Fortune cookie file contains a CR"
+    }
+    if (any { /[ \t]\z/ } @l)
+    {
+        return "Fortune cookie file contains trailing whitespace";
+    }
+    return "";
+}
+
 sub mytest
 {
     foreach my $cookie (split/ /, $ENV{COOKIES})
     {
-        if (system("sh", "$ENV{SRC_DIR}/tests/scripts/check-fortune-file.sh", "$ENV{SRC_DIR}/datfiles/$cookie") != 0)
+        my $err = check_file( "$ENV{SRC_DIR}/datfiles/$cookie");
+        if ($err ne '')
         {
-            fail("$cookie failed.");
+            fail("$cookie failed - $err.");
             return;
         }
     }