Skip to content

Commit cb2ac41

Browse files
authored
Merge pull request #11 from ynechaev/remove-uikit-dependency
Remove UIKit dependency from test target.
2 parents 45e5143 + 75f623d commit cb2ac41

7 files changed

Lines changed: 121 additions & 40 deletions

File tree

.github/workflows/ios.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: XCode build & test
2+
3+
env:
4+
DEVELOPER_DIR: /Applications/Xcode_14.3.1.app/Contents/Developer
5+
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
pull_request:
10+
branches: [ "master" ]
11+
12+
jobs:
13+
build:
14+
name: Build and Test default scheme using any available iPhone simulator
15+
runs-on: macos-13
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
- name: Set Default Scheme
21+
run: |
22+
scheme_list=$(xcodebuild -list -json | tr -d "\n")
23+
default=$(echo $scheme_list | ruby -e "require 'json'; puts JSON.parse(STDIN.gets)['project']['targets'][0]")
24+
echo $default | cat >default
25+
echo Using default scheme: $default
26+
- name: Build
27+
env:
28+
scheme: ${{ 'default' }}
29+
platform: ${{ 'iOS Simulator' }}
30+
run: |
31+
# xcrun xctrace returns via stderr, not the expected stdout (see https://developer.apple.com/forums/thread/663959)
32+
device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"`
33+
if [ $scheme = default ]; then scheme=$(cat default); fi
34+
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
35+
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
36+
xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device"
37+
- name: Test
38+
env:
39+
scheme: ${{ 'default' }}
40+
platform: ${{ 'iOS Simulator' }}
41+
run: |
42+
# xcrun xctrace returns via stderr, not the expected stdout (see https://developer.apple.com/forums/thread/663959)
43+
device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"`
44+
if [ $scheme = default ]; then scheme=$(cat default); fi
45+
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
46+
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
47+
xcodebuild test-without-building -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device"
48+

.github/workflows/swift.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v3
2323
- name: Build
24-
run: swift build -v
25-
- name: Run tests
26-
run: swift test -v
24+
run: swift build -v -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios16.0-simulator"

ImageAsyncTest.xcodeproj/project.pbxproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@
163163
TargetAttributes = {
164164
062AC0021A0827E000744325 = {
165165
CreatedOnToolsVersion = 6.1;
166-
DevelopmentTeam = ZAUU33QHP4;
167166
LastSwiftMigration = 0800;
168167
ProvisioningStyle = Automatic;
169168
};
@@ -354,7 +353,7 @@
354353
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
355354
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
356355
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
357-
DEVELOPMENT_TEAM = ZAUU33QHP4;
356+
DEVELOPMENT_TEAM = "";
358357
INFOPLIST_FILE = "Demo/Supporting Files/Info.plist";
359358
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
360359
LD_RUNPATH_SEARCH_PATHS = (
@@ -374,7 +373,7 @@
374373
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
375374
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
376375
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
377-
DEVELOPMENT_TEAM = ZAUU33QHP4;
376+
DEVELOPMENT_TEAM = "";
378377
INFOPLIST_FILE = "Demo/Supporting Files/Info.plist";
379378
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
380379
LD_RUNPATH_SEARCH_PATHS = (

ImageAsyncTest.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,10 @@
4141
skipped = "NO">
4242
<BuildableReference
4343
BuildableIdentifier = "primary"
44-
BlueprintIdentifier = "0626EA661DB2316C000DC212"
45-
BuildableName = "YNImageAsyncTests.xctest"
44+
BlueprintIdentifier = "YNImageAsyncTests"
45+
BuildableName = "YNImageAsyncTests"
4646
BlueprintName = "YNImageAsyncTests"
47-
ReferencedContainer = "container:ImageAsyncTest.xcodeproj">
48-
</BuildableReference>
49-
</TestableReference>
50-
<TestableReference
51-
skipped = "NO">
52-
<BuildableReference
53-
BuildableIdentifier = "primary"
54-
BlueprintIdentifier = "062AC0171A0827E000744325"
55-
BuildableName = "ImageAsyncTestTests.xctest"
56-
BlueprintName = "ImageAsyncTestTests"
57-
ReferencedContainer = "container:ImageAsyncTest.xcodeproj">
47+
ReferencedContainer = "container:YNImageAsync">
5848
</BuildableReference>
5949
</TestableReference>
6050
</Testables>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1500"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
</BuildAction>
9+
<TestAction
10+
buildConfiguration = "Debug"
11+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
12+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13+
shouldUseLaunchSchemeArgsEnv = "YES"
14+
shouldAutocreateTestPlan = "YES">
15+
<Testables>
16+
<TestableReference
17+
skipped = "NO">
18+
<BuildableReference
19+
BuildableIdentifier = "primary"
20+
BlueprintIdentifier = "YNImageAsyncTests"
21+
BuildableName = "YNImageAsyncTests"
22+
BlueprintName = "YNImageAsyncTests"
23+
ReferencedContainer = "container:YNImageAsync">
24+
</BuildableReference>
25+
</TestableReference>
26+
</Testables>
27+
</TestAction>
28+
<LaunchAction
29+
buildConfiguration = "Debug"
30+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
31+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
32+
launchStyle = "0"
33+
useCustomWorkingDirectory = "NO"
34+
ignoresPersistentStateOnLaunch = "NO"
35+
debugDocumentVersioning = "YES"
36+
debugServiceExtension = "internal"
37+
allowLocationSimulation = "YES">
38+
</LaunchAction>
39+
<ProfileAction
40+
buildConfiguration = "Release"
41+
shouldUseLaunchSchemeArgsEnv = "YES"
42+
savedToolIdentifier = ""
43+
useCustomWorkingDirectory = "NO"
44+
debugDocumentVersioning = "YES">
45+
</ProfileAction>
46+
<AnalyzeAction
47+
buildConfiguration = "Debug">
48+
</AnalyzeAction>
49+
<ArchiveAction
50+
buildConfiguration = "Release"
51+
revealArchiveInOrganizer = "YES">
52+
</ArchiveAction>
53+
</Scheme>

YNImageAsync/Sources/YNImageAsync/YNImageAsync.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ extension StringProtocol {
243243

244244
extension FileManager {
245245
func clearDirectory(with url: URL) throws {
246-
let tmpDirectory = try contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
246+
guard let tmpDirectory = try? contentsOfDirectory(at: url, includingPropertiesForKeys: nil) else {
247+
return
248+
}
247249
try tmpDirectory.forEach { file in
248250
let fileUrl = url.appendingPathComponent(file.lastPathComponent)
249251
try removeItem(at: fileUrl)

YNImageAsync/Tests/YNImageAsyncTests/CacheComposerTests.swift

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
//
88

99
import XCTest
10-
import UIKit
1110
@testable import YNImageAsync
1211

1312
class CacheComposerTests: XCTestCase {
1413
static let cacheName = "CacheComposerTests"
15-
static let testImage = UIImage.build(with: CGSize(width: 1, height: 1), filledWithColor: .clear)!
14+
static let imageData = "image".data(using: .utf8)!
1615

1716
override func setUp() async throws {
1817
try FileManager.default.clearDirectory(with: DiskCacheProvider.cachePath)
@@ -27,8 +26,7 @@ class CacheComposerTests: XCTestCase {
2726
let memoryMock = CacheMock()
2827
let sut = CacheComposer(memoryCache: memoryMock, diskCache: nil)
2928

30-
let image = CacheComposerTests.testImage
31-
let imageData = image.jpegData(compressionQuality: 0.8)!
29+
let imageData = CacheComposerTests.imageData
3230
let url = URL(string: "http://example.com/mountains.jpg")!
3331

3432
// when
@@ -46,8 +44,7 @@ class CacheComposerTests: XCTestCase {
4644
let diskMock = CacheMock(storeThrottling: 1)
4745
let sut = CacheComposer(memoryCache: memoryMock, diskCache: diskMock)
4846

49-
let image = CacheComposerTests.testImage
50-
let imageData = image.jpegData(compressionQuality: 0.8)!
47+
let imageData = CacheComposerTests.imageData
5148
let url = URL(string: "http://example.com/mountains.jpg")!
5249

5350
// when
@@ -69,8 +66,7 @@ class CacheComposerTests: XCTestCase {
6966
let memoryMock = CacheMock()
7067
let sut = CacheComposer(memoryCache: memoryMock, diskCache: nil)
7168

72-
let image = CacheComposerTests.testImage
73-
let imageData = image.jpegData(compressionQuality: 0.8)!
69+
let imageData = CacheComposerTests.imageData
7470
let url = URL(string: "http://example.com/mountains.jpg")!
7571

7672
memoryMock.cache[url] = imageData
@@ -89,8 +85,7 @@ class CacheComposerTests: XCTestCase {
8985
let diskMock = CacheMock()
9086
let sut = CacheComposer(memoryCache: memoryMock, diskCache: diskMock)
9187

92-
let image = CacheComposerTests.testImage
93-
let imageData = image.jpegData(compressionQuality: 0.8)!
88+
let imageData = CacheComposerTests.imageData
9489
let url = URL(string: "http://example.com/mountains.jpg")!
9590

9691
diskMock.cache[url] = imageData
@@ -110,8 +105,7 @@ class CacheComposerTests: XCTestCase {
110105
let diskMock = CacheMock()
111106
let sut = CacheComposer(memoryCache: memoryMock, diskCache: diskMock)
112107

113-
let image = CacheComposerTests.testImage
114-
let imageData = image.jpegData(compressionQuality: 0.8)!
108+
let imageData = CacheComposerTests.imageData
115109
let url = URL(string: "http://example.com/mountains.jpg")!
116110

117111
memoryMock.cache[url] = imageData
@@ -130,8 +124,7 @@ class CacheComposerTests: XCTestCase {
130124
let memoryMock = CacheMock()
131125
let sut = CacheComposer(memoryCache: memoryMock, diskCache: nil)
132126

133-
let image = CacheComposerTests.testImage
134-
let imageData = image.jpegData(compressionQuality: 0.8)!
127+
let imageData = CacheComposerTests.imageData
135128
let url = URL(string: "http://example.com/mountains.jpg")!
136129

137130
memoryMock.cache[url] = imageData
@@ -140,7 +133,7 @@ class CacheComposerTests: XCTestCase {
140133
let size = try await sut.size()
141134

142135
// then
143-
XCTAssertEqual(size, 825)
136+
XCTAssertEqual(size, 5)
144137
XCTAssertEqual(memoryMock.sizeCalls, 1)
145138
}
146139

@@ -150,8 +143,7 @@ class CacheComposerTests: XCTestCase {
150143
let diskMock = CacheMock()
151144
let sut = CacheComposer(memoryCache: memoryMock, diskCache: diskMock)
152145

153-
let image = CacheComposerTests.testImage
154-
let imageData = image.jpegData(compressionQuality: 0.8)!
146+
let imageData = CacheComposerTests.imageData
155147
let url = URL(string: "http://example.com/mountains.jpg")!
156148

157149
memoryMock.cache[url] = imageData
@@ -161,7 +153,7 @@ class CacheComposerTests: XCTestCase {
161153
let size = try await sut.size()
162154

163155
// then
164-
XCTAssertEqual(size, 1650)
156+
XCTAssertEqual(size, 10)
165157
XCTAssertEqual(memoryMock.sizeCalls, 1)
166158
}
167159

@@ -171,8 +163,7 @@ class CacheComposerTests: XCTestCase {
171163
let diskMock = CacheMock()
172164
let sut = CacheComposer(memoryCache: memoryMock, diskCache: diskMock)
173165

174-
let image = CacheComposerTests.testImage
175-
let imageData = image.jpegData(compressionQuality: 0.8)!
166+
let imageData = CacheComposerTests.imageData
176167
let url = URL(string: "http://example.com/mountains.jpg")!
177168

178169
memoryMock.cache[url] = imageData

0 commit comments

Comments
 (0)