Patchwork [7,of,7] tests: add test-check-execute.t

login
register
mail settings
Submitter timeless@mozdev.org
Date Dec. 22, 2015, 11:14 a.m.
Message ID <6ad4f900e4fdf8efed6f.1450782855@waste.org>
Download mbox | patch
Permalink /patch/12241/
State Superseded
Headers show

Comments

timeless@mozdev.org - Dec. 22, 2015, 11:14 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1450782356 0
#      Tue Dec 22 11:05:56 2015 +0000
# Node ID 6ad4f900e4fdf8efed6fc67e0216db89e4973599
# Parent  e394811e1af32bd177e2429baea8c7d623491ff0
tests: add test-check-execute.t

Try to prevent people from adding files with incorrect execute bits
Augie Fackler - Dec. 29, 2015, 10:46 p.m.
On Tue, Dec 22, 2015 at 05:14:15AM -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1450782356 0
> #      Tue Dec 22 11:05:56 2015 +0000
> # Node ID 6ad4f900e4fdf8efed6fc67e0216db89e4973599
> # Parent  e394811e1af32bd177e2429baea8c7d623491ff0
> tests: add test-check-execute.t

Sure, seems like a worthy cause. Queued.

>
> Try to prevent people from adding files with incorrect execute bits
>
> diff --git a/tests/test-check-execute.t b/tests/test-check-execute.t
> new file mode 100644
> --- /dev/null
> +++ b/tests/test-check-execute.t
> @@ -0,0 +1,34 @@
> +#require test-repo
> +
> +  $ cd "`dirname "$TESTDIR"`"
> +
> +look for python scripts without the execute bit
> +
> +  $ hg files 'set:(**.py) and not exec()' 2> /dev/null | \
> +  > xargs -n1 egrep -n -H '(env |/)python'|grep ':1:' | \
> +  > cat
> +
> +look for python scripts with execute bit but not shbang
> +
> +  $ hg files 'set:(**.py) and exec()' 2> /dev/null | \
> +  > xargs -n1 egrep -n -L '^#!.*(env |/)python' | \
> +  > cat
> +
> +look for shell scripts with execute bit but not shbang
> +
> +  $ hg files 'set:(**.sh) and exec()' 2> /dev/null | \
> +  > xargs -n1 egrep -n -L '^#!.*(env |/)(ba|)sh' | \
> +  > cat
> +
> +look for shell scripts with execute bit and no shbang on first line
> +
> +  $ for a in $(hg files 'set:exec() and (**.sh)' 2> /dev/null); \
> +  > do head -1 $a|grep '#!' > /dev/null|| echo $a; \
> +  > done
> +
> +look for non scripts with no shbang
> +
> +  $ for a in $(hg files 'set:exec() and not (**.sh) and not (**.py)' 2> /dev/null); \
> +  > do head -1 $a|grep '#!' > /dev/null|| echo $a; \
> +  > done
> +
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/tests/test-check-execute.t b/tests/test-check-execute.t
new file mode 100644
--- /dev/null
+++ b/tests/test-check-execute.t
@@ -0,0 +1,34 @@ 
+#require test-repo
+
+  $ cd "`dirname "$TESTDIR"`"
+
+look for python scripts without the execute bit
+
+  $ hg files 'set:(**.py) and not exec()' 2> /dev/null | \
+  > xargs -n1 egrep -n -H '(env |/)python'|grep ':1:' | \
+  > cat
+
+look for python scripts with execute bit but not shbang
+
+  $ hg files 'set:(**.py) and exec()' 2> /dev/null | \
+  > xargs -n1 egrep -n -L '^#!.*(env |/)python' | \
+  > cat
+
+look for shell scripts with execute bit but not shbang
+
+  $ hg files 'set:(**.sh) and exec()' 2> /dev/null | \
+  > xargs -n1 egrep -n -L '^#!.*(env |/)(ba|)sh' | \
+  > cat
+
+look for shell scripts with execute bit and no shbang on first line
+
+  $ for a in $(hg files 'set:exec() and (**.sh)' 2> /dev/null); \
+  > do head -1 $a|grep '#!' > /dev/null|| echo $a; \
+  > done
+
+look for non scripts with no shbang
+
+  $ for a in $(hg files 'set:exec() and not (**.sh) and not (**.py)' 2> /dev/null); \
+  > do head -1 $a|grep '#!' > /dev/null|| echo $a; \
+  > done
+