Skip to content

Commit

Permalink
Added support for SelectedTests in schemes Test configuration. (#913)
Browse files Browse the repository at this point in the history
* added support for selectedTests in test shemes

* added PR description to changelog

* CHANGELOG fix

* use presence of selectedTests for useTestSelectionWhitelist

Co-authored-by: Artem Semavin <Artem Semavin>
Co-authored-by: yonaskolb <[email protected]>
  • Loading branch information
ooodin and yonaskolb authored Apr 8, 2021
1 parent 209afcc commit 0ac7a5f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added explicity `LastUpgradeCheck` and `LastUpgradeVersion` override support so it's possible to override these properties without using the `project.xcodeVersion`. [1013](https://github.com/yonaskolb/XcodeGen/pull/1013) @Andre113
- Added `macroExpansion` for `run` in `schemes` [#1036](https://github.com/yonaskolb/XcodeGen/pull/1036) @freddi-kit
- Added `askForAppToLaunch` for `profile` in `schemes` [#1035](https://github.com/yonaskolb/XcodeGen/pull/1035) @freddi-kit
- Added support for selectedTests in schemes `Test` configuration. [#913](https://github.com/yonaskolb/XcodeGen/pull/913) @ooodin

#### Fixed
- Fixed regression on **.storekit** configuration files' default build phase. [#1026](https://github.com/yonaskolb/XcodeGen/pull/1026) @jcolicchio
Expand Down
3 changes: 2 additions & 1 deletion Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ A multiline script can be written using the various YAML multiline methods, for
- [ ] **parallelizable**: **Bool** - Whether to run tests in parallel. Defaults to false
- [ ] **randomExecutionOrder**: **Bool** - Whether to run tests in a random order. Defaults to false
- [ ] **skipped**: **Bool** - Whether to skip all of the test target tests. Defaults to false
- [ ] **skippedTests**: **[String]** - List of tests in the test target to skip. Defaults to empty.
- [ ] **skippedTests**: **[String]** - List of tests in the test target to skip. Defaults to empty
- [ ] **selectedTests**: **[String]** - List of tests in the test target to whitelist and select. Defaults to empty. This will override `skippedTests` if provided

### Archive Action

Expand Down
7 changes: 6 additions & 1 deletion Sources/ProjectSpec/Scheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,22 @@ public struct Scheme: Equatable {
public var parallelizable: Bool
public var skipped: Bool
public var skippedTests: [String]
public var selectedTests: [String]

public init(
targetReference: TargetReference,
randomExecutionOrder: Bool = randomExecutionOrderDefault,
parallelizable: Bool = parallelizableDefault,
skipped: Bool = false,
skippedTests: [String] = []
skippedTests: [String] = [],
selectedTests: [String] = []
) {
self.targetReference = targetReference
self.randomExecutionOrder = randomExecutionOrder
self.parallelizable = parallelizable
self.skipped = skipped
self.skippedTests = skippedTests
self.selectedTests = selectedTests
}

public init(stringLiteral value: String) {
Expand All @@ -207,6 +210,7 @@ public struct Scheme: Equatable {
parallelizable = false
skipped = false
skippedTests = []
selectedTests = []
} catch {
fatalError(SpecParsingError.invalidTargetReference(value).description)
}
Expand Down Expand Up @@ -512,6 +516,7 @@ extension Scheme.Test.TestTarget: JSONObjectConvertible {
parallelizable = jsonDictionary.json(atKeyPath: "parallelizable") ?? Scheme.Test.TestTarget.parallelizableDefault
skipped = jsonDictionary.json(atKeyPath: "skipped") ?? false
skippedTests = jsonDictionary.json(atKeyPath: "skippedTests") ?? []
selectedTests = jsonDictionary.json(atKeyPath: "selectedTests") ?? []
}
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/XcodeGenKit/SchemeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ public class SchemeGenerator {
parallelizable: testTarget.parallelizable,
randomExecutionOrdering: testTarget.randomExecutionOrder,
buildableReference: testBuilEntries.buildableReference,
skippedTests: testTarget.skippedTests.map(XCScheme.TestItem.init)
skippedTests: testTarget.skippedTests.map(XCScheme.TestItem.init),
selectedTests: testTarget.selectedTests.map(XCScheme.TestItem.init),
useTestSelectionWhitelist: !testTarget.selectedTests.isEmpty ? true : nil
)
}

Expand Down
40 changes: 40 additions & 0 deletions Tests/ProjectSpecTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,46 @@ class SpecLoadingTests: XCTestCase {
try expect(scheme.test) == expectedTest
}

$0.it("parses alternate test schemes") {
let schemeDictionary: [String: Any] = [
"build": [
"targets": ["Target1": "all"],
],
"test": [
"config": "debug",
"targets": [
"Target1",
[
"name": "ExternalProject/Target2",
"parallelizable": true,
"randomExecutionOrder": true,
"selectedTests": ["Test/testExample()"],
],
],
"gatherCoverageData": true,
"disableMainThreadChecker": true,
"stopOnEveryMainThreadCheckerIssue": true,
],
]
let scheme = try Scheme(name: "Scheme", jsonDictionary: schemeDictionary)

let expectedTest = Scheme.Test(
config: "debug",
gatherCoverageData: true,
disableMainThreadChecker: true,
targets: [
"Target1",
Scheme.Test.TestTarget(
targetReference: "ExternalProject/Target2",
randomExecutionOrder: true,
parallelizable: true,
selectedTests: ["Test/testExample()"]
),
]
)
try expect(scheme.test) == expectedTest
}

$0.it("parses schemes variables") {
let schemeDictionary: [String: Any] = [
"build": [
Expand Down

0 comments on commit 0ac7a5f

Please sign in to comment.