mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-09-19 16:40:46 -09:00
Enable the common checks: - consecutive empty lines - empty last line - missing new line at end of file - trailing space - warn for executable files, with the hint to instead use '$(INSTALL) -D -m 0755' in the .mk file Check indent with tabs: - add a simple check function to warn only when the indent is done using spaces or a mix of tabs and spaces. It does not check indenting levels, but it already makes the review easier, since it diferentiates spaces and tabs. Check variables: - check DAEMON is defined - when DAEMON is defined, check the filename is in the form S01daemon - when PIDFILE is defined, expect it to be in /var/run and defined using $DAEMON. Also add unit test for this. Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com> [Arnout: avoid 'del NotExecutable_base' by importing the module instead of the class; refer to manual in warnings] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
import os
|
|
import pytest
|
|
import re
|
|
import tempfile
|
|
import checkpackagelib.tool as m
|
|
|
|
workdir_regex = re.compile(r'/tmp/tmp[^/]*-checkpackagelib-test-tool')
|
|
|
|
|
|
def check_file(tool, filename, string, permissions=None):
|
|
with tempfile.TemporaryDirectory(suffix='-checkpackagelib-test-tool') as workdir:
|
|
script = os.path.join(workdir, filename)
|
|
with open(script, 'wb') as f:
|
|
f.write(string.encode())
|
|
if permissions:
|
|
os.chmod(script, permissions)
|
|
obj = tool(script)
|
|
result = obj.run()
|
|
if result is None:
|
|
return []
|
|
return [workdir_regex.sub('dir', r) for r in result]
|
|
|
|
|
|
NotExecutable = [
|
|
('664',
|
|
'package.mk',
|
|
0o664,
|
|
'',
|
|
[]),
|
|
('775',
|
|
'package.mk',
|
|
0o775,
|
|
'',
|
|
["dir/package.mk:0: This file does not need to be executable"]),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize('testname,filename,permissions,string,expected', NotExecutable)
|
|
def test_NotExecutable(testname, filename, permissions, string, expected):
|
|
warnings = check_file(m.NotExecutable, filename, string, permissions)
|
|
assert warnings == expected
|
|
|
|
|
|
NotExecutable_hint = [
|
|
('no hint',
|
|
"",
|
|
'sh-shebang.sh',
|
|
0o775,
|
|
'#!/bin/sh',
|
|
["dir/sh-shebang.sh:0: This file does not need to be executable"]),
|
|
('hint',
|
|
", very special hint",
|
|
'sh-shebang.sh',
|
|
0o775,
|
|
'#!/bin/sh',
|
|
["dir/sh-shebang.sh:0: This file does not need to be executable, very special hint"]),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize('testname,hint,filename,permissions,string,expected', NotExecutable_hint)
|
|
def test_NotExecutable_hint(testname, hint, filename, permissions, string, expected):
|
|
class NotExecutable(m.NotExecutable):
|
|
def hint(self):
|
|
return hint
|
|
warnings = check_file(NotExecutable, filename, string, permissions)
|
|
assert warnings == expected
|