From 51fd99e8f234889327521692c0a65fed7b52bb9c Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 8 Dec 2016 16:56:15 +0200 Subject: [PATCH] Convert from shell to perl. --- fortune-mod/tests/t/check-cookies.t | 32 +++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/fortune-mod/tests/t/check-cookies.t b/fortune-mod/tests/t/check-cookies.t index 4ceb4b9..601b558 100644 --- a/fortune-mod/tests/t/check-cookies.t +++ b/fortune-mod/tests/t/check-cookies.t @@ -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; } } -- 2.40.0