From a3e64d7edcef3412cc64056510aacb046a2cc4a7 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Mon, 27 Jul 2009 00:12:54 +0200 Subject: [PATCH] lib.sh: Add perl support to generate(). Also add test for this. --- lib.sh | 9 +++++---- tests/lib.sh.test | 8 ++++++++ tests/lib.sh.test.out | 9 +++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib.sh b/lib.sh index 799560c..9d79b65 100644 --- a/lib.sh +++ b/lib.sh @@ -99,9 +99,10 @@ warning() { # The following commands are possible; the file extension for the source file # in brackets. # -# - m4 (.m4): pipe $2.m4 through m4 then write it to $2 -# - awk (.in): pipe $2.in through awk then write it to $2 -# - cat ($3): copy $2$3 to $2 +# - m4 (.m4): pipe $2.m4 through m4 then write it to $2 +# - awk (.in): pipe $2.in through awk then write it to $2 +# - perl (.in): pipe $2.in through perl then write it to $2 +# - cat ($3): copy $2$3 to $2 generate() { # Get command and target file. command="$1" @@ -114,7 +115,7 @@ generate() { # extension. if [ x"$command" = xm4 ]; then extension=.m4 - elif [ x"$command" = xawk ]; then + elif [ x"$command" = xawk -o x"$command" = xperl ]; then extension=.in elif [ x"$command" = xcat ]; then extension="$1" # is $3 in reality, $1 because of shifting diff --git a/tests/lib.sh.test b/tests/lib.sh.test index d3620cc..32bbd70 100644 --- a/tests/lib.sh.test +++ b/tests/lib.sh.test @@ -63,6 +63,14 @@ generate awk tmp/test-awk '{ print $1 }' # Remove the line with the current date as it changes every time. cat tmp/test-awk | grep -v "It was generated from tmp/test-awk.in" +# Test generate() using perl. +echo "Simple test fiel for generate() using perl. +first second +" > tmp/test-perl.in +generate perl tmp/test-perl -p -e 's/first/best/' +# Remove the line with the current date as it changes every time. +cat tmp/test-perl | grep -v "It was generated from tmp/test-perl.in" + # Test generate() using cat. echo "Simple test fiel for generate() using cat (simple copy). diff --git a/tests/lib.sh.test.out b/tests/lib.sh.test.out index 725a69a..9258e0f 100644 --- a/tests/lib.sh.test.out +++ b/tests/lib.sh.test.out @@ -39,6 +39,15 @@ awk: generating 'tmp/test-awk' from 'tmp/test-awk.in' with options '{ print $1 } Simple first +perl: generating 'tmp/test-perl' from 'tmp/test-perl.in' with options '-p -e s/first/best/' +################################### +# WARNING! DO NOT EDIT THIS FILE! # +################################### + + +Simple test fiel for generate() using perl. +best second + cat: generating 'tmp/test-cat' from 'tmp/test-cat.real' ################################### # WARNING! DO NOT EDIT THIS FILE! # -- 2.43.2