diff --git a/Package.resolved b/Package.resolved index 5b6b82e..1210651 100644 --- a/Package.resolved +++ b/Package.resolved @@ -42,7 +42,7 @@ "location" : "https://github.com/mattmassicotte/XCConfig", "state" : { "branch" : "main", - "revision" : "26059718eab7a4fa723dd75cde45cf099d3e75a8" + "revision" : "ffe291c9237407f3f2695d10e567df63ad8b81fd" } }, { diff --git a/Sources/XCLinting/Extensions/PBXProj+BuildSettings.swift b/Sources/XCLinting/Extensions/PBXProj+BuildSettings.swift new file mode 100644 index 0000000..a0e0435 --- /dev/null +++ b/Sources/XCLinting/Extensions/PBXProj+BuildSettings.swift @@ -0,0 +1,19 @@ +import Foundation + +import XcodeProj + +extension PBXProj { + func enumerateBuildConfigurations(_ block: (String, XCConfigurationList) throws -> Void) rethrows { + for target in legacyTargets { + guard let list = target.buildConfigurationList else { continue } + + try block(target.name, list) + } + + for target in nativeTargets { + guard let list = target.buildConfigurationList else { continue } + + try block(target.name, list) + } + } +} diff --git a/Sources/XCLinting/Rules/ValidateBuildSettingsRule.swift b/Sources/XCLinting/Rules/ValidateBuildSettingsRule.swift new file mode 100644 index 0000000..e73b37e --- /dev/null +++ b/Sources/XCLinting/Rules/ValidateBuildSettingsRule.swift @@ -0,0 +1,48 @@ +import Foundation + +import XcodeProj +import XCConfig + +/// Detect build settings that are deprecated or no longer functional. +/// +/// This currently runs a superficial check. It does not perform configuration evaluation yet. +struct ValidateBuildSettingsRule { + func run(_ environment: XCLinter.Environment) throws -> [Violation] { + var violations = [Violation]() + + // check top-level + for config in environment.project.pbxproj.buildConfigurations { + violations.append(contentsOf: evaluateTargetSettings("Project", config: config)) + } + + // check targets + environment.project.pbxproj.enumerateBuildConfigurations { name, configList in + for config in configList.buildConfigurations { + violations.append(contentsOf: evaluateTargetSettings(name, config: config)) + } + } + + return violations + } + + func evaluateTargetSettings(_ name: String, config: XCBuildConfiguration) -> [Violation] { + var violations = [Violation]() + + for pair in config.buildSettings { + guard let setting = BuildSetting(rawValue: pair.key) else { continue } + + let status = setting.evaluateValue(pair.value as? String ?? "") + + switch status { + case .deprecated: + violations.append(.init("\(name):\(pair.key) = \(pair.value) is deprecated")) + case .invalid: + violations.append(.init("\(name):\(pair.key) = \(pair.value) is invalid")) + case .valid: + break + } + } + + return violations + } +} diff --git a/Sources/XCLinting/Violation.swift b/Sources/XCLinting/Violation.swift index c0ca956..38b76f4 100644 --- a/Sources/XCLinting/Violation.swift +++ b/Sources/XCLinting/Violation.swift @@ -1,9 +1,9 @@ import XcodeProj -public struct Violation { +public struct Violation: Hashable { public var message: String public var objects: [PBXObject] - + public init(_ message: String, objects: [PBXObject] = []) { self.message = message self.objects = objects diff --git a/Sources/XCLinting/XCLinter.swift b/Sources/XCLinting/XCLinter.swift index 76c4cbb..55d2c66 100644 --- a/Sources/XCLinting/XCLinter.swift +++ b/Sources/XCLinting/XCLinter.swift @@ -66,7 +66,8 @@ extension XCLinter.Environment { extension XCLinter { public static let defaultRuleIdentifiers: Set = [ - "build_files_ordered" + "build_files_ordered", + "validate_build_settings", ] public static let defaultRules: [Rule] = Array(ruleMap.filter({ defaultRuleIdentifiers.contains($0.0) }).values) @@ -76,5 +77,6 @@ extension XCLinter { "embedded_build_setting": embeddedBuildSettingsRule, "build_files_ordered": { try BuildFilesAreOrderedRule().run($0) }, "groups_sorted": groupsAreSortedRule, + "validate_build_settings": { try ValidateBuildSettingsRule().run($0) }, ] } diff --git a/Tests/XCLintTests/Bundle+TestData.swift b/Tests/XCLintTests/Bundle+TestData.swift new file mode 100644 index 0000000..add67ae --- /dev/null +++ b/Tests/XCLintTests/Bundle+TestData.swift @@ -0,0 +1,15 @@ +import Foundation +import XCTest + +extension Bundle { + func testDataURL(named: String) throws -> URL { + let bundle = Bundle.module + + let resourceURL = try XCTUnwrap(bundle.resourceURL) + + return resourceURL + .appendingPathComponent("TestData", isDirectory: true) + .appendingPathComponent(named) + .standardizedFileURL + } +} diff --git a/Tests/XCLintTests/EmbeddedBuildSettingsRuleTests.swift b/Tests/XCLintTests/EmbeddedBuildSettingsRuleTests.swift index 3120e6d..5ce0f2c 100644 --- a/Tests/XCLintTests/EmbeddedBuildSettingsRuleTests.swift +++ b/Tests/XCLintTests/EmbeddedBuildSettingsRuleTests.swift @@ -3,19 +3,6 @@ import XCTest @testable import XCLinting import XcodeProj -extension Bundle { - func testDataURL(named: String) throws -> URL { - let bundle = Bundle.module - - let resourceURL = try XCTUnwrap(bundle.resourceURL) - - return resourceURL - .appendingPathComponent("TestData", isDirectory: true) - .appendingPathComponent(named) - .standardizedFileURL - } -} - final class EmbeddedBuildSettingsRuleTests: XCTestCase { func testProjectWithBuildSettings() throws { let url = try Bundle.module.testDataURL(named: "StockMacOSApp.xcodeproj") diff --git a/Tests/XCLintTests/TestData/InvalidEmbeddedBuildSettings.xcodeproj/project.pbxproj b/Tests/XCLintTests/TestData/InvalidEmbeddedBuildSettings.xcodeproj/project.pbxproj new file mode 100644 index 0000000..1be28aa --- /dev/null +++ b/Tests/XCLintTests/TestData/InvalidEmbeddedBuildSettings.xcodeproj/project.pbxproj @@ -0,0 +1,346 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + C965BD2C2AE6E5D700E5836A /* StockMacOSAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C965BD2B2AE6E5D700E5836A /* StockMacOSAppApp.swift */; }; + C965BD2E2AE6E5D700E5836A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C965BD2D2AE6E5D700E5836A /* ContentView.swift */; }; + C965BD302AE6E5D800E5836A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C965BD2F2AE6E5D800E5836A /* Assets.xcassets */; }; + C965BD332AE6E5D800E5836A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C965BD322AE6E5D800E5836A /* Preview Assets.xcassets */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + C965BD282AE6E5D700E5836A /* StockMacOSApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StockMacOSApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; + C965BD2B2AE6E5D700E5836A /* StockMacOSAppApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StockMacOSAppApp.swift; sourceTree = ""; }; + C965BD2D2AE6E5D700E5836A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + C965BD2F2AE6E5D800E5836A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + C965BD322AE6E5D800E5836A /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + C965BD342AE6E5D800E5836A /* StockMacOSApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = StockMacOSApp.entitlements; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + C965BD252AE6E5D700E5836A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + C965BD1F2AE6E5D700E5836A = { + isa = PBXGroup; + children = ( + C965BD2A2AE6E5D700E5836A /* StockMacOSApp */, + C965BD292AE6E5D700E5836A /* Products */, + ); + sourceTree = ""; + }; + C965BD292AE6E5D700E5836A /* Products */ = { + isa = PBXGroup; + children = ( + C965BD282AE6E5D700E5836A /* StockMacOSApp.app */, + ); + name = Products; + sourceTree = ""; + }; + C965BD2A2AE6E5D700E5836A /* StockMacOSApp */ = { + isa = PBXGroup; + children = ( + C965BD2B2AE6E5D700E5836A /* StockMacOSAppApp.swift */, + C965BD2D2AE6E5D700E5836A /* ContentView.swift */, + C965BD2F2AE6E5D800E5836A /* Assets.xcassets */, + C965BD342AE6E5D800E5836A /* StockMacOSApp.entitlements */, + C965BD312AE6E5D800E5836A /* Preview Content */, + ); + path = StockMacOSApp; + sourceTree = ""; + }; + C965BD312AE6E5D800E5836A /* Preview Content */ = { + isa = PBXGroup; + children = ( + C965BD322AE6E5D800E5836A /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + C965BD272AE6E5D700E5836A /* StockMacOSApp */ = { + isa = PBXNativeTarget; + buildConfigurationList = C965BD372AE6E5D800E5836A /* Build configuration list for PBXNativeTarget "StockMacOSApp" */; + buildPhases = ( + C965BD242AE6E5D700E5836A /* Sources */, + C965BD252AE6E5D700E5836A /* Frameworks */, + C965BD262AE6E5D700E5836A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = StockMacOSApp; + productName = StockMacOSApp; + productReference = C965BD282AE6E5D700E5836A /* StockMacOSApp.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + C965BD202AE6E5D700E5836A /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1510; + LastUpgradeCheck = 1510; + TargetAttributes = { + C965BD272AE6E5D700E5836A = { + CreatedOnToolsVersion = 15.1; + }; + }; + }; + buildConfigurationList = C965BD232AE6E5D700E5836A /* Build configuration list for PBXProject "InvalidEmbeddedBuildSettings" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = C965BD1F2AE6E5D700E5836A; + productRefGroup = C965BD292AE6E5D700E5836A /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + C965BD272AE6E5D700E5836A /* StockMacOSApp */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + C965BD262AE6E5D700E5836A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C965BD332AE6E5D800E5836A /* Preview Assets.xcassets in Resources */, + C965BD302AE6E5D800E5836A /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + C965BD242AE6E5D700E5836A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C965BD2E2AE6E5D700E5836A /* ContentView.swift in Sources */, + C965BD2C2AE6E5D700E5836A /* StockMacOSAppApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + C965BD352AE6E5D800E5836A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = YES; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 14.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + C965BD362AE6E5D800E5836A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = YES; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 14.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + }; + name = Release; + }; + C965BD382AE6E5D800E5836A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = StockMacOSApp/StockMacOSApp.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"StockMacOSApp/Preview Content\""; + DEVELOPMENT_TEAM = 77X93NZ3G2; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = org.massicotte.StockMacOSApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + C965BD392AE6E5D800E5836A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = StockMacOSApp/StockMacOSApp.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"StockMacOSApp/Preview Content\""; + DEVELOPMENT_TEAM = 77X93NZ3G2; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = org.massicotte.StockMacOSApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + C965BD232AE6E5D700E5836A /* Build configuration list for PBXProject "InvalidEmbeddedBuildSettings" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C965BD352AE6E5D800E5836A /* Debug */, + C965BD362AE6E5D800E5836A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C965BD372AE6E5D800E5836A /* Build configuration list for PBXNativeTarget "StockMacOSApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C965BD382AE6E5D800E5836A /* Debug */, + C965BD392AE6E5D800E5836A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = C965BD202AE6E5D700E5836A /* Project object */; +} diff --git a/Tests/XCLintTests/ValidateBuildSettingsRuleTests.swift b/Tests/XCLintTests/ValidateBuildSettingsRuleTests.swift new file mode 100644 index 0000000..ae5ee47 --- /dev/null +++ b/Tests/XCLintTests/ValidateBuildSettingsRuleTests.swift @@ -0,0 +1,38 @@ +import XCTest + +@testable import XCLinting +import XcodeProj + +final class ValidateBuildSettingsRuleTests: XCTestCase { + func testProjectWithNoInvalidBuildSettings() 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 ValidateBuildSettingsRule().run(env) + + XCTAssertEqual(violations, []) + } + + func testProjectWithInvalidBuildSettings() throws { + let url = try Bundle.module.testDataURL(named: "InvalidEmbeddedBuildSettings.xcodeproj") + + let project = try XcodeProj(pathString: url.path) + + let env = XCLinter.Environment( + project: project, + projectRootURL: url, + configuration: Configuration() + ) + + let violations = try ValidateBuildSettingsRule().run(env) + + XCTAssertFalse(violations.isEmpty) + } +}