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

test: migrated from Quick & Nimble to use XCTest to remove dependency on third party packages #213

Merged
merged 5 commits into from
Jun 21, 2024
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
12 changes: 0 additions & 12 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ runs:
run: xcodebuild -version | tee .xcode-version
shell: bash

- id: restore-carthage-cache
name: Restore Carthage cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: Carthage
key: carthage-${{ inputs.platform }}-${{ hashFiles('Cartfile.resolved') }}-${{ hashFiles('.xcode-version') }}-v1

- name: Install dependencies
if: steps.restore-carthage-cache.outputs.cache-hit != 'true'
run: carthage bootstrap --platform ${{ inputs.platform }} --use-xcframeworks --no-use-binaries --cache-builds
shell: bash

- name: Run tests
uses: mxcl/xcodebuild@6e60022a0cbe8c89278be2dd1773a2f68e7c5c87
with:
Expand Down
5 changes: 1 addition & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@

## Environment setup

We use [Carthage](https://github.com/Carthage/Carthage) to manage SimpleKeychain's dependencies.

1. Clone this repository and enter its root directory.
2. Run `carthage bootstrap --use-xcframeworks` to fetch and build the dependencies.
3. Open `SimpleKeychain.xcodeproj` in Xcode.
2. Open `SimpleKeychain.xcodeproj` in Xcode.
2 changes: 0 additions & 2 deletions Cartfile.private

This file was deleted.

2 changes: 0 additions & 2 deletions Cartfile.resolved

This file was deleted.

7 changes: 0 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
// swift-tools-version:5.7

import PackageDescription

let package = Package(
name: "SimpleKeychain",
platforms: [.iOS(.v13), .macOS(.v11), .tvOS(.v13), .watchOS(.v7)],
products: [.library(name: "SimpleKeychain", targets: ["SimpleKeychain"])],
dependencies: [
.package(url: "https://github.com/Quick/Quick.git", .upToNextMajor(from: "7.0.0")),
.package(url: "https://github.com/Quick/Nimble.git", .upToNextMajor(from: "12.0.0")),
],
targets: [
.target(
name: "SimpleKeychain",
Expand All @@ -20,8 +15,6 @@ let package = Package(
name: "SimpleKeychainTests",
dependencies: [
"SimpleKeychain",
.product(name: "Quick", package: "Quick"),
.product(name: "Nimble", package: "Nimble"),
],
path: "SimpleKeychainTests",
exclude: ["Info.plist"])
Expand Down
62 changes: 0 additions & 62 deletions SimpleKeychain.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
5C737B34285AB9B100B4BB25 /* SimpleKeychainErrorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C737B2F285AB57A00B4BB25 /* SimpleKeychainErrorSpec.swift */; };
5C737B35285AB9B100B4BB25 /* SimpleKeychainErrorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C737B2F285AB57A00B4BB25 /* SimpleKeychainErrorSpec.swift */; };
5C737B36285AB9B100B4BB25 /* SimpleKeychainErrorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C737B2F285AB57A00B4BB25 /* SimpleKeychainErrorSpec.swift */; };
5C737B4F285ACC9F00B4BB25 /* Nimble.xcframework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5CE9CA1126FD42B0005A75FA /* Nimble.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
5C737B50285ACC9F00B4BB25 /* Quick.xcframework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5CE9CA1026FD42B0005A75FA /* Quick.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
5C840112285AFF7B00689C01 /* Accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C840111285AFF7B00689C01 /* Accessibility.swift */; };
5C840113285AFF7B00689C01 /* Accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C840111285AFF7B00689C01 /* Accessibility.swift */; };
5C840114285AFF7B00689C01 /* Accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C840111285AFF7B00689C01 /* Accessibility.swift */; };
Expand All @@ -32,16 +30,6 @@
5CDF405B2852D88C003840E6 /* SimpleKeychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CDF40592852D88C003840E6 /* SimpleKeychain.swift */; };
5CDF405C2852D88C003840E6 /* SimpleKeychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CDF40592852D88C003840E6 /* SimpleKeychain.swift */; };
5CDF405D2852D88C003840E6 /* SimpleKeychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CDF40592852D88C003840E6 /* SimpleKeychain.swift */; };
5CE9CA1226FD42B0005A75FA /* Quick.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CE9CA1026FD42B0005A75FA /* Quick.xcframework */; };
5CE9CA1326FD42B0005A75FA /* Nimble.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CE9CA1126FD42B0005A75FA /* Nimble.xcframework */; };
5CE9CA1626FD42F4005A75FA /* Nimble.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CE9CA1126FD42B0005A75FA /* Nimble.xcframework */; };
5CE9CA1726FD42F4005A75FA /* Quick.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CE9CA1026FD42B0005A75FA /* Quick.xcframework */; };
5CE9CA1826FD42FA005A75FA /* Nimble.xcframework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5CE9CA1126FD42B0005A75FA /* Nimble.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
5CE9CA1926FD42FA005A75FA /* Quick.xcframework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5CE9CA1026FD42B0005A75FA /* Quick.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
5CE9CA1A26FD430F005A75FA /* Nimble.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CE9CA1126FD42B0005A75FA /* Nimble.xcframework */; };
5CE9CA1B26FD430F005A75FA /* Quick.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CE9CA1026FD42B0005A75FA /* Quick.xcframework */; };
5CE9CA1C26FD4316005A75FA /* Nimble.xcframework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5CE9CA1126FD42B0005A75FA /* Nimble.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
5CE9CA1D26FD4316005A75FA /* Quick.xcframework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5CE9CA1026FD42B0005A75FA /* Quick.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
5CE9CA2126FD43F5005A75FA /* SimpleKeychain.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B108AB81EA637B100ED4DD2 /* SimpleKeychain.framework */; };
5CEB577B285BCE7E00A32A80 /* AccessibilitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CEB577A285BCE7E00A32A80 /* AccessibilitySpec.swift */; };
5CEB577C285BCE7E00A32A80 /* AccessibilitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CEB577A285BCE7E00A32A80 /* AccessibilitySpec.swift */; };
Expand Down Expand Up @@ -92,28 +80,6 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
5B062A3A1EA63F6100827E79 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
5CE9CA1C26FD4316005A75FA /* Nimble.xcframework in CopyFiles */,
5CE9CA1D26FD4316005A75FA /* Quick.xcframework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
5C737B4E285ACC9200B4BB25 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
5C737B4F285ACC9F00B4BB25 /* Nimble.xcframework in CopyFiles */,
5C737B50285ACC9F00B4BB25 /* Quick.xcframework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
5CAF69A826FE57A90045266B /* Copy Files */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -125,17 +91,6 @@
name = "Copy Files";
runOnlyForDeploymentPostprocessing = 0;
};
5F4D279C1BCEA6A7003C27B3 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
5CE9CA1826FD42FA005A75FA /* Nimble.xcframework in CopyFiles */,
5CE9CA1926FD42FA005A75FA /* Quick.xcframework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
Expand All @@ -155,8 +110,6 @@
5C737B2F285AB57A00B4BB25 /* SimpleKeychainErrorSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleKeychainErrorSpec.swift; sourceTree = "<group>"; };
5C840111285AFF7B00689C01 /* Accessibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Accessibility.swift; sourceTree = "<group>"; };
5CDF40592852D88C003840E6 /* SimpleKeychain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleKeychain.swift; sourceTree = "<group>"; };
5CE9CA1026FD42B0005A75FA /* Quick.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Quick.xcframework; path = Carthage/Build/Quick.xcframework; sourceTree = SOURCE_ROOT; };
5CE9CA1126FD42B0005A75FA /* Nimble.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Nimble.xcframework; path = Carthage/Build/Nimble.xcframework; sourceTree = SOURCE_ROOT; };
5CEB577A285BCE7E00A32A80 /* AccessibilitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilitySpec.swift; sourceTree = "<group>"; };
5F4D27651BCE995C003C27B3 /* SimpleKeychainSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleKeychainSpec.swift; sourceTree = "<group>"; };
5F4D277B1BCE99DF003C27B3 /* SimpleKeychainTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SimpleKeychainTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -177,8 +130,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5CE9CA1A26FD430F005A75FA /* Nimble.xcframework in Frameworks */,
5CE9CA1B26FD430F005A75FA /* Quick.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -208,17 +159,13 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5CE9CA1326FD42B0005A75FA /* Nimble.xcframework in Frameworks */,
5CE9CA1226FD42B0005A75FA /* Quick.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
5F4D278C1BCEA69E003C27B3 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5CE9CA1626FD42F4005A75FA /* Nimble.xcframework in Frameworks */,
5CE9CA1726FD42F4005A75FA /* Quick.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -264,8 +211,6 @@
5F51D71D1BCDC4D400613162 /* Frameworks */ = {
isa = PBXGroup;
children = (
5CE9CA1126FD42B0005A75FA /* Nimble.xcframework */,
5CE9CA1026FD42B0005A75FA /* Quick.xcframework */,
);
name = Frameworks;
path = SimpleKeychain;
Expand Down Expand Up @@ -398,7 +343,6 @@
5B0D47551EA63C74009FF1BF /* Sources */,
5B0D47561EA63C74009FF1BF /* Frameworks */,
5B0D47571EA63C74009FF1BF /* Resources */,
5B062A3A1EA63F6100827E79 /* CopyFiles */,
);
buildRules = (
);
Expand Down Expand Up @@ -473,7 +417,6 @@
5F4D27771BCE99DF003C27B3 /* Sources */,
5F4D27781BCE99DF003C27B3 /* Frameworks */,
5F4D27791BCE99DF003C27B3 /* Resources */,
5C737B4E285ACC9200B4BB25 /* CopyFiles */,
);
buildRules = (
);
Expand All @@ -493,7 +436,6 @@
5F4D278B1BCEA69E003C27B3 /* Sources */,
5F4D278C1BCEA69E003C27B3 /* Frameworks */,
5F4D278D1BCEA69E003C27B3 /* Resources */,
5F4D279C1BCEA6A7003C27B3 /* CopyFiles */,
);
buildRules = (
);
Expand Down Expand Up @@ -937,7 +879,6 @@
5B0D47621EA63C74009FF1BF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
Expand Down Expand Up @@ -965,7 +906,6 @@
5B0D47631EA63C74009FF1BF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
Expand Down Expand Up @@ -1171,7 +1111,6 @@
5F4D27831BCE99E0003C27B3 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
DEBUG_INFORMATION_FORMAT = dwarf;
INFOPLIST_FILE = SimpleKeychainTests/Info.plist;
Expand All @@ -1192,7 +1131,6 @@
5F4D27841BCE99E0003C27B3 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
INFOPLIST_FILE = SimpleKeychainTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Expand Down
127 changes: 58 additions & 69 deletions SimpleKeychainTests/AccessibilitySpec.swift
Original file line number Diff line number Diff line change
@@ -1,74 +1,63 @@
import Security
import Nimble
import Quick
import XCTest
import SimpleKeychain

class AccessibilitySpec: QuickSpec {
override class func spec() {
describe("raw representable") {
context("from raw value to case") {
it("should map kSecAttrAccessibleWhenUnlocked") {
let sut = Accessibility(rawValue: kSecAttrAccessibleWhenUnlocked)
expect(sut) == Accessibility.whenUnlocked
}

it("should map kSecAttrAccessibleWhenUnlockedThisDeviceOnly") {
let sut = Accessibility(rawValue: kSecAttrAccessibleWhenUnlockedThisDeviceOnly)
expect(sut) == Accessibility.whenUnlockedThisDeviceOnly
}

it("should map kSecAttrAccessibleAfterFirstUnlock") {
let sut = Accessibility(rawValue: kSecAttrAccessibleAfterFirstUnlock)
expect(sut) == Accessibility.afterFirstUnlock
}

it("should map kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly") {
let sut = Accessibility(rawValue: kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly)
expect(sut) == Accessibility.afterFirstUnlockThisDeviceOnly
}

it("should map kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly") {
let sut = Accessibility(rawValue: kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly)
expect(sut) == Accessibility.whenPasscodeSetThisDeviceOnly
}

it("should map unknown values") {
let sut = Accessibility(rawValue: "foo" as CFString)
expect(sut) == Accessibility.afterFirstUnlock
}
}

context("from case to raw value") {
it("should map whenUnlocked") {
let sut = Accessibility.whenUnlocked.rawValue as String
expect(sut) == (kSecAttrAccessibleWhenUnlocked as String)
}

it("should map whenUnlockedThisDeviceOnly") {
let sut = Accessibility.whenUnlockedThisDeviceOnly.rawValue as String
expect(sut) == (kSecAttrAccessibleWhenUnlockedThisDeviceOnly as String)
}

it("should map afterFirstUnlock") {
let sut = Accessibility.afterFirstUnlock.rawValue as String
expect(sut) == (kSecAttrAccessibleAfterFirstUnlock as String)
}

it("should map afterFirstUnlockThisDeviceOnly") {
let sut = Accessibility.afterFirstUnlockThisDeviceOnly.rawValue as String
expect(sut) == (kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly as String)
}

it("should map whenPasscodeSetThisDeviceOnly") {
let sut = Accessibility.whenPasscodeSetThisDeviceOnly.rawValue as String
expect(sut) == (kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly as String)
}

it("should map whenPasscodeSetThisDeviceOnly") {
let sut = Accessibility.whenPasscodeSetThisDeviceOnly.rawValue as String
expect(sut) == (kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly as String)
}
}
}
class AccessibilitySpec: XCTestCase {

// Test from raw value to case
func testKSecAttrAccessibleWhenUnlocked() {
let sut = Accessibility(rawValue: kSecAttrAccessibleWhenUnlocked)
XCTAssertEqual(sut, Accessibility.whenUnlocked)
}

func testKSecAttrAccessibleWhenUnlockedThisDeviceOnly() {
let sut = Accessibility(rawValue: kSecAttrAccessibleWhenUnlockedThisDeviceOnly)
XCTAssertEqual(sut, Accessibility.whenUnlockedThisDeviceOnly)
}

func testKSecAttrAccessibleAfterFirstUnlock() {
let sut = Accessibility(rawValue: kSecAttrAccessibleAfterFirstUnlock)
XCTAssertEqual(sut, Accessibility.afterFirstUnlock)
}

func testKSecAttrAccessibleAfterFirstUnlockThisDeviceOnly() {
let sut = Accessibility(rawValue: kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly)
XCTAssertEqual(sut, Accessibility.afterFirstUnlockThisDeviceOnly)
}

func testKSecAttrAccessibleWhenPasscodeSetThisDeviceOnly() {
let sut = Accessibility(rawValue: kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly)
XCTAssertEqual(sut, Accessibility.whenPasscodeSetThisDeviceOnly)
}

func testUnknownValues() {
let sut = Accessibility(rawValue: "foo" as CFString)
XCTAssertEqual(sut, Accessibility.afterFirstUnlock)
}

// Test from case to raw value
func testWhenUnlocked() {
let sut = Accessibility.whenUnlocked.rawValue as String
XCTAssertEqual(sut, kSecAttrAccessibleWhenUnlocked as String)
}

func testWhenUnlockedThisDeviceOnly() {
let sut = Accessibility.whenUnlockedThisDeviceOnly.rawValue as String
XCTAssertEqual(sut, kSecAttrAccessibleWhenUnlockedThisDeviceOnly as String)
}

func testAfterFirstUnlock() {
let sut = Accessibility.afterFirstUnlock.rawValue as String
XCTAssertEqual(sut, kSecAttrAccessibleAfterFirstUnlock as String)
}

func testAfterFirstUnlockThisDeviceOnly() {
let sut = Accessibility.afterFirstUnlockThisDeviceOnly.rawValue as String
XCTAssertEqual(sut, kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly as String)
}

func testWhenPasscodeSetThisDeviceOnly() {
let sut = Accessibility.whenPasscodeSetThisDeviceOnly.rawValue as String
XCTAssertEqual(sut, kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly as String)
}
}
Loading
Loading