Skip to content

Commit cd53eae

Browse files
committed
More test tweaks
1 parent 3708575 commit cd53eae

7 files changed

Lines changed: 31 additions & 40 deletions

File tree

Tests/InterposeKitTests/ClassHookTests.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
@testable import InterposeKit
1+
import InterposeKit
22
import XCTest
33

44
fileprivate class ExampleClass: NSObject {
5+
@objc static dynamic func doSomethingStatic() {}
56
@objc dynamic func doSomething() {}
67
@objc dynamic var intValue: Int { 1 }
78
@objc dynamic var arrayValue: [String] { ["ExampleClass"] }
@@ -13,7 +14,11 @@ fileprivate class ExampleSubclass: ExampleClass {
1314
}
1415
}
1516

16-
final class ClassHookTests: InterposeKitTestCase {
17+
final class ClassHookTests: XCTestCase {
18+
19+
override func setUpWithError() throws {
20+
Interpose.isLoggingEnabled = true
21+
}
1722

1823
func testLifecycle_applyHook() throws {
1924
let hook = try Interpose.applyHook(
@@ -158,7 +163,7 @@ final class ClassHookTests: InterposeKitTestCase {
158163
XCTAssertEqual(object.arrayValue, ["ExampleClass", "ExampleSubclass"])
159164
}
160165

161-
func testValidationFailure_methodNotFound() throws {
166+
func testValidationFailure_methodNotFound_nonExistent() throws {
162167
XCTAssertThrowsError(
163168
try Interpose.prepareHook(
164169
on: ExampleClass.self,
@@ -175,6 +180,23 @@ final class ClassHookTests: InterposeKitTestCase {
175180
)
176181
}
177182

183+
func testValidationFailure_methodNotFound_classMethod() throws {
184+
XCTAssertThrowsError(
185+
try Interpose.prepareHook(
186+
on: ExampleClass.self,
187+
for: #selector(ExampleClass.doSomethingStatic),
188+
methodSignature: (@convention(c) (NSObject, Selector) -> Void).self,
189+
hookSignature: (@convention(block) (NSObject) -> Void).self
190+
) { hook in
191+
return { `self` in }
192+
},
193+
expected: InterposeError.methodNotFound(
194+
class: ExampleClass.self,
195+
selector: #selector(ExampleClass.doSomethingStatic)
196+
)
197+
)
198+
}
199+
178200
func testValidationFailure_methodNotDirectlyImplemented() throws {
179201
XCTAssertThrowsError(
180202
try Interpose.prepareHook(

Tests/InterposeKitTests/ToBePolished/ClassMethodInterposeTests.swift

Lines changed: 0 additions & 23 deletions
This file was deleted.

Tests/InterposeKitTests/ToBePolished/InterposeKitTestCase.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.

Tests/InterposeKitTests/ToBePolished/KVOTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Foundation
33
import XCTest
44

5-
final class KVOTests: InterposeKitTestCase {
5+
final class KVOTests: XCTestCase {
66

77
// Helper observer that wraps a token and removes it on deinit.
88
class TestClassObserver {

Tests/InterposeKitTests/ToBePolished/MultipleInterposing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import XCTest
33
@testable import InterposeKit
44

5-
final class MultipleInterposingTests: InterposeKitTestCase {
5+
final class MultipleInterposingTests: XCTestCase {
66

77
func testInterposeSingleObjectMultipleTimes() throws {
88
let testObj = TestClass()

Tests/InterposeKitTests/ToBePolished/ObjectInterposeTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import XCTest
33
@testable import InterposeKit
44

5-
final class ObjectInterposeTests: InterposeKitTestCase {
5+
final class ObjectInterposeTests: XCTestCase {
66

77
func testInterposeSingleObject() throws {
88
let testObj = TestClass()

Tests/InterposeKitTests/UtilitiesTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import XCTest
33

44
fileprivate class ExampleClass: NSObject {
5-
@objc dynamic var value = 0
5+
@objc dynamic var intValue: Int = 0
66
}
77

88
fileprivate class RealClass: NSObject {}
@@ -40,10 +40,10 @@ final class UtilitiesTests: XCTestCase {
4040
let object = ExampleClass()
4141
XCTAssertFalse(object_isKVOActive(object))
4242

43-
var token1: NSKeyValueObservation? = object.observe(\.value, options: []) { _, _ in }
43+
var token1: NSKeyValueObservation? = object.observe(\.intValue, options: []) { _, _ in }
4444
XCTAssertTrue(object_isKVOActive(object))
4545

46-
var token2: NSKeyValueObservation? = object.observe(\.value, options: []) { _, _ in }
46+
var token2: NSKeyValueObservation? = object.observe(\.intValue, options: []) { _, _ in }
4747
XCTAssertTrue(object_isKVOActive(object))
4848

4949
_ = token1

0 commit comments

Comments
 (0)