[xen-tools-dev] [PATCH 07/13] Harden this test

Stéphane Jourdois sjourdois at gmail.com
Sun Jul 18 18:23:02 CEST 2010


Read and test only the shebang, not the whole file, +typos
---
 t/shell-syntax.t |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/t/shell-syntax.t b/t/shell-syntax.t
index a53a228..b135fb6 100755
--- a/t/shell-syntax.t
+++ b/t/shell-syntax.t
@@ -34,26 +34,25 @@ sub checkFile
     # We don't care about directories
     return if ( ! -f $file );
 
-    # Finally mercurial files are fine.
-    return if ( $file =~ /\.(hg|git)\// );
+    # Finally mercurial/git files are fine.
+    return if ( $file =~ /^\.\/\.(hg|git)\// );
 
     # See if it is a shell script.
     my $isShell = 0;
 
-    # Read the file.
+    # Read the shebang
     open( INPUT, "<", $file );
-    foreach my $line ( <INPUT> )
+    my $line = <INPUT>;
+    close( INPUT );
+
+    # Check if it is really a shell file
+    if ( $line =~ /^#! ?\/bin\/(ba)?sh/ )
     {
-        if ( ( $line =~ /\/bin\/sh/ ) ||
-             ( $line =~ /\/bin\/bash/ ) )
-        {
-            $isShell = 1;
-        }
+        $isShell = 1;
     }
-    close( INPUT );
 
     #
-    #  Return if it wasn't a perl file.
+    #  Return if it wasn't a shell file.
     #
     return if ( ! $isShell );
 
-- 
1.7.1.1



More information about the xen-tools-dev mailing list