]> granicus.if.org Git - fortune-mod/commitdiff
Convert another test to cmake.
authorShlomi Fish <shlomif@shlomifish.org>
Thu, 8 Dec 2016 14:36:14 +0000 (16:36 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Thu, 8 Dec 2016 14:36:14 +0000 (16:36 +0200)
fortune-mod/CMakeLists.txt
fortune-mod/datfiles/CMakeLists.txt
fortune-mod/run-tests.pl
fortune-mod/tests/scripts/check-fortune-file.sh
fortune-mod/tests/t/check-cookies.t [new file with mode: 0644]

index f1c50d68ad96b87398d8d342ef13b8367c07db39..fe7b4d2e0b758a79cc0d1f80614971660198480c 100644 (file)
@@ -121,9 +121,53 @@ ADD_DEFINITIONS("-DLOCFORTDIR=\"${LOCALDIR}\"")
 ADD_DEFINITIONS("-DOFFDIR=\"${OCOOKIEDIR}\"")
 ADD_DEFINITIONS("-DFORTDIR=\"${COOKIEDIR}\"")
 
+SET (COOKIES
+    art
+    ascii-art
+    computers
+    cookie
+    definitions
+    drugs
+    education
+    ethnic
+    food
+    fortunes
+    goedel
+    humorists
+    kids
+    law
+    linuxcookie
+    literature
+    love
+    magic
+    medicine
+    men-women
+    miscellaneous
+    news
+    people
+    pets
+    platitudes
+    politics
+    riddles
+    science
+    songs-poems
+    sports
+    startrek
+    translate-me
+    wisdom
+    work
+    linux
+    perl
+    knghtbrd
+    paradoxum
+    zippy
+    debian
+)
+
 ADD_SUBDIRECTORY("datfiles")
 
+string (REPLACE ";" " " COOKIES_STR "${COOKIES}")
 ADD_CUSTOM_TARGET(
     "check"
-    "perl" "${CMAKE_SOURCE_DIR}/run-tests.pl" "--src-dir" "${CMAKE_SOURCE_DIR}"
+    "perl" "${CMAKE_SOURCE_DIR}/run-tests.pl" "--src-dir" "${CMAKE_SOURCE_DIR}" "--cookies" "${COOKIES_STR}"
 )
index ef9b65e15409de5fc8de5521f645ac26e636627b..b45da63828479849c731ef519218cd549d73559c 100644 (file)
@@ -1,46 +1,3 @@
-SET (COOKIES
-    art
-    ascii-art
-    computers
-    cookie
-    definitions
-    drugs
-    education
-    ethnic
-    food
-    fortunes
-    goedel
-    humorists
-    kids
-    law
-    linuxcookie
-    literature
-    love
-    magic
-    medicine
-    men-women
-    miscellaneous
-    news
-    people
-    pets
-    platitudes
-    politics
-    riddles
-    science
-    songs-poems
-    sports
-    startrek
-    translate-me
-    wisdom
-    work
-    linux
-    perl
-    knghtbrd
-    paradoxum
-    zippy
-    debian
-)
-
 FOREACH(c ${COOKIES})
     SET(TARGET_NAME "cookie__${c}")
     SET(DEST "${c}.dat")
index 938329c234bdab9574b97ff6ca91d63e65b2f6c6..c589957c440961d13e4d6592248e476df1ab1acf 100644 (file)
@@ -6,7 +6,9 @@ use warnings;
 use Getopt::Long qw/ GetOptions /;
 
 my $src_dir;
+my $cookies_list_str;
 GetOptions(
+    'cookies=s' => \$cookies_list_str,
     'src-dir=s' => \$src_dir,
 ) or die "could not parse options - $!";
 
@@ -16,13 +18,14 @@ if (!defined $src_dir)
 }
 
 local $ENV{SRC_DIR} = $src_dir;
+local $ENV{COOKIES} = $cookies_list_str;
 
 sub do_system
 {
     my ($args) = @_;
 
     my $cmd = $args->{cmd};
-    print "Running [@$cmd]";
+    print "Running [@$cmd]\n";
     if ( system(@$cmd) )
     {
         die "Running [@$cmd] failed!";
index 41b84bdd927e9b530807265c1a5fbdf0b012ef9a..3ea06ff4ac3909001195bbb9df7e17106ef8db86 100644 (file)
@@ -3,7 +3,7 @@
 i="$1"
 shift
 
-echo -n "Testing "$i" ..."
+echo -n "Testing \"$i\" ..."
 if ! tail -n 1 "$i" | grep -q '^%$'  ; then
     echo " failed % check"
     echo "Fortune cookie file does not end in a single %"
diff --git a/fortune-mod/tests/t/check-cookies.t b/fortune-mod/tests/t/check-cookies.t
new file mode 100644 (file)
index 0000000..4ceb4b9
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+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)
+        {
+            fail("$cookie failed.");
+            return;
+        }
+    }
+    pass("All are ok.");
+}
+
+mytest();
+