From bf116e22e11b9cf38dc9e3c1ed2f64d21020d77f Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 8 Dec 2016 16:36:14 +0200 Subject: [PATCH] Convert another test to cmake. --- fortune-mod/CMakeLists.txt | 46 ++++++++++++++++++- fortune-mod/datfiles/CMakeLists.txt | 43 ----------------- fortune-mod/run-tests.pl | 5 +- .../tests/scripts/check-fortune-file.sh | 2 +- fortune-mod/tests/t/check-cookies.t | 22 +++++++++ 5 files changed, 72 insertions(+), 46 deletions(-) create mode 100644 fortune-mod/tests/t/check-cookies.t diff --git a/fortune-mod/CMakeLists.txt b/fortune-mod/CMakeLists.txt index f1c50d6..fe7b4d2 100644 --- a/fortune-mod/CMakeLists.txt +++ b/fortune-mod/CMakeLists.txt @@ -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}" ) diff --git a/fortune-mod/datfiles/CMakeLists.txt b/fortune-mod/datfiles/CMakeLists.txt index ef9b65e..b45da63 100644 --- a/fortune-mod/datfiles/CMakeLists.txt +++ b/fortune-mod/datfiles/CMakeLists.txt @@ -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") diff --git a/fortune-mod/run-tests.pl b/fortune-mod/run-tests.pl index 938329c..c589957 100644 --- a/fortune-mod/run-tests.pl +++ b/fortune-mod/run-tests.pl @@ -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!"; diff --git a/fortune-mod/tests/scripts/check-fortune-file.sh b/fortune-mod/tests/scripts/check-fortune-file.sh index 41b84bd..3ea06ff 100644 --- a/fortune-mod/tests/scripts/check-fortune-file.sh +++ b/fortune-mod/tests/scripts/check-fortune-file.sh @@ -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 index 0000000..4ceb4b9 --- /dev/null +++ b/fortune-mod/tests/t/check-cookies.t @@ -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(); + -- 2.50.1