@@ -196,6 +196,41 @@ func TestStructuralParserFixtureSearchAndReplaceCoversLineTypes(t *testing.T) {
196196 assertReparseable (t , contents )
197197}
198198
199+ func TestStructuralParserFixtureSubpackageMacroRemovalHoistsReferencedDefinitions (t * testing.T ) {
200+ for _ , name := range []string {
201+ "subpackage-define-referenced.spec" ,
202+ "subpackage-define-transitive.spec" ,
203+ "subpackage-define-shadowed.spec" ,
204+ } {
205+ t .Run (name , func (t * testing.T ) {
206+ specification := openFixture (t , name )
207+ require .NoError (t , specification .RemoveSubpackage (
208+ map [string ]string {
209+ "subpackage-define-referenced.spec" : "tests" ,
210+ "subpackage-define-transitive.spec" : "tests" ,
211+ "subpackage-define-shadowed.spec" : "tools" ,
212+ }[name ],
213+ ))
214+
215+ contents := serializeFixture (t , specification )
216+ assertReparseable (t , contents )
217+
218+ switch name {
219+ case "subpackage-define-referenced.spec" :
220+ assert .Contains (t , contents , "%define testsdir %{_libdir}/%{name}/tests-src" )
221+ assert .Less (t , strings .LastIndex (contents , "%define testsdir" ), strings .Index (contents , "\n %install\n " ))
222+ case "subpackage-define-transitive.spec" :
223+ assert .Less (t , strings .Index (contents , "%define testroot" ), strings .Index (contents , "%define testsdir" ))
224+ assert .Contains (t , contents , "%define testsdir %{testroot}/tests-src" )
225+ case "subpackage-define-shadowed.spec" :
226+ assert .Equal (t , 2 , strings .Count (contents , "%global toolsdir" ))
227+ assert .Contains (t , contents , "tools-override" )
228+ assert .Less (t , strings .LastIndex (contents , "%global toolsdir" ), strings .Index (contents , "\n %install\n " ))
229+ }
230+ })
231+ }
232+ }
233+
199234func TestStructuralParserGDBShapedMacroBodyIsOpaqueKnownLimitation (t * testing.T ) {
200235 input := `%define gdb_python_configure \
201236%if 0%{?with_python}\
0 commit comments