]> granicus.if.org Git - fortune-mod/commitdiff
Extract an sh script to check a fortune file.
authorShlomi Fish <shlomif@shlomifish.org>
Mon, 4 Apr 2016 12:35:38 +0000 (15:35 +0300)
committerShlomi Fish <shlomif@shlomifish.org>
Mon, 4 Apr 2016 12:35:38 +0000 (15:35 +0300)
From the makefile and check it for errors.

fortune-mod/datfiles/Makefile
fortune-mod/tests/scripts/check-fortune-file.sh [new file with mode: 0644]

index 05413f0ab8175edd0743728f1e9fe95246e4f516..9011410e69cd2a3dafdee8ca7b0c7ba186bfd13a 100644 (file)
@@ -1,3 +1,4 @@
+TOP = ..
 
 COOKIES=art ascii-art computers cookie definitions drugs education ethnic \
        food fortunes goedel humorists kids law linuxcookie literature \
@@ -15,28 +16,9 @@ all: cookies o-cookies w-cookies
 check:
        for i in $(COOKIES) ; \
                do \
-                       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 %" ; \
+                       if ! sh $(TOP)/tests/scripts/check-fortune-file.sh "$$i" ; then \
                                exit 1; \
-                       fi;\
-                       if egrep -q ".{81}" $$i ; then \
-                               echo " failed length check"; \
-                               echo "Fortune cookie file contains a line longer than 78 characters"; \
-                               exit 1; \
-                       fi; \
-                       if egrep -q "`printf "\\r"`" $$i ; then \
-                               echo " failed lack of carriage-return check"; \
-                               echo "Fortune cookie file contains a CR"; \
-                               exit 1; \
-                       fi; \
-                       if egrep -q "[ `printf "\\t"`]\$$" $$i ; then \
-                               echo " failed lack of trailing space check"; \
-                               echo "Fortune cookie file contains trailing whitespace"; \
-                               exit 1; \
-                       fi; \
-                       echo " passed " ;\
+                       fi ; \
                done;
 
 cookies: cookies-stamp
diff --git a/fortune-mod/tests/scripts/check-fortune-file.sh b/fortune-mod/tests/scripts/check-fortune-file.sh
new file mode 100644 (file)
index 0000000..24fe0e0
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+i="$1"
+shift
+
+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 %"
+    exit 1
+fi
+if egrep -q ".{81}" "$i" ; then
+    echo " failed length check"
+    echo "Fortune cookie file contains a line longer than 78 characters"
+    exit 1
+fi
+if egrep -q "`printf "\\r"`" "$i" ; then
+    echo " failed lack of carriage-return check"
+    echo "Fortune cookie file contains a CR"
+    exit 1
+fi
+if egrep -q "[ `printf "\\t"`]\$$" "$i" ; then
+    echo " failed lack of trailing space check"
+    echo "Fortune cookie file contains trailing whitespace"
+    exit 1
+fi
+echo " passed "
+exit 0