mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-09-19 16:40:46 -09:00
Currently there are no .mk, Config.in, .patch or .hash files with executable permissions in the tree. But we don't want to have that. So warn when a file checked by check-package has executable permission. This check will be reused when testing SysV init scripts in the tree. Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com> [Arnout: use context manager for temp dir so it gets deleted] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
42 lines
1.1 KiB
Python
42 lines
1.1 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
|