Skip to content

Commit

Permalink
Merge pull request #1081 from danigm/warn-macro-comment
Browse files Browse the repository at this point in the history
SpecCheck: Allow macros for special comments
  • Loading branch information
danigm authored Jun 29, 2023
2 parents 5a769e1 + 2d6c2ba commit 6f54739
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
9 changes: 7 additions & 2 deletions rpmlint/checks/SpecCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,13 @@ def _checkline_macros_in_comments(self, line):
# Test if there are macros in comments
if hash_pos != -1 and \
(hash_pos == 0 or line[hash_pos - 1] in (' ', '\t')):
for match in self.macro_regex.findall(
line[hash_pos + 1:]):

comment = line[hash_pos + 1:]
# Ignore special comments like #!BuildIgnore
if comment and comment[0] == '!':
return

for match in self.macro_regex.findall(comment):
res = re.match('%+', match)
if len(res.group(0)) % 2:
self.output.add_info('W', self.pkg, 'macro-in-comment', match)
Expand Down
49 changes: 49 additions & 0 deletions test/spec/MacroInComment.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Name: MacroInComment
Version: 0
Release: 0
Summary: None here

Group: Undefined
License: GPLv2
URL: http://rpmlint.zarb.org/#%{name}
Source0: Source0.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Provides: unversioned-provides, versioned-provides = 1.0
Obsoletes: versioned-obsoletes < 2.0
Obsoletes: unversioned-obsoletes
Obsoletes: /usr/bin/unversioned-but-filename
Provides: /sbin/another-unversioned-but-filename
#!BuildIgnore: %{name}

%description
MacroInComment test.

%package noarch-sub
Summary: Noarch subpackage
Group: Undefined
BuildArch: noarch

%description noarch-sub
Noarch subpackage test.

%prep
%autosetup -p 1

%build
# %configure
# %%%

%install
rm -rf $RPM_BUILD_ROOT

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
%{_libdir}/foo

%files noarch-sub
%defattr(-,root,root,-)

%changelog
24 changes: 23 additions & 1 deletion test/test_speccheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@ def speccheck():
CONFIG.info = True
output = Filter(CONFIG)
test = SpecCheck(CONFIG, output)
return output, test
yield output, test


@pytest.fixture
def output(speccheck):
output, _test = speccheck
yield output


@pytest.fixture
def test(speccheck):
_output, test = speccheck
yield test


def test_check_include(tmp_path, speccheck):
Expand Down Expand Up @@ -1168,3 +1180,13 @@ def test_null_char(package, speccheck):
test.check_spec(pkg)
out = output.print_results(output.results)
assert 'forbidden-controlchar-found' in out


@pytest.mark.parametrize('package', [
get_tested_spec_package('spec/MacroInComment'),
])
def test_special_comments(package, output, test):
test.check_spec(package)
out = output.print_results(output.results)
assert 'W: macro-in-comment %configure' in out
assert 'W: macro-in-comment %{name}' not in out

0 comments on commit 6f54739

Please sign in to comment.