Skip to content

Commit 8457ab8

Browse files
committed
test(spec): add structural parser fixtures
1 parent b7c3b02 commit 8457ab8

14 files changed

Lines changed: 843 additions & 0 deletions
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Name: comment-only-conditional
2+
Version: 1.0
3+
Release: 1
4+
Summary: %%if blocks whose entire body is comments and blank lines
5+
License: MIT
6+
7+
%if 0%{?with_future}
8+
# Reserved for the upcoming foo backend.
9+
# Empty until upstream finalizes the API.
10+
11+
# Track: https://example.invalid/issues/42
12+
%endif
13+
14+
%description
15+
Fixture: a top-level conditional whose body contains only RPM-spec comments
16+
and blank lines, plus a guard inside a script section with the same shape.
17+
18+
%build
19+
%if 0%{?with_future}
20+
# TODO(future): wire up the foo backend once it lands upstream.
21+
%endif
22+
make
23+
24+
%install
25+
make install DESTDIR=%{buildroot}
26+
27+
%files
28+
/usr/bin/comment-only-conditional
29+
30+
%changelog
31+
* Thu Jan 01 1970 Builder <builder@example.com> - 1.0-1
32+
- Initial fixture.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Name: elif-chain
2+
Version: 1.0
3+
Release: 1
4+
Summary: %%if / %%elif / %%else chain inside preamble
5+
License: MIT
6+
7+
%if 0%{?rhel} >= 10
8+
Requires: rhel10-runtime
9+
BuildRequires: rhel10-devel
10+
%elif 0%{?rhel} >= 9
11+
Requires: rhel9-runtime
12+
BuildRequires: rhel9-devel
13+
%elif 0%{?fedora} >= 40
14+
Requires: fedora-runtime
15+
BuildRequires: fedora-devel
16+
%elif 0%{?suse_version}
17+
Requires: suse-runtime
18+
BuildRequires: suse-devel
19+
%else
20+
Requires: generic-runtime
21+
BuildRequires: generic-devel
22+
%endif
23+
24+
%description
25+
Fixture: deep %%elif chain with terminal %%else, content-style conditional
26+
(no section headers in any branch).
27+
28+
%build
29+
make
30+
31+
%install
32+
make install DESTDIR=%{buildroot}
33+
34+
%files
35+
/usr/bin/elif-chain
36+
37+
%changelog
38+
* Thu Jan 01 1970 Builder <builder@example.com> - 1.0-1
39+
- Initial fixture.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Name: elif-with-sections
2+
Version: 1.0
3+
Release: 1
4+
Summary: %%elif branches that each contain entire %%package sections
5+
License: MIT
6+
7+
%description
8+
Fixture: %%elif chain where every branch (including %%else) introduces a
9+
distinct %%package + %%description + %%files trio. Each conditional branch
10+
acts as a wrapper, not as in-section content.
11+
12+
%if 0%{?rhel}
13+
%package rhel-extras
14+
Summary: RHEL-specific extras
15+
16+
%description rhel-extras
17+
Extras only built for RHEL.
18+
19+
%files rhel-extras
20+
/usr/share/elif-with-sections/rhel
21+
%elif 0%{?fedora}
22+
%package fedora-extras
23+
Summary: Fedora-specific extras
24+
25+
%description fedora-extras
26+
Extras only built for Fedora.
27+
28+
%files fedora-extras
29+
/usr/share/elif-with-sections/fedora
30+
%else
31+
%package generic-extras
32+
Summary: Generic extras
33+
34+
%description generic-extras
35+
Fallback extras for all other distros.
36+
37+
%files generic-extras
38+
/usr/share/elif-with-sections/generic
39+
%endif
40+
41+
%build
42+
make
43+
44+
%install
45+
make install DESTDIR=%{buildroot}
46+
47+
%files
48+
/usr/bin/elif-with-sections
49+
50+
%changelog
51+
* Thu Jan 01 1970 Builder <builder@example.com> - 1.0-1
52+
- Initial fixture.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Name: if-with-continuation
2+
Version: 1.0
3+
Release: 1
4+
Summary: %%if condition that spans multiple lines via backslash continuation
5+
License: MIT
6+
7+
%global _is_long_arch \
8+
0%{?rhel} >= 9 || \
9+
0%{?fedora} >= 40 || \
10+
0%{?suse_version} >= 1550
11+
12+
%if %{_is_long_arch} && \
13+
%{undefined disable_long_arch} && \
14+
"%{_arch}" != "armv7hl"
15+
BuildRequires: long-arch-support
16+
Requires: long-arch-runtime
17+
%endif
18+
19+
%description
20+
Fixture: backslash-continuation inside an %%if condition itself (not just in
21+
the body) and in a %%global that the condition references.
22+
23+
%build
24+
make
25+
26+
%install
27+
make install DESTDIR=%{buildroot}
28+
29+
%files
30+
/usr/bin/if-with-continuation
31+
32+
%changelog
33+
* Thu Jan 01 1970 Builder <builder@example.com> - 1.0-1
34+
- Initial fixture.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Name: macro-conditional
2+
Version: 1.0
3+
Release: 1%{?dist}
4+
Summary: Fixture with %if/%endif inside macro continuation bodies
5+
License: MIT
6+
7+
# Parameterized macro with %if/%endif in the body (kernel pattern).
8+
# The %if here is RPM macro body text, NOT a structural conditional.
9+
%define kernel_reqprovconf(o) \
10+
%if %{-o:0}%{!-o:1}\
11+
Provides: kernel = %{version}-%{release}\
12+
Provides: %{name} = %{version}-%{release}\
13+
%endif\
14+
%{nil}
15+
16+
# Global macro with conditional (ghc pattern).
17+
%global obsoletes_pkg() \
18+
%if %{defined old_name}\
19+
Obsoletes: %{old_name}%{?1:-%1} < %{version}-%{release}\
20+
Provides: %{old_name}%{?1:-%1} = %{version}-%{release}\
21+
%endif\
22+
%{nil}
23+
24+
# Real structural conditional (should still be parsed).
25+
%if 0%{?fedora}
26+
BuildRequires: fedora-only-dep
27+
%endif
28+
29+
%description
30+
A spec testing that %if/%endif inside backslash-continued macro
31+
definitions are treated as macro body text, not structural conditionals.
32+
33+
%build
34+
make %{?_smp_mflags}
35+
36+
%install
37+
make install DESTDIR=%{buildroot}
38+
39+
%files
40+
/usr/bin/macro-conditional
41+
42+
%changelog
43+
* Thu Jan 01 1970 Builder <builder@example.com> - 1.0-1
44+
- Initial build.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Name: macro-continuation
2+
Version: 1.0
3+
Release: 1
4+
Summary: %%define / %%global with backslash continuation
5+
License: MIT
6+
7+
%global cmake_flags \
8+
-DENABLE_FOO=ON \
9+
-DENABLE_BAR=OFF \
10+
-DCMAKE_BUILD_TYPE=Release
11+
12+
%define configure_args \
13+
--prefix=%{_prefix} \
14+
--libdir=%{_libdir} \
15+
--sysconfdir=%{_sysconfdir}
16+
17+
%description
18+
Fixture: %%define / %%global with backslash continuation lines.
19+
20+
%build
21+
cmake %{cmake_flags} .
22+
./configure %{configure_args}
23+
make
24+
25+
%install
26+
make install DESTDIR=%{buildroot}
27+
28+
%files
29+
/usr/bin/macro-continuation
30+
31+
%changelog
32+
* Thu Jan 01 1970 Builder <builder@example.com> - 1.0-1
33+
- Initial fixture.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Name: macro-with-parameters
2+
Version: 1.0
3+
Release: 1
4+
Summary: %%define macros that accept positional parameters
5+
License: MIT
6+
7+
%define uname_suffix() %{?1:+%{1}}
8+
%define uname_variant() %{lua:
9+
local v = rpm.expand("%{?1}")
10+
if v == "" then return "" end
11+
return "-" .. v
12+
}
13+
14+
%define build_with(opt) \
15+
%{expand:%%global _with_%{1} --with-%{1}} \
16+
%global _enable_%{1} 1
17+
18+
%description
19+
Fixture: parameterized %%define macros — empty-arg, lua body, and a
20+
multi-line definition that itself expands further %%global calls.
21+
22+
%build
23+
%{build_with foo}
24+
%{build_with bar}
25+
make %{?_smp_mflags}
26+
27+
%install
28+
make install DESTDIR=%{buildroot}
29+
30+
%files
31+
/usr/bin/macro-with-parameters
32+
33+
%changelog
34+
* Thu Jan 01 1970 Builder <builder@example.com> - 1.0-1
35+
- Initial fixture.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Name: multi-package-mixed
2+
Version: 1.0
3+
Release: 1
4+
Summary: Multiple subpackages mixed with conditionals and macros
5+
License: MIT
6+
URL: https://example.invalid/
7+
Source0: %{name}-%{version}.tar.gz
8+
9+
%global commit_id 0123456789abcdef0123456789abcdef01234567
10+
%define short_commit %(echo %{commit_id} | cut -c1-7)
11+
12+
%description
13+
Fixture: realistic multi-subpackage layout combining %%package -n
14+
renaming, mixed conditional wrappers, and shared macros. Exercises tag
15+
walks, section enumeration, and per-package filtering against a
16+
non-trivial topology.
17+
18+
%package devel
19+
Summary: Development files for %{name}
20+
Requires: %{name}%{?_isa} = %{version}-%{release}
21+
22+
%description devel
23+
Headers and link-time helpers for building against %{name}.
24+
25+
%package -n lib%{name}
26+
Summary: Runtime library for %{name}
27+
Provides: bundled(%{name}-internal) = %{short_commit}
28+
29+
%description -n lib%{name}
30+
Just the shared library, suitable for stand-alone consumption.
31+
32+
%if 0%{?with_docs}
33+
%package doc
34+
Summary: Documentation for %{name}
35+
BuildArch: noarch
36+
37+
%description doc
38+
HTML and man pages for %{name}, built from the in-tree sources.
39+
%endif
40+
41+
%prep
42+
%autosetup -n %{name}-%{version}
43+
44+
%build
45+
%configure
46+
%make_build
47+
48+
%install
49+
%make_install
50+
51+
%files
52+
%license LICENSE
53+
/usr/bin/multi-package-mixed
54+
55+
%files devel
56+
/usr/include/%{name}/
57+
58+
%files -n lib%{name}
59+
/usr/lib64/lib%{name}.so.*
60+
61+
%if 0%{?with_docs}
62+
%files doc
63+
%doc README.md
64+
%doc docs/html/
65+
%endif
66+
67+
%changelog
68+
* Thu Jan 01 1970 Builder <builder@example.com> - 1.0-1
69+
- Initial fixture.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Name: nested-wrappers
2+
Version: 1.0
3+
Release: 1
4+
Summary: %%if wrappers nested inside other %%if wrappers across sections
5+
License: MIT
6+
7+
%description
8+
Fixture: outer %%if wraps the %%package devel section, which itself contains
9+
an inner %%if that wraps %%description devel / %%files devel.
10+
11+
%if 0%{?with_devel}
12+
%package devel
13+
Summary: Development files
14+
Requires: %{name} = %{version}-%{release}
15+
16+
%if 0%{?with_devel_docs}
17+
%description devel
18+
Devel files for nested-wrappers, including extra documentation.
19+
20+
%files devel
21+
/usr/include/nested-wrappers.h
22+
/usr/share/doc/nested-wrappers/devel/
23+
%else
24+
%description devel
25+
Devel files for nested-wrappers.
26+
27+
%files devel
28+
/usr/include/nested-wrappers.h
29+
%endif
30+
%endif
31+
32+
%build
33+
make
34+
35+
%install
36+
make install DESTDIR=%{buildroot}
37+
38+
%files
39+
/usr/bin/nested-wrappers
40+
41+
%changelog
42+
* Thu Jan 01 1970 Builder <builder@example.com> - 1.0-1
43+
- Initial fixture.

0 commit comments

Comments
 (0)