]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba.tests.source: Verify that only executable python files (and only executable...
authorJelmer Vernooij <jelmer@samba.org>
Thu, 15 Mar 2012 15:03:36 +0000 (16:03 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 15 Mar 2012 15:03:36 +0000 (16:03 +0100)
source4/scripting/python/samba/tests/source.py

index 06e8739dc2e9362acbdb6eca62c4d9026cdc0bb5..0876b043d0cce5c573d20ed902947c3e507c7f12 100644 (file)
@@ -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