From 6821d7c1e89fab5324a00a8f716acef294ebc97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Tue, 21 Nov 2023 20:29:51 +0100 Subject: [PATCH 1/3] feat: add UserDefaults tests --- .github/workflows/build-app.yml | 3 + MiniSim.xcodeproj/project.pbxproj | 133 +++++++++++++++++- .../xcshareddata/xcschemes/MiniSim.xcscheme | 13 +- MiniSimTests/UserDefaultsTests.swift | 63 +++++++++ 4 files changed, 209 insertions(+), 3 deletions(-) create mode 100644 MiniSimTests/UserDefaultsTests.swift diff --git a/.github/workflows/build-app.yml b/.github/workflows/build-app.yml index f21d62a..5f8c79d 100644 --- a/.github/workflows/build-app.yml +++ b/.github/workflows/build-app.yml @@ -28,5 +28,8 @@ jobs: - name: Install XCBeautify run: brew install xcbeautify + - name: Test + run: set -o pipefail && xcodebuild test -scheme MiniSim -destination 'platform=macOS' -skipPackagePluginValidation build | xcbeautify + - name: Build run: set -o pipefail && xcodebuild -scheme MiniSim -destination 'platform=macOS' -skipPackagePluginValidation build | xcbeautify diff --git a/MiniSim.xcodeproj/project.pbxproj b/MiniSim.xcodeproj/project.pbxproj index 3e4913a..c3e5cbc 100644 --- a/MiniSim.xcodeproj/project.pbxproj +++ b/MiniSim.xcodeproj/project.pbxproj @@ -69,6 +69,7 @@ 768F8EC829954C8A00DFBCDB /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 768F8EC729954C8A00DFBCDB /* Sparkle */; }; 76AC9AF62A0EA82C00864A8B /* CustomCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76AC9AF52A0EA82C00864A8B /* CustomCommands.swift */; }; 76AC9AF92A0EB50800864A8B /* SymbolPicker in Frameworks */ = {isa = PBXBuildFile; productRef = 76AC9AF82A0EB50800864A8B /* SymbolPicker */; }; + 76B70F7E2B0D361A009D87A4 /* UserDefaultsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76B70F7D2B0D361A009D87A4 /* UserDefaultsTests.swift */; }; 76E4451229D4391000039025 /* Onboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76E4451129D4391000039025 /* Onboarding.swift */; }; 76E4451429D4403F00039025 /* NSNotificationName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76E4451329D4403F00039025 /* NSNotificationName.swift */; }; 76F04A11298A5AE000BF9CA3 /* ADB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F04A10298A5AE000BF9CA3 /* ADB.swift */; }; @@ -82,6 +83,16 @@ 76FCABAB29B390D5003BBF9A /* Collection+get.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FCABAA29B390D5003BBF9A /* Collection+get.swift */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 76B70F782B0D359D009D87A4 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 766BD2282981628A0042261B /* Project object */; + proxyType = 1; + remoteGlobalIDString = 766BD22F2981628A0042261B; + remoteInfo = MiniSim; + }; +/* End PBXContainerItemProxy section */ + /* Begin PBXFileReference section */ 4AFACC732AD730BE00EC369F /* SubMenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubMenuItem.swift; sourceTree = ""; }; 4AFACC752AD73D7900EC369F /* NSMenuItem+ConvenienceInit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMenuItem+ConvenienceInit.swift"; sourceTree = ""; }; @@ -142,6 +153,8 @@ 7684FAAE29D202F500230BB0 /* AndroidHomeError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AndroidHomeError.swift; sourceTree = ""; }; 768F8ECC2995575B00DFBCDB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 76AC9AF52A0EA82C00864A8B /* CustomCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCommands.swift; sourceTree = ""; }; + 76B70F742B0D359D009D87A4 /* MiniSimTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MiniSimTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 76B70F7D2B0D361A009D87A4 /* UserDefaultsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsTests.swift; sourceTree = ""; }; 76E4451129D4391000039025 /* Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Onboarding.swift; sourceTree = ""; }; 76E4451329D4403F00039025 /* NSNotificationName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSNotificationName.swift; sourceTree = ""; }; 76F04A10298A5AE000BF9CA3 /* ADB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ADB.swift; sourceTree = ""; }; @@ -169,6 +182,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 76B70F712B0D359D009D87A4 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -266,6 +286,7 @@ isa = PBXGroup; children = ( 766BD2322981628A0042261B /* MiniSim */, + 76B70F752B0D359D009D87A4 /* MiniSimTests */, 766BD2312981628A0042261B /* Products */, ); sourceTree = ""; @@ -274,6 +295,7 @@ isa = PBXGroup; children = ( 766BD2302981628A0042261B /* MiniSim.app */, + 76B70F742B0D359D009D87A4 /* MiniSimTests.xctest */, ); name = Products; sourceTree = ""; @@ -330,6 +352,14 @@ path = Onboarding; sourceTree = ""; }; + 76B70F752B0D359D009D87A4 /* MiniSimTests */ = { + isa = PBXGroup; + children = ( + 76B70F7D2B0D361A009D87A4 /* UserDefaultsTests.swift */, + ); + path = MiniSimTests; + sourceTree = ""; + }; 76E5FAD1299BEBD2007987E0 /* MenuItems */ = { isa = PBXGroup; children = ( @@ -390,6 +420,24 @@ productReference = 766BD2302981628A0042261B /* MiniSim.app */; productType = "com.apple.product-type.application"; }; + 76B70F732B0D359D009D87A4 /* MiniSimTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 76B70F7C2B0D359E009D87A4 /* Build configuration list for PBXNativeTarget "MiniSimTests" */; + buildPhases = ( + 76B70F702B0D359D009D87A4 /* Sources */, + 76B70F712B0D359D009D87A4 /* Frameworks */, + 76B70F722B0D359D009D87A4 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 76B70F792B0D359D009D87A4 /* PBXTargetDependency */, + ); + name = MiniSimTests; + productName = MiniSimTests; + productReference = 76B70F742B0D359D009D87A4 /* MiniSimTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -397,12 +445,16 @@ isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = 1; - LastSwiftUpdateCheck = 1400; - LastUpgradeCheck = 1420; + LastSwiftUpdateCheck = 1500; + LastUpgradeCheck = 1500; TargetAttributes = { 766BD22F2981628A0042261B = { CreatedOnToolsVersion = 14.0.1; }; + 76B70F732B0D359D009D87A4 = { + CreatedOnToolsVersion = 15.0.1; + TestTargetID = 766BD22F2981628A0042261B; + }; }; }; buildConfigurationList = 766BD22B2981628A0042261B /* Build configuration list for PBXProject "MiniSim" */; @@ -429,6 +481,7 @@ projectRoot = ""; targets = ( 766BD22F2981628A0042261B /* MiniSim */, + 76B70F732B0D359D009D87A4 /* MiniSimTests */, ); }; /* End PBXProject section */ @@ -445,6 +498,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 76B70F722B0D359D009D87A4 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -539,6 +599,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 76B70F702B0D359D009D87A4 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 76B70F7E2B0D361A009D87A4 /* UserDefaultsTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -546,6 +614,11 @@ isa = PBXTargetDependency; productRef = 4A7892892AF1A9A3004D3FC8 /* SwiftLintPlugin */; }; + 76B70F792B0D359D009D87A4 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 766BD22F2981628A0042261B /* MiniSim */; + targetProxy = 76B70F782B0D359D009D87A4 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -553,6 +626,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + 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"; @@ -615,6 +689,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + 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"; @@ -739,6 +814,51 @@ }; name = Release; }; + 76B70F7A2B0D359E009D87A4 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = Z3M9P6G4WY; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GENERATE_INFOPLIST_FILE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 14.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = pl.okwasniewski.MiniSimTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MiniSim.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/MiniSim"; + }; + name = Debug; + }; + 76B70F7B2B0D359E009D87A4 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = Z3M9P6G4WY; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GENERATE_INFOPLIST_FILE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 14.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = pl.okwasniewski.MiniSimTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MiniSim.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/MiniSim"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -760,6 +880,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 76B70F7C2B0D359E009D87A4 /* Build configuration list for PBXNativeTarget "MiniSimTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 76B70F7A2B0D359E009D87A4 /* Debug */, + 76B70F7B2B0D359E009D87A4 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ diff --git a/MiniSim.xcodeproj/xcshareddata/xcschemes/MiniSim.xcscheme b/MiniSim.xcodeproj/xcshareddata/xcschemes/MiniSim.xcscheme index a1cdeee..3ae36fe 100644 --- a/MiniSim.xcodeproj/xcshareddata/xcschemes/MiniSim.xcscheme +++ b/MiniSim.xcodeproj/xcshareddata/xcschemes/MiniSim.xcscheme @@ -1,6 +1,6 @@ + + + + Date: Tue, 21 Nov 2023 20:37:30 +0100 Subject: [PATCH 2/3] fix: test CI step --- .github/workflows/build-app.yml | 4 ++-- MiniSim.xcodeproj/project.pbxproj | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-app.yml b/.github/workflows/build-app.yml index 5f8c79d..a30856f 100644 --- a/.github/workflows/build-app.yml +++ b/.github/workflows/build-app.yml @@ -29,7 +29,7 @@ jobs: run: brew install xcbeautify - name: Test - run: set -o pipefail && xcodebuild test -scheme MiniSim -destination 'platform=macOS' -skipPackagePluginValidation build | xcbeautify + run: set -o pipefail && xcodebuild -scheme MiniSim -destination 'platform=macOS' -skipPackagePluginValidation test COMPILER_INDEX_STORE_ENABLE=NO | xcbeautify - name: Build - run: set -o pipefail && xcodebuild -scheme MiniSim -destination 'platform=macOS' -skipPackagePluginValidation build | xcbeautify + run: set -o pipefail && xcodebuild -scheme MiniSim -destination 'platform=macOS' -skipPackagePluginValidation build COMPILER_INDEX_STORE_ENABLE=NO | xcbeautify diff --git a/MiniSim.xcodeproj/project.pbxproj b/MiniSim.xcodeproj/project.pbxproj index c3e5cbc..e408789 100644 --- a/MiniSim.xcodeproj/project.pbxproj +++ b/MiniSim.xcodeproj/project.pbxproj @@ -819,14 +819,15 @@ buildSettings = { ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; BUNDLE_LOADER = "$(TEST_HOST)"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = Z3M9P6G4WY; + DEVELOPMENT_TEAM = ""; ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu17; GENERATE_INFOPLIST_FILE = YES; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; - MACOSX_DEPLOYMENT_TARGET = 14.0; + MACOSX_DEPLOYMENT_TARGET = 13.0; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = pl.okwasniewski.MiniSimTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -842,14 +843,15 @@ buildSettings = { ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; BUNDLE_LOADER = "$(TEST_HOST)"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = Z3M9P6G4WY; + DEVELOPMENT_TEAM = ""; ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu17; GENERATE_INFOPLIST_FILE = YES; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; - MACOSX_DEPLOYMENT_TARGET = 14.0; + MACOSX_DEPLOYMENT_TARGET = 13.0; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = pl.okwasniewski.MiniSimTests; PRODUCT_NAME = "$(TARGET_NAME)"; From 4b915d0e27df2f98761c96f41ef5f57038be4e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Tue, 21 Nov 2023 21:52:06 +0100 Subject: [PATCH 3/3] fix: adjust SwiftLint for UserDefaultsTests --- MiniSim.xcodeproj/project.pbxproj | 10 ++++++++++ MiniSimTests/UserDefaultsTests.swift | 11 +++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/MiniSim.xcodeproj/project.pbxproj b/MiniSim.xcodeproj/project.pbxproj index e408789..db5ed8b 100644 --- a/MiniSim.xcodeproj/project.pbxproj +++ b/MiniSim.xcodeproj/project.pbxproj @@ -431,6 +431,7 @@ buildRules = ( ); dependencies = ( + 76B70F802B0D4F9D009D87A4 /* PBXTargetDependency */, 76B70F792B0D359D009D87A4 /* PBXTargetDependency */, ); name = MiniSimTests; @@ -619,6 +620,10 @@ target = 766BD22F2981628A0042261B /* MiniSim */; targetProxy = 76B70F782B0D359D009D87A4 /* PBXContainerItemProxy */; }; + 76B70F802B0D4F9D009D87A4 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + productRef = 76B70F7F2B0D4F9D009D87A4 /* SwiftLintPlugin */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -996,6 +1001,11 @@ package = 76AC9AF72A0EB50800864A8B /* XCRemoteSwiftPackageReference "SymbolPicker" */; productName = SymbolPicker; }; + 76B70F7F2B0D4F9D009D87A4 /* SwiftLintPlugin */ = { + isa = XCSwiftPackageProductDependency; + package = 4A7892862AF1A767004D3FC8 /* XCRemoteSwiftPackageReference "SwiftLint" */; + productName = "plugin:SwiftLintPlugin"; + }; 76F04A13298A62CF00BF9CA3 /* ShellOut */ = { isa = XCSwiftPackageProductDependency; package = 76F04A12298A62CF00BF9CA3 /* XCRemoteSwiftPackageReference "ShellOut" */; diff --git a/MiniSimTests/UserDefaultsTests.swift b/MiniSimTests/UserDefaultsTests.swift index 7028ae7..33a4fcc 100644 --- a/MiniSimTests/UserDefaultsTests.swift +++ b/MiniSimTests/UserDefaultsTests.swift @@ -36,25 +36,24 @@ final class UserDefaultsTests: XCTestCase { XCTAssertEqual(UserDefaults.standard.enableiOSSimulators, true) XCTAssertEqual(UserDefaults.standard.enableAndroidEmulators, true) } - + func testChangingParameters() { let parameters: [Parameter] = [.init(title: "First", command: "adb reverse")] let data = try? JSONEncoder().encode(parameters) UserDefaults.standard.parameters = data - + let newParameters = UserDefaults.standard.parameters let decoded = try? JSONDecoder().decode([Parameter].self, from: newParameters!) - + XCTAssertEqual(parameters, decoded) } - + func testChanging() { UserDefaults.standard.isOnboardingFinished = true UserDefaults.standard.enableiOSSimulators = false UserDefaults.standard.enableAndroidEmulators = false UserDefaults.standard.androidHome = "test" - - + XCTAssertEqual(UserDefaults.standard.isOnboardingFinished, true) XCTAssertEqual(UserDefaults.standard.enableiOSSimulators, false) XCTAssertEqual(UserDefaults.standard.enableAndroidEmulators, false)