-
-
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
aaba185
commit b869601
Showing
5 changed files
with
79 additions
and
2 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
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,37 @@ | ||
import Foundation | ||
|
||
import XcodeProj | ||
import XCConfig | ||
|
||
/// Ensure that targets have a shared scheme on disk. | ||
struct SharedSchemesRule { | ||
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 [.init("Shared scheme directory not found")] | ||
} | ||
|
||
let schemes = Set(try fileManager.contentsOfDirectory(atPath: sharedSchemesURL.path)) | ||
|
||
var violations = [Violation]() | ||
|
||
// check targets | ||
environment.project.pbxproj.enumerateBuildConfigurations { name, configList in | ||
let schemeName = name + ".xcscheme" | ||
|
||
if schemes.contains(schemeName) { | ||
return | ||
} | ||
|
||
violations.append(.init("No shared scheme found for \"\(name)\"")) | ||
} | ||
|
||
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,38 @@ | ||
import XCTest | ||
|
||
@testable import XCLinting | ||
import XcodeProj | ||
|
||
final class SharedSchemesRuleTests: XCTestCase { | ||
func testProjectWithSharedSchemes() 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 SharedSchemesRule().run(env) | ||
|
||
XCTAssertTrue(violations.isEmpty) | ||
} | ||
|
||
func testProjectWithMissingSharedSchemes() 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 SharedSchemesRule().run(env) | ||
|
||
XCTAssertFalse(violations.isEmpty) | ||
} | ||
} |