diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2012-03-15 16:03:36 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2012-03-15 16:03:36 +0100 |
commit | 3530ac01492727d64b7f7d10d7a1ef21bb590c5d (patch) | |
tree | 47e0012e96d187b94d9aba873f867e2a3f030e12 /source4 | |
parent | fa806eb7c666ec795fa4f8309f939c4e9bfb7b36 (diff) | |
download | samba-3530ac01492727d64b7f7d10d7a1ef21bb590c5d.tar.gz samba-3530ac01492727d64b7f7d10d7a1ef21bb590c5d.tar.bz2 samba-3530ac01492727d64b7f7d10d7a1ef21bb590c5d.zip |
samba.tests.source: Verify that only executable python files (and only executable files) have a shebang line.
Diffstat (limited to 'source4')
-rw-r--r-- | source4/scripting/python/samba/tests/source.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/source4/scripting/python/samba/tests/source.py b/source4/scripting/python/samba/tests/source.py index 06e8739dc2..0876b043d0 100644 --- a/source4/scripting/python/samba/tests/source.py +++ b/source4/scripting/python/samba/tests/source.py @@ -33,7 +33,6 @@ from samba.tests import ( ) - def get_python_source_files(): """Iterate over all Python source files.""" library_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "samba")) @@ -184,6 +183,26 @@ class TestSource(TestCase): self.fail(self._format_message(illegal_newlines, 'Non-unix newlines were found in the following source files:')) + def test_shebang_lines(self): + """Check that files with shebang lines and only those are executable.""" + files_with_shebang = {} + files_without_shebang= {} + for fname, line_no, line in self._iter_source_files_lines(): + if line_no >= 1: + continue + executable = (os.stat(fname).st_mode & 0111) + has_shebang = line.startswith("#!") + if has_shebang and not executable: + self._push_file(files_with_shebang, fname, line_no) + if not has_shebang and executable: + self._push_file(files_without_shebang, fname, line_no) + if files_with_shebang: + self.fail(self._format_message(files_with_shebang, + 'Files with shebang line that are not executable:')) + if files_without_shebang: + self.fail(self._format_message(files_without_shebang, + 'Files without shebang line that are executable:')) + pep8_ignore = [ 'E401', # multiple imports on one line 'E501', # line too long |