@@ -144,6 +144,63 @@ struct PackagesParserTests {
144144 )
145145 #expect( messages == expectedMessages)
146146 }
147+
148+ @Test ( " test parsePackages given valid path with custom path argument uses correct target path " )
149+ func parsePackagesGivenValidPathWithCustomPathArgument( ) throws {
150+ // Given
151+ // This test verifies that:
152+ // 1. Files in Sources/Core are scanned for TestModule (has CoreDependency import)
153+ // 2. Files in Sources/UI are NOT scanned (has UndeclaredDependency import that would fail)
154+ // 3. Files in CustomTests are scanned for TestModuleTests (testTarget with custom path)
155+ let path : String = URL . Mock. customPathPackageFileDir. relativePath
156+ var messages : [ String ] = [ ]
157+ let expectedMessages : [ String ] = [
158+ " Package: CustomPathPackage Target: TestModule - Type: regular " ,
159+ " ✅ All imports for target TestModule are explicit " ,
160+ " Package: CustomPathPackage Target: TestModuleTests - Type: test " ,
161+ " ✅ All imports for target TestModuleTests are explicit "
162+ ]
163+ let sut = makeSUT ( path: path)
164+
165+ // When
166+ try sut. parsePackages (
167+ configs: configs,
168+ verbose: verbose,
169+ print: { messages. append ( $0) }
170+ )
171+
172+ // Then
173+ // If Sources/UI was incorrectly scanned, this would fail with UndeclaredDependency error
174+ #expect( messages == expectedMessages)
175+ }
176+
177+ @Test ( " test parsePackages given custom path that does not exist throws error " )
178+ func parsePackagesGivenCustomPathNotFoundThrowsError( ) throws {
179+ // Given
180+ let path : String = URL . Mock. invalidCustomPathPackageFileDir. relativePath
181+ var messages : [ String ] = [ ]
182+ let expectedMessages : [ String ] = [
183+ " Package: InvalidPathPackage Target: MissingModule - Type: regular "
184+ ]
185+ let sut = makeSUT ( path: path)
186+
187+ // When, Then
188+ #expect(
189+ throws: PackagesParser . Error. customPathNotFound (
190+ targetName: " MissingModule " ,
191+ path: " Sources/DoesNotExist " ,
192+ resolvedPath: path + " /InvalidPathPackage/Sources/DoesNotExist "
193+ ) ,
194+ performing: {
195+ try sut. parsePackages (
196+ configs: configs,
197+ verbose: verbose,
198+ print: { messages. append ( $0) }
199+ )
200+ }
201+ )
202+ #expect( messages == expectedMessages)
203+ }
147204}
148205
149206extension PackagesParserTests {
@@ -162,5 +219,7 @@ private extension URL {
162219 static let secondPackageFileDir = Bundle . module. url ( forResource: " Example/SecondPackage/Package " , withExtension: " swift " ) !. deletingLastPathComponent ( )
163220 static let duplicatesPackageFileDir = Bundle . module. url ( forResource: " Example/DuplicatesPackage/Package " , withExtension: " swift " ) !. deletingLastPathComponent ( )
164221 static let failurePackageFileDir = Bundle . module. url ( forResource: " Example/FailurePackage/Package " , withExtension: " swift " ) !. deletingLastPathComponent ( )
222+ static let customPathPackageFileDir = Bundle . module. url ( forResource: " Example/CustomPathPackage/Package " , withExtension: " swift " ) !. deletingLastPathComponent ( )
223+ static let invalidCustomPathPackageFileDir = Bundle . module. url ( forResource: " Example/InvalidCustomPathPackage/Package " , withExtension: " swift " ) !. deletingLastPathComponent ( )
165224 }
166225}
0 commit comments