@@ -48,14 +48,18 @@ struct BazelTargetQuerierTests {
4848 private static func makeInitializedConfig(
4949 bazelWrapper: String = " bazelisk " ,
5050 targets: [ String ] = [ " //HelloWorld " ] ,
51- indexFlags: [ String ] = [ " --config=test " ]
51+ indexFlags: [ String ] = [ " --config=test " ] ,
52+ topLevelTargetsToExclude: [ String ] = [ ] ,
53+ dependencyTargetsToExclude: [ String ] = [ ]
5254 ) -> InitializedServerConfig {
5355 let baseConfig = BaseServerConfig (
5456 bazelWrapper: bazelWrapper,
5557 targets: targets,
5658 indexFlags: indexFlags,
5759 filesToWatch: nil ,
58- compileTopLevel: false
60+ compileTopLevel: false ,
61+ topLevelTargetsToExclude: topLevelTargetsToExclude,
62+ dependencyTargetsToExclude: dependencyTargetsToExclude
5963 )
6064 return InitializedServerConfig (
6165 baseConfig: baseConfig,
@@ -89,7 +93,7 @@ struct BazelTargetQuerierTests {
8993 let config = Self . makeInitializedConfig ( )
9094
9195 let expectedCommand =
92- " bazelisk --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld)) in $topLevelTargets union kind( \" swift_library|objc_library|cc_library|alias|source file \" , deps($topLevelTargets)) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto --config=test "
96+ " bazelisk --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld)) in $topLevelTargets union ( kind( \" swift_library|objc_library|cc_library|alias|source file \" , deps($topLevelTargets) )) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto --config=test "
9397 runnerMock. setResponse ( for: expectedCommand, cwd: Self . mockRootUri, response: exampleCqueryOutput)
9498
9599 _ = try querier. cqueryTargets (
@@ -112,7 +116,7 @@ struct BazelTargetQuerierTests {
112116 let config = Self . makeInitializedConfig ( targets: [ " //HelloWorld " , " //Tests " ] )
113117
114118 let expectedCommand =
115- " bazelisk --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld //Tests)) in $topLevelTargets union kind( \" swift_library|objc_library|cc_library|alias|source file \" , deps($topLevelTargets)) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto --config=test "
119+ " bazelisk --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld //Tests)) in $topLevelTargets union ( kind( \" swift_library|objc_library|cc_library|alias|source file \" , deps($topLevelTargets) )) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto --config=test "
116120 runnerMock. setResponse ( for: expectedCommand, cwd: Self . mockRootUri, response: exampleCqueryOutput)
117121
118122 _ = try querier. cqueryTargets (
@@ -136,13 +140,13 @@ struct BazelTargetQuerierTests {
136140
137141 runnerMock. setResponse (
138142 for:
139- " bazel --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld)) in $topLevelTargets union kind( \" swift_library|alias|source file \" , deps($topLevelTargets)) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto " ,
143+ " bazel --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld)) in $topLevelTargets union ( kind( \" swift_library|alias|source file \" , deps($topLevelTargets) )) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto " ,
140144 cwd: Self . mockRootUri,
141145 response: exampleCqueryOutput
142146 )
143147 runnerMock. setResponse (
144148 for:
145- " bazel --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld)) in $topLevelTargets union kind( \" objc_library|alias|source file \" , deps($topLevelTargets)) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto " ,
149+ " bazel --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld)) in $topLevelTargets union ( kind( \" objc_library|alias|source file \" , deps($topLevelTargets) )) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto " ,
146150 cwd: Self . mockRootUri,
147151 response: exampleCqueryOutput
148152 )
@@ -178,7 +182,7 @@ struct BazelTargetQuerierTests {
178182 let config = Self . makeInitializedConfig ( )
179183
180184 let expectedCommand =
181- " bazelisk --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application|watchos_unit_test|_watchos_internal_unit_test_bundle \" , set(//HelloWorld)) in $topLevelTargets union kind( \" swift_library|objc_library|cc_library|alias|source file \" , deps($topLevelTargets)) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto --config=test "
185+ " bazelisk --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application|watchos_unit_test|_watchos_internal_unit_test_bundle \" , set(//HelloWorld)) in $topLevelTargets union ( kind( \" swift_library|objc_library|cc_library|alias|source file \" , deps($topLevelTargets) )) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto --config=test "
182186 runnerMock. setResponse ( for: expectedCommand, cwd: Self . mockRootUri, response: exampleCqueryOutput)
183187
184188 _ = try querier. cqueryTargets (
@@ -193,6 +197,82 @@ struct BazelTargetQuerierTests {
193197 #expect( ranCommands [ 0 ] . cwd == Self . mockRootUri)
194198 }
195199
200+ @Test
201+ func cqueryExcludesTopLevelTargets( ) throws {
202+ let runnerMock = CommandRunnerFake ( )
203+ let parserMock = BazelTargetQuerierParserFake ( )
204+ let querier = Self . makeQuerier ( runner: runnerMock, parser: parserMock)
205+ let config = Self . makeInitializedConfig (
206+ topLevelTargetsToExclude: [ " //HelloWorld:Excluded " ]
207+ )
208+
209+ let expectedCommand =
210+ " bazelisk --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld)) except set(//HelloWorld:Excluded) in $topLevelTargets union (kind( \" swift_library|objc_library|cc_library|alias|source file \" , deps($topLevelTargets))) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto --config=test "
211+ runnerMock. setResponse ( for: expectedCommand, cwd: Self . mockRootUri, response: exampleCqueryOutput)
212+
213+ _ = try querier. cqueryTargets (
214+ config: config,
215+ supportedDependencyRuleTypes: DependencyRuleType . allCases,
216+ supportedTopLevelRuleTypes: [ . iosApplication]
217+ )
218+
219+ let ranCommands = runnerMock. commands
220+ #expect( ranCommands. count == 1 )
221+ #expect( ranCommands [ 0 ] . command == expectedCommand)
222+ #expect( ranCommands [ 0 ] . cwd == Self . mockRootUri)
223+ }
224+
225+ @Test
226+ func cqueryExcludesDependencyTargets( ) throws {
227+ let runnerMock = CommandRunnerFake ( )
228+ let parserMock = BazelTargetQuerierParserFake ( )
229+ let querier = Self . makeQuerier ( runner: runnerMock, parser: parserMock)
230+ let config = Self . makeInitializedConfig (
231+ dependencyTargetsToExclude: [ " //Libs/ExcludedLib:ExcludedLib " ]
232+ )
233+
234+ let expectedCommand =
235+ " bazelisk --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld)) in $topLevelTargets union (kind( \" swift_library|objc_library|cc_library|alias|source file \" , deps($topLevelTargets)) except set(//Libs/ExcludedLib:ExcludedLib)) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto --config=test "
236+ runnerMock. setResponse ( for: expectedCommand, cwd: Self . mockRootUri, response: exampleCqueryOutput)
237+
238+ _ = try querier. cqueryTargets (
239+ config: config,
240+ supportedDependencyRuleTypes: DependencyRuleType . allCases,
241+ supportedTopLevelRuleTypes: [ . iosApplication]
242+ )
243+
244+ let ranCommands = runnerMock. commands
245+ #expect( ranCommands. count == 1 )
246+ #expect( ranCommands [ 0 ] . command == expectedCommand)
247+ #expect( ranCommands [ 0 ] . cwd == Self . mockRootUri)
248+ }
249+
250+ @Test
251+ func cqueryExcludesBothTopLevelAndDependencyTargets( ) throws {
252+ let runnerMock = CommandRunnerFake ( )
253+ let parserMock = BazelTargetQuerierParserFake ( )
254+ let querier = Self . makeQuerier ( runner: runnerMock, parser: parserMock)
255+ let config = Self . makeInitializedConfig (
256+ topLevelTargetsToExclude: [ " //HelloWorld:Excluded " , " //HelloWorld:AlsoExcluded " ] ,
257+ dependencyTargetsToExclude: [ " //Libs/ExcludedLib:ExcludedLib " ]
258+ )
259+
260+ let expectedCommand =
261+ " bazelisk --output_base=/path/to/output/base cquery \' let topLevelTargets = kind( \" ios_application \" , set(//HelloWorld)) except set(//HelloWorld:Excluded //HelloWorld:AlsoExcluded) in $topLevelTargets union (kind( \" swift_library|objc_library|cc_library|alias|source file \" , deps($topLevelTargets)) except set(//Libs/ExcludedLib:ExcludedLib)) \' --noinclude_aspects --notool_deps --noimplicit_deps --output proto --config=test "
262+ runnerMock. setResponse ( for: expectedCommand, cwd: Self . mockRootUri, response: exampleCqueryOutput)
263+
264+ _ = try querier. cqueryTargets (
265+ config: config,
266+ supportedDependencyRuleTypes: DependencyRuleType . allCases,
267+ supportedTopLevelRuleTypes: [ . iosApplication]
268+ )
269+
270+ let ranCommands = runnerMock. commands
271+ #expect( ranCommands. count == 1 )
272+ #expect( ranCommands [ 0 ] . command == expectedCommand)
273+ #expect( ranCommands [ 0 ] . cwd == Self . mockRootUri)
274+ }
275+
196276 // MARK: - Aquery Tests
197277
198278 @Test
0 commit comments