-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c29be0c
commit 90e461c
Showing
12 changed files
with
1,541 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Foundation | ||
|
||
import XcodeProj | ||
import XCConfig | ||
|
||
// this is needed for XCScheme creation | ||
import PathKit | ||
|
||
/// Detect when a shared scheme has disabled tests. | ||
struct SharedSchemeSkipsTestsRule { | ||
func run(_ environment: XCLinter.Environment) throws -> [Violation] { | ||
let sharedSchemesURL = environment | ||
.projectRootURL | ||
.appendingPathComponent("xcshareddata/xcschemes", isDirectory: true) | ||
.standardizedFileURL | ||
|
||
let fileManager = FileManager.default | ||
|
||
guard fileManager.isReadableFile(atPath: sharedSchemesURL.path) else { return [] } | ||
|
||
var violations = [Violation]() | ||
|
||
for entry in try fileManager.contentsOfDirectory(atPath: sharedSchemesURL.path) { | ||
let entryPath = sharedSchemesURL | ||
.appendingPathComponent(entry, isDirectory: false) | ||
.standardizedFileURL | ||
.path | ||
|
||
let scheme = try XCScheme(path: Path(entryPath)) | ||
|
||
guard let testAction = scheme.testAction else { continue } | ||
|
||
if testAction.testables.contains(where: { $0.skipped == true }) { | ||
violations.append(.init("Scheme \"\(entry)\" has skipped test bundles")) | ||
} | ||
|
||
if testAction.testables.contains(where: { $0.skippedTests.isEmpty == false }) { | ||
violations.append(.init("Scheme \"\(entry)\" has skipped tests")) | ||
} | ||
} | ||
|
||
|
||
return violations | ||
} | ||
|
||
private func validateSchemes(in url: URL) throws -> [Violation] { | ||
let fileManager = FileManager.default | ||
|
||
guard fileManager.isReadableFile(atPath: url.path) else { return [] } | ||
|
||
var violations = [Violation]() | ||
|
||
for entry in try fileManager.contentsOfDirectory(atPath: url.path) { | ||
let entryPath = url | ||
.appendingPathComponent(entry, isDirectory: false) | ||
.standardizedFileURL | ||
.path | ||
|
||
let scheme = try XCScheme(path: Path(entryPath)) | ||
|
||
if scheme.buildAction?.buildImplicitDependencies == true { | ||
violations.append(.init("Scheme \"\(entry)\" has implicit dependencies enabled")) | ||
} | ||
} | ||
|
||
return violations | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import XCTest | ||
|
||
@testable import XCLinting | ||
import XcodeProj | ||
|
||
final class SharedSchemeSkipsTestsRuleTests: XCTestCase { | ||
func testProjectWithNoSkippedTests() throws { | ||
let url = try Bundle.module.testDataURL(named: "StockMacOSApp.xcodeproj") | ||
|
||
let project = try XcodeProj(pathString: url.path) | ||
|
||
let env = XCLinter.Environment( | ||
project: project, | ||
projectRootURL: url, | ||
configuration: Configuration() | ||
) | ||
|
||
let violations = try SharedSchemeSkipsTestsRule().run(env) | ||
|
||
XCTAssertTrue(violations.isEmpty) | ||
} | ||
|
||
func testProjectWithSkippedTests() throws { | ||
let url = try Bundle.module.testDataURL(named: "SchemeSkipsTests.xcodeproj") | ||
|
||
let project = try XcodeProj(pathString: url.path) | ||
|
||
let env = XCLinter.Environment( | ||
project: project, | ||
projectRootURL: url, | ||
configuration: Configuration() | ||
) | ||
|
||
let violations = try SharedSchemeSkipsTestsRule().run(env) | ||
|
||
XCTAssertFalse(violations.isEmpty) | ||
} | ||
|
||
func testProjectWithSkippedTestBundles() throws { | ||
let url = try Bundle.module.testDataURL(named: "SchemeSkipsTestBundles.xcodeproj") | ||
|
||
let project = try XcodeProj(pathString: url.path) | ||
|
||
let env = XCLinter.Environment( | ||
project: project, | ||
projectRootURL: url, | ||
configuration: Configuration() | ||
) | ||
|
||
let violations = try SharedSchemeSkipsTestsRule().run(env) | ||
|
||
XCTAssertFalse(violations.isEmpty) | ||
} | ||
} |
Oops, something went wrong.