Skip to content

Commit 4de34e3

Browse files
authored
Merge branch 'main' into aaronsky/enable-code-coverage-in-xcode
2 parents 1459684 + d90788b commit 4de34e3

19 files changed

+114
-11
lines changed

docs/bazel.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ Creates a value for the [`scheme_autogeneration_config`](xcodeproj-scheme_autoge
265265
| Name | Description | Default Value |
266266
| :------------- | :------------- | :------------- |
267267
| <a id="xcschemes.autogeneration_config-scheme_name_exclude_patterns"></a>scheme_name_exclude_patterns | A `list` of regex patterns used to skip creating matching autogenerated schemes.<br><br>Example:<br><br><pre><code class="language-starlark">xcodeproj(&#10; ...&#10; scheme_name_exclude_patterns = xcschemes.autogeneration_config(&#10; scheme_name_exclude_patterns = [&#10; ".*somePattern.*",&#10; "^AnotherPattern.*",&#10; ],&#10; ),&#10;)</code></pre> | `None` |
268-
| <a id="xcschemes.autogeneration_config-test"></a>test | Options to use for the test action.<br><br>Example:<br><br>```starlark xcodeproj( ... scheme_autogeneration_config = xcschemes.autogeneration_config( test = xcschemes.autogeneration.test( options = xcschemes.test_options( app_language = "en", app_region = "US", ) ) ) ) | `None` |
268+
| <a id="xcschemes.autogeneration_config-test"></a>test | Options to use for the test action.<br><br>Example:<br><br><pre><code class="language-starlark">xcodeproj(&#10; ...&#10; scheme_autogeneration_config = xcschemes.autogeneration_config(&#10; test = xcschemes.autogeneration.test(&#10; options = xcschemes.test_options(&#10; app_language = "en",&#10; app_region = "US",&#10; code_coverage = False,&#10; )&#10; )&#10; )&#10;)</code></pre> | `None` |
269269

270270
**RETURNS**
271271

@@ -537,7 +537,7 @@ Defines the Test action.
537537
## xcschemes.test_options
538538

539539
<pre>
540-
xcschemes.test_options(<a href="#xcschemes.test_options-app_language">app_language</a>, <a href="#xcschemes.test_options-app_region">app_region</a>)
540+
xcschemes.test_options(<a href="#xcschemes.test_options-app_language">app_language</a>, <a href="#xcschemes.test_options-app_region">app_region</a>, <a href="#xcschemes.test_options-code_coverage">code_coverage</a>)
541541
</pre>
542542

543543
Defines the test options for a custom scheme.
@@ -549,6 +549,7 @@ Defines the test options for a custom scheme.
549549
| :------------- | :------------- | :------------- |
550550
| <a id="xcschemes.test_options-app_language"></a>app_language | Language to set in scheme.<br><br>Defaults to system settings if not set. | `None` |
551551
| <a id="xcschemes.test_options-app_region"></a>app_region | Region to set in scheme.<br><br>Defaults to system settings if not set. | `None` |
552+
| <a id="xcschemes.test_options-code_coverage"></a>code_coverage | Whether to enable code coverage.<br><br>If `True`, code coverage will be enabled. | `False` |
552553

553554

554555
<a id="xcschemes.test_target"></a>

examples/integration/xcodeproj_targets.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ SCHEME_AUTOGENERATION_CONFIG = xcschemes.autogeneration_config(
152152
options = xcschemes.test_options(
153153
app_language = "en",
154154
app_region = "US",
155+
code_coverage = False,
155156
),
156157
),
157158
)
@@ -187,6 +188,7 @@ XCSCHEMES = [
187188
test_options = xcschemes.test_options(
188189
app_language = "en",
189190
app_region = "US",
191+
code_coverage = False,
190192
),
191193
test_targets = [
192194
"//iOSApp/Test/SwiftUnitTests:iOSAppSwiftUnitTests",

test/internal/xcschemes/info_constructors_tests.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def info_constructors_test_suite(name):
271271
expected_info = struct(
272272
app_language = "",
273273
app_region = "",
274+
code_coverage = "0",
274275
),
275276
)
276277

@@ -281,12 +282,14 @@ def info_constructors_test_suite(name):
281282
info = xcscheme_infos_testable.make_test_options(
282283
app_language = "en",
283284
app_region = "US",
285+
code_coverage = "0",
284286
),
285287

286288
# Expected
287289
expected_info = struct(
288290
app_language = "en",
289291
app_region = "US",
292+
code_coverage = "0",
290293
),
291294
)
292295

@@ -759,6 +762,7 @@ def info_constructors_test_suite(name):
759762
options = xcscheme_infos_testable.make_test_options(
760763
app_language = "en",
761764
app_region = "US",
765+
code_coverage = "0",
762766
),
763767
test_targets = [
764768
xcscheme_infos_testable.make_test_target("tt 9"),
@@ -796,6 +800,7 @@ def info_constructors_test_suite(name):
796800
options = xcscheme_infos_testable.make_test_options(
797801
app_language = "en",
798802
app_region = "US",
803+
code_coverage = "0",
799804
),
800805
test_targets = [
801806
xcscheme_infos_testable.make_test_target("tt 9"),

test/internal/xcschemes/infos_from_json_tests.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ def infos_from_json_test_suite(name):
997997
options = struct(
998998
app_language = "en",
999999
app_region = "US",
1000+
code_coverage = "0",
10001001
),
10011002
test_targets = [
10021003
"tt 1 label",
@@ -1090,6 +1091,7 @@ def infos_from_json_test_suite(name):
10901091
options = xcscheme_infos_testable.make_test_options(
10911092
app_language = "en",
10921093
app_region = "US",
1094+
code_coverage = "0",
10931095
),
10941096
test_targets = [
10951097
xcscheme_infos_testable.make_test_target("sim tt 1"),

test/internal/xcschemes/utils.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def _dict_to_test_options_info(d):
2424
return struct(
2525
app_language = d["app_language"],
2626
app_region = d["app_region"],
27+
code_coverage = d["code_coverage"],
2728
)
2829

2930
def _dict_to_launch_target_info(d):

test/internal/xcschemes/write_schemes_tests.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ def write_schemes_test_suite(name):
615615
options = xcscheme_infos_testable.make_test_options(
616616
app_language = "en",
617617
app_region = "US",
618+
code_coverage = "0",
618619
),
619620
test_targets = [
620621
xcscheme_infos_testable.make_test_target(
@@ -1091,6 +1092,8 @@ def write_schemes_test_suite(name):
10911092
"",
10921093
# - test - app_region
10931094
"",
1095+
# - test - code_coverage
1096+
"0",
10941097
# - test - xcodeConfiguration
10951098
"",
10961099
# - run - buildTargets
@@ -1194,6 +1197,8 @@ def write_schemes_test_suite(name):
11941197
"en",
11951198
# - test - app_region
11961199
"US",
1200+
# - test - code_coverage
1201+
"0",
11971202
# - test - xcodeConfiguration
11981203
"Test",
11991204
# - run - buildTargets
@@ -1325,6 +1330,8 @@ def write_schemes_test_suite(name):
13251330
"",
13261331
# - test - app_region
13271332
"",
1333+
# - test - code_coverage
1334+
"0",
13281335
# - test - xcodeConfiguration
13291336
"",
13301337
# - run - buildTargets

tools/generators/lib/XCScheme/src/CreateTestAction.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public struct CreateTestAction {
1212
public func callAsFunction(
1313
appLanguage: String?,
1414
appRegion: String?,
15+
codeCoverage: Bool,
1516
buildConfiguration: String,
1617
commandLineArguments: [CommandLineArgument],
1718
enableAddressSanitizer: Bool,
@@ -29,6 +30,7 @@ public struct CreateTestAction {
2930
return callable(
3031
/*appLanguage:*/ appLanguage,
3132
/*appRegion:*/ appRegion,
33+
/*codeCoverage:*/ codeCoverage,
3234
/*buildConfiguration:*/ buildConfiguration,
3335
/*commandLineArguments:*/ commandLineArguments,
3436
/*enableAddressSanitizer:*/ enableAddressSanitizer,
@@ -52,6 +54,7 @@ extension CreateTestAction {
5254
public typealias Callable = (
5355
_ appLanguage: String?,
5456
_ appRegion: String?,
57+
_ codeCoverage: Bool,
5558
_ buildConfiguration: String,
5659
_ commandLineArguments: [CommandLineArgument],
5760
_ enableAddressSanitizer: Bool,
@@ -70,6 +73,7 @@ extension CreateTestAction {
7073
public static func defaultCallable(
7174
appLanguage: String?,
7275
appRegion: String?,
76+
codeCoverage: Bool,
7377
buildConfiguration: String,
7478
commandLineArguments: [CommandLineArgument],
7579
enableAddressSanitizer: Bool,
@@ -118,6 +122,9 @@ buildConfiguration = "\#(buildConfiguration)"
118122
if let appRegion {
119123
components.append("region = \"\(appRegion)\"")
120124
}
125+
if codeCoverage {
126+
components.append("codeCoverageEnabled = \"YES\"")
127+
}
121128

122129
let macroExpansion: String
123130
if let macroReference {

tools/generators/lib/XCScheme/test/CreateTestActionTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,45 @@ final class CreateTestActionTests: XCTestCase {
417417

418418
XCTAssertNoDifference(action, expectedAction)
419419
}
420+
421+
func test_codeCoverageEnable() {
422+
// Arrange
423+
424+
let buildConfiguration = "Release"
425+
let useLaunchSchemeArgsEnv = false
426+
427+
let expectedAction = #"""
428+
<TestAction
429+
buildConfiguration = "Release"
430+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
431+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
432+
shouldUseLaunchSchemeArgsEnv = "NO"
433+
language = "en"
434+
region = "US">
435+
<Testables>
436+
</Testables>
437+
</TestAction>
438+
"""#
439+
440+
// Act
441+
442+
let action = createTestActionWithDefaults(
443+
appLanguage: "en",
444+
appRegion: "US",
445+
buildConfiguration: buildConfiguration,
446+
useLaunchSchemeArgsEnv: useLaunchSchemeArgsEnv
447+
)
448+
449+
// Assert
450+
451+
XCTAssertNoDifference(action, expectedAction)
452+
}
420453
}
421454

422455
private func createTestActionWithDefaults(
423456
appLanguage: String? = nil,
424457
appRegion: String? = nil,
458+
codeCoverage: Bool = false,
425459
buildConfiguration: String,
426460
commandLineArguments: [CommandLineArgument] = [],
427461
enableAddressSanitizer: Bool = false,
@@ -439,6 +473,7 @@ private func createTestActionWithDefaults(
439473
return CreateTestAction.defaultCallable(
440474
appLanguage: appLanguage,
441475
appRegion: appRegion,
476+
codeCoverage: codeCoverage,
442477
buildConfiguration: buildConfiguration,
443478
commandLineArguments: commandLineArguments,
444479
enableAddressSanitizer: enableAddressSanitizer,

tools/generators/xcschemes/src/Generator/AutogenerationConfigArguments.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ToolCommon
44
struct AutogenerationConfigArguments {
55
let appLanguage: String?
66
let appRegion: String?
7+
let codeCoverage: Bool
78
let schemeNameExcludePatterns: [String]
89

910
static func parse(
@@ -21,6 +22,11 @@ struct AutogenerationConfigArguments {
2122
as: String?.self,
2223
in: url
2324
)
25+
let codeCoverage = try rawArgs.consumeArg(
26+
"code-coverage",
27+
as: Bool.self,
28+
in: url
29+
)
2430
let schemeNameExcludePatterns = try rawArgs.consumeArgs(
2531
"scheme-name-exclude-patterns",
2632
in: url
@@ -29,6 +35,7 @@ struct AutogenerationConfigArguments {
2935
return AutogenerationConfigArguments(
3036
appLanguage: appLanguage,
3137
appRegion: appRegion,
38+
codeCoverage: codeCoverage,
3239
schemeNameExcludePatterns: schemeNameExcludePatterns
3340
)
3441
}

tools/generators/xcschemes/src/Generator/CreateCustomSchemeInfos.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,11 @@ set
659659
as: String?.self,
660660
in: url
661661
)
662+
let codeCoverage = try consumeArg(
663+
"test-code-coverage",
664+
as: Bool.self,
665+
in: url
666+
)
662667
let xcodeConfiguration = try consumeArg(
663668
"test-xcode-configuration",
664669
as: String?.self,
@@ -739,7 +744,8 @@ set
739744
enableThreadPerformanceChecker: enableThreadPerformanceChecker,
740745
environmentVariables: environmentVariables,
741746
options: .init(appLanguage: appLanguage,
742-
appRegion: appRegion),
747+
appRegion: appRegion,
748+
codeCoverage: codeCoverage),
743749
testTargets: testTargets,
744750
useRunArgsAndEnv: useRunArgsAndEnv,
745751
xcodeConfiguration: xcodeConfiguration

0 commit comments

Comments
 (0)