Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add UserDefaults tests #109

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/build-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ jobs:
- name: Install XCBeautify
run: brew install xcbeautify

- name: Test
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
145 changes: 143 additions & 2 deletions MiniSim.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
4AFACC752AD73D7900EC369F /* NSMenuItem+ConvenienceInit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMenuItem+ConvenienceInit.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -142,6 +153,8 @@
7684FAAE29D202F500230BB0 /* AndroidHomeError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AndroidHomeError.swift; sourceTree = "<group>"; };
768F8ECC2995575B00DFBCDB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
76AC9AF52A0EA82C00864A8B /* CustomCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCommands.swift; sourceTree = "<group>"; };
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 = "<group>"; };
76E4451129D4391000039025 /* Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Onboarding.swift; sourceTree = "<group>"; };
76E4451329D4403F00039025 /* NSNotificationName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSNotificationName.swift; sourceTree = "<group>"; };
76F04A10298A5AE000BF9CA3 /* ADB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ADB.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -169,6 +182,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
76B70F712B0D359D009D87A4 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
Expand Down Expand Up @@ -266,6 +286,7 @@
isa = PBXGroup;
children = (
766BD2322981628A0042261B /* MiniSim */,
76B70F752B0D359D009D87A4 /* MiniSimTests */,
766BD2312981628A0042261B /* Products */,
);
sourceTree = "<group>";
Expand All @@ -274,6 +295,7 @@
isa = PBXGroup;
children = (
766BD2302981628A0042261B /* MiniSim.app */,
76B70F742B0D359D009D87A4 /* MiniSimTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -330,6 +352,14 @@
path = Onboarding;
sourceTree = "<group>";
};
76B70F752B0D359D009D87A4 /* MiniSimTests */ = {
isa = PBXGroup;
children = (
76B70F7D2B0D361A009D87A4 /* UserDefaultsTests.swift */,
);
path = MiniSimTests;
sourceTree = "<group>";
};
76E5FAD1299BEBD2007987E0 /* MenuItems */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -390,19 +420,42 @@
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 = (
76B70F802B0D4F9D009D87A4 /* PBXTargetDependency */,
76B70F792B0D359D009D87A4 /* PBXTargetDependency */,
);
name = MiniSimTests;
productName = MiniSimTests;
productReference = 76B70F742B0D359D009D87A4 /* MiniSimTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
766BD2282981628A0042261B /* Project object */ = {
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" */;
Expand All @@ -429,6 +482,7 @@
projectRoot = "";
targets = (
766BD22F2981628A0042261B /* MiniSim */,
76B70F732B0D359D009D87A4 /* MiniSimTests */,
);
};
/* End PBXProject section */
Expand All @@ -445,6 +499,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
76B70F722B0D359D009D87A4 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
Expand Down Expand Up @@ -539,20 +600,38 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
76B70F702B0D359D009D87A4 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
76B70F7E2B0D361A009D87A4 /* UserDefaultsTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
4A78928A2AF1A9A3004D3FC8 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = 4A7892892AF1A9A3004D3FC8 /* SwiftLintPlugin */;
};
76B70F792B0D359D009D87A4 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 766BD22F2981628A0042261B /* MiniSim */;
targetProxy = 76B70F782B0D359D009D87A4 /* PBXContainerItemProxy */;
};
76B70F802B0D4F9D009D87A4 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = 76B70F7F2B0D4F9D009D87A4 /* SwiftLintPlugin */;
};
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
766BD23D2981628C0042261B /* Debug */ = {
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";
Expand Down Expand Up @@ -615,6 +694,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";
Expand Down Expand Up @@ -739,6 +819,53 @@
};
name = Release;
};
76B70F7A2B0D359E009D87A4 /* Debug */ = {
isa = XCBuildConfiguration;
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 = "";
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GENERATE_INFOPLIST_FILE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 13.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_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GENERATE_INFOPLIST_FILE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 13.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 */
Expand All @@ -760,6 +887,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 */
Expand Down Expand Up @@ -865,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" */;
Expand Down
13 changes: 12 additions & 1 deletion MiniSim.xcodeproj/xcshareddata/xcschemes/MiniSim.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -28,6 +28,17 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "76B70F732B0D359D009D87A4"
BuildableName = "MiniSimTests.xctest"
BlueprintName = "MiniSimTests"
ReferencedContainer = "container:MiniSim.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
62 changes: 62 additions & 0 deletions MiniSimTests/UserDefaultsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import XCTest

@testable import MiniSim

final class UserDefaultsTests: XCTestCase {
let savedParameters = UserDefaults.standard.parameters
let savedCommands = UserDefaults.standard.commands
let savedAndroidHome = UserDefaults.standard.androidHome
let savedIsOnboardingFinished = UserDefaults.standard.isOnboardingFinished
let savedEnableiOSSimulators = UserDefaults.standard.enableiOSSimulators
let savedEnableAndroidEmulators = UserDefaults.standard.enableAndroidEmulators

override func setUp() {
UserDefaults.standard.removeObject(forKey: UserDefaults.Keys.parameters)
UserDefaults.standard.removeObject(forKey: UserDefaults.Keys.commands)
UserDefaults.standard.removeObject(forKey: UserDefaults.Keys.androidHome)
UserDefaults.standard.removeObject(forKey: UserDefaults.Keys.isOnboardingFinished)
UserDefaults.standard.removeObject(forKey: UserDefaults.Keys.enableiOSSimulators)
UserDefaults.standard.removeObject(forKey: UserDefaults.Keys.enableAndroidEmulators)
}

override func tearDown() {
UserDefaults.standard.parameters = savedParameters
UserDefaults.standard.commands = savedCommands
UserDefaults.standard.androidHome = savedAndroidHome
UserDefaults.standard.isOnboardingFinished = savedIsOnboardingFinished
UserDefaults.standard.enableiOSSimulators = savedEnableiOSSimulators
UserDefaults.standard.enableAndroidEmulators = savedEnableAndroidEmulators
}

func testDefaultValues() {
XCTAssertEqual(UserDefaults.standard.parameters, nil)
XCTAssertEqual(UserDefaults.standard.commands, nil)
XCTAssertEqual(UserDefaults.standard.androidHome, nil)
XCTAssertEqual(UserDefaults.standard.isOnboardingFinished, false)
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)
XCTAssertEqual(UserDefaults.standard.androidHome, "test")
}
}
Loading