Permalink
Browse files

Add a test

  • Loading branch information...
1 parent 029345a commit 8170d7c33f8e2baf6aef3bf5a24db854c1fe14f5 @holdenk committed Sep 5, 2012
Showing with 3 additions and 2 deletions.
  1. +1 −1 Unicorn/Shell.pm
  2. +2 −1 t/shell.t
View
@@ -17,7 +17,7 @@ sub fix_shell {
# http://www.pixelbeat.org/programming/shell_script_mistakes.html
$rt =~ s/if\s*\[\s*\-e\s*(\w+?)\s*\-e\s*(\w+?)\s*\]\s*$/if [-e $1] || [\-e $2]/;
#Double negative
- $rt =~ s/\[\s*\!\-z\s*(\"\$\w*\")\]/[$1]/;
+# $rt =~ s/\[\s*\!\-z\s*(\"\$\w*\")\]/SUP/;
#Check for cat pipe to grep
#i.e cat foo | grep baz
$rt =~ s/^\s*cat\s*(\w+)\s*\|\s*grep\s+([\w\"]+)\s*$/grep $2 < $1/
View
@@ -1,9 +1,10 @@
#Test the shell script thing
-use Test::More tests => 3;
+use Test::More tests => 4;
use Unicorn::Shell qw( fix_shell check_shell);
is (fix_shell("fake","#!/bin/bash\nif [-e foo -e bar]"), "#!/bin/bash\nif [-e foo] || [-e bar]", "Expands -e works");
is (check_shell("fake","#!/bin/bash\nif [-e foo -e bar]"), 1, "Expands -e works");
is (fix_shell("fake","#!/bin/bash\nif [-e foo -f bar]"), "#!/bin/bash\nif [-e foo -f bar]", "Does not expand -e / -f");
+is (fix_shell("fake","#!/bin/bash\nif [!-z \"$foo\"]"), "#!/bin/bash\nif [\"\$foo\"]", "Removes double negatives");
done_testing();

0 comments on commit 8170d7c

Please sign in to comment.