Skip to content

Commit

Permalink
add package validation
Browse files Browse the repository at this point in the history
  • Loading branch information
yonaskolb committed Aug 13, 2019
1 parent e3b66f8 commit e4acc8d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/ProjectSpec/SpecValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ extension Project {
errors.append(.invalidSDKDependency(target: target.name, dependency: dependency.reference))
}
}
case .package:
if packages[dependency.reference] == nil {
errors.append(.invalidSwiftPackage(name: dependency.reference, target: target.name))
}
default: break
}
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/ProjectSpec/SpecValidationError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public struct SpecValidationError: Error, CustomStringConvertible {
case invalidTargetSchemeTest(target: String, testTarget: String)
case invalidSchemeTarget(scheme: String, target: String)
case invalidSchemeConfig(scheme: String, config: String)
case invalidSwiftPackage(name: String, target: String)
case invalidConfigFile(configFile: String, config: String)
case invalidBuildSettingConfig(String)
case invalidSettingsGroup(String)
Expand Down Expand Up @@ -61,6 +62,8 @@ public struct SpecValidationError: Error, CustomStringConvertible {
return "Invalid file group \(group.quoted)"
case let .invalidConfigFileConfig(config):
return "Config file has invalid config \(config.quoted)"
case let .invalidSwiftPackage(name, target):
return "Target \(target.quoted) has an invalid package dependency \(name.quoted)"
case let .missingConfigForTargetScheme(target, configType):
return "Target \(target.quoted) is missing a config of type \(configType.rawValue) to generate its scheme"
case let .missingDefaultConfig(name):
Expand Down
6 changes: 5 additions & 1 deletion Tests/XcodeGenKitTests/ProjectSpecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,18 @@ class ProjectSpecTests: XCTestCase {
settings: invalidSettings,
configFiles: ["invalidConfig": "invalidConfigFile"],
sources: ["invalidSource"],
dependencies: [Dependency(type: .target, reference: "invalidDependency")],
dependencies: [
Dependency(type: .target, reference: "invalidDependency"),
Dependency(type: .package(product: nil), reference: "invalidPackage")
],
preBuildScripts: [BuildScript(script: .path("invalidPreBuildScript"), name: "preBuildScript1")],
postCompileScripts: [BuildScript(script: .path("invalidPostCompileScript"))],
postBuildScripts: [BuildScript(script: .path("invalidPostBuildScript"))],
scheme: TargetScheme(testTargets: ["invalidTarget"])
)]

try expectValidationError(project, .invalidTargetDependency(target: "target1", dependency: "invalidDependency"))
try expectValidationError(project, .invalidSwiftPackage(name: "invalidPackage", target: "target1"))
try expectValidationError(project, .invalidTargetConfigFile(target: "target1", configFile: "invalidConfigFile", config: "invalidConfig"))
try expectValidationError(project, .invalidTargetSchemeTest(target: "target1", testTarget: "invalidTarget"))
try expectValidationError(project, .invalidTargetSource(target: "target1", source: "invalidSource"))
Expand Down

0 comments on commit e4acc8d

Please sign in to comment.