From 8fe5c0cd16370a5d877f4f1e565b8632280a47eb Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 6 Jan 2020 20:51:58 +0900 Subject: [PATCH] Validate project reference path --- Sources/ProjectSpec/SpecValidation.swift | 6 ++++++ Sources/ProjectSpec/SpecValidationError.swift | 3 +++ Tests/ProjectSpecTests/ProjectSpecTests.swift | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/Sources/ProjectSpec/SpecValidation.swift b/Sources/ProjectSpec/SpecValidation.swift index 920632a7..387afac2 100644 --- a/Sources/ProjectSpec/SpecValidation.swift +++ b/Sources/ProjectSpec/SpecValidation.swift @@ -178,6 +178,12 @@ extension Project { } } + for projectReference in projectReferences { + if !(basePath + projectReference.path).exists { + errors.append(.invalidProjectReferencePath(projectReference)) + } + } + for scheme in schemes { for buildTarget in scheme.build.targets { switch buildTarget.target.location { diff --git a/Sources/ProjectSpec/SpecValidationError.swift b/Sources/ProjectSpec/SpecValidationError.swift index 89daf124..64df979d 100644 --- a/Sources/ProjectSpec/SpecValidationError.swift +++ b/Sources/ProjectSpec/SpecValidationError.swift @@ -30,6 +30,7 @@ public struct SpecValidationError: Error, CustomStringConvertible { case missingDefaultConfig(configName: String) case invalidPerConfigSettings case invalidProjectReference(scheme: String, reference: String) + case invalidProjectReferencePath(ProjectReference) public var description: String { switch self { @@ -75,6 +76,8 @@ public struct SpecValidationError: Error, CustomStringConvertible { return "Settings that are for a specific config must go in \"configs\". \"base\" can be used for common settings" case let .invalidProjectReference(scheme, project): return "Scheme \(scheme.quoted) has invalid project reference \(project.quoted)" + case let .invalidProjectReferencePath(reference): + return "Project reference \(reference.name) has a project file path that doesn't exist \"\(reference.path)\"" } } } diff --git a/Tests/ProjectSpecTests/ProjectSpecTests.swift b/Tests/ProjectSpecTests/ProjectSpecTests.swift index eb80e2c1..d840b91f 100644 --- a/Tests/ProjectSpecTests/ProjectSpecTests.swift +++ b/Tests/ProjectSpecTests/ProjectSpecTests.swift @@ -226,6 +226,13 @@ class ProjectSpecTests: XCTestCase { try expectValidationError(project, .invalidProjectReference(scheme: "scheme1", reference: "invalidProjectRef")) } + $0.it("fails with invalid project reference path") { + var project = baseProject + let reference = ProjectReference(name: "InvalidProj", path: "invalid_path") + project.projectReferences = [reference] + try expectValidationError(project, .invalidProjectReferencePath(reference)) + } + $0.it("allows missing optional file") { var project = baseProject project.targets = [Target(