Skip to content

Commit 7510c18

Browse files
committed
Support QuickSpec.current for SwiftPM builds as well on Darwin
1 parent 7e6b060 commit 7510c18

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

Quick.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@
237237
DAEB6B9A1943873100289F44 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAEB6B8E1943873100289F44 /* Quick.framework */; };
238238
DAF28BC31A4DB8EC00A5D9BF /* FocusedTests+ObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = DAF28BC21A4DB8EC00A5D9BF /* FocusedTests+ObjC.m */; };
239239
DAF28BC41A4DB8EC00A5D9BF /* FocusedTests+ObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = DAF28BC21A4DB8EC00A5D9BF /* FocusedTests+ObjC.m */; };
240-
DED3036B1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED3036A1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift */; };
241-
DED3036C1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED3036A1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift */; };
242-
DED3036D1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED3036A1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift */; };
240+
DED3036B1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED3036A1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift */; };
241+
DED3036C1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED3036A1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift */; };
242+
DED3036D1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED3036A1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift */; };
243243
DED3037D1DF6CF140041394E /* BundleModuleNameTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED3037C1DF6CF140041394E /* BundleModuleNameTests.swift */; };
244244
DED3037E1DF6CF140041394E /* BundleModuleNameTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED3037C1DF6CF140041394E /* BundleModuleNameTests.swift */; };
245245
DED3037F1DF6CF140041394E /* BundleModuleNameTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED3037C1DF6CF140041394E /* BundleModuleNameTests.swift */; };
@@ -553,7 +553,7 @@
553553
DAEB6B991943873100289F44 /* Quick - macOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Quick - macOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
554554
DAEB6B9F1943873100289F44 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
555555
DAF28BC21A4DB8EC00A5D9BF /* FocusedTests+ObjC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FocusedTests+ObjC.m"; sourceTree = "<group>"; };
556-
DED3036A1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSString+C99ExtendedIdentifier.swift"; sourceTree = "<group>"; };
556+
DED3036A1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+C99ExtendedIdentifier.swift"; sourceTree = "<group>"; };
557557
DED3037C1DF6CF140041394E /* BundleModuleNameTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BundleModuleNameTests.swift; sourceTree = "<group>"; };
558558
F8100E901A1E4447007595ED /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = BUILT_PRODUCTS_DIR; };
559559
/* End PBXFileReference section */
@@ -894,7 +894,7 @@
894894
CE57CEDA1C430BD200D63004 /* QuickTestSuite.swift */,
895895
CE57CED91C430BD200D63004 /* QuickSelectedTestSuiteBuilder.swift */,
896896
CE57CED81C430BD200D63004 /* NSBundle+CurrentTestBundle.swift */,
897-
DED3036A1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift */,
897+
DED3036A1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift */,
898898
CE57CEDB1C430BD200D63004 /* URL+FileName.swift */,
899899
34C586071C4AC5E500D4F057 /* ErrorUtility.swift */,
900900
DAEB6B911943873100289F44 /* Supporting Files */,
@@ -1428,7 +1428,7 @@
14281428
34C5860A1C4AC5E500D4F057 /* ErrorUtility.swift in Sources */,
14291429
1F118D041BDCA536005013A2 /* Example.swift in Sources */,
14301430
1F118CFF1BDCA536005013A2 /* QCKDSL.m in Sources */,
1431-
DED3036D1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift in Sources */,
1431+
DED3036D1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift in Sources */,
14321432
CE590E211C431FE400253D19 /* NSBundle+CurrentTestBundle.swift in Sources */,
14331433
1F118D071BDCA536005013A2 /* Callsite.swift in Sources */,
14341434
CE590E231C431FE400253D19 /* XCTestSuite+QuickTestSuiteBuilder.m in Sources */,
@@ -1510,7 +1510,7 @@
15101510
34C586091C4AC5E500D4F057 /* ErrorUtility.swift in Sources */,
15111511
DA408BE719FF5599005DF92A /* SuiteHooks.swift in Sources */,
15121512
34F375BA19515CA700CE1B99 /* QuickSpec.m in Sources */,
1513-
DED3036C1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift in Sources */,
1513+
DED3036C1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift in Sources */,
15141514
CE590E1C1C431FE300253D19 /* NSBundle+CurrentTestBundle.swift in Sources */,
15151515
DAE7150119FF6A62005905B8 /* QuickConfiguration.m in Sources */,
15161516
CE590E1E1C431FE300253D19 /* XCTestSuite+QuickTestSuiteBuilder.m in Sources */,
@@ -1632,7 +1632,7 @@
16321632
DA02C91919A8073100093156 /* ExampleMetadata.swift in Sources */,
16331633
CE57CEDF1C430BD200D63004 /* QuickTestSuite.swift in Sources */,
16341634
34C586081C4AC5E500D4F057 /* ErrorUtility.swift in Sources */,
1635-
DED3036B1DF6C66B0041394E /* NSString+C99ExtendedIdentifier.swift in Sources */,
1635+
DED3036B1DF6C66B0041394E /* String+C99ExtendedIdentifier.swift in Sources */,
16361636
DA408BE619FF5599005DF92A /* SuiteHooks.swift in Sources */,
16371637
34F375B919515CA700CE1B99 /* QuickSpec.m in Sources */,
16381638
CE57CEE11C430BD200D63004 /* XCTestSuite+QuickTestSuiteBuilder.m in Sources */,

Sources/Quick/NSBundle+CurrentTestBundle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension Bundle {
1717
Module name has to be a valid "C99 extended identifier".
1818
*/
1919
internal var moduleName: String {
20-
let fileName = bundleURL.fileName as NSString
20+
let fileName = bundleURL.fileName
2121
return fileName.c99ExtendedIdentifier
2222
}
2323
}

Sources/Quick/QuickSpec.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import XCTest
55

66
#if SWIFT_PACKAGE
77

8-
#if canImport(Darwin)
8+
#if canImport(QuickSpecBase)
99
import QuickSpecBase
1010

1111
public typealias QuickSpecBase = _QuickSpecBase
@@ -14,6 +14,18 @@ public typealias QuickSpecBase = XCTestCase
1414
#endif
1515

1616
open class QuickSpec: QuickSpecBase {
17+
#if canImport(Darwin)
18+
/// Returns the currently executing spec. Use in specs that require XCTestCase
19+
/// methods, e.g. expectation(description:).
20+
public private(set) static var current: QuickSpec!
21+
22+
private var example: Example? {
23+
didSet {
24+
QuickSpec.current = self
25+
}
26+
}
27+
#endif
28+
1729
open func spec() {}
1830

1931
#if !canImport(Darwin)
@@ -72,12 +84,13 @@ open class QuickSpec: QuickSpecBase {
7284
}
7385

7486
private static func addInstanceMethod(for example: Example, classSelectorNames selectorNames : inout Set<String>) -> Selector {
75-
let block: @convention(block) (QuickSpec) -> Void = { _ in
87+
let block: @convention(block) (QuickSpec) -> Void = { spec in
88+
spec.example = example
7689
example.run()
7790
}
7891
let implementation = imp_implementationWithBlock(block as Any)
7992

80-
let originalName = example.name
93+
let originalName = example.name.c99ExtendedIdentifier
8194
var selectorName = originalName
8295
var i: UInt = 2
8396

Sources/Quick/NSString+C99ExtendedIdentifier.swift renamed to Sources/Quick/String+C99ExtendedIdentifier.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#if canImport(Darwin)
22
import Foundation
33

4-
extension NSString {
4+
extension String {
55
private static var invalidCharacters: CharacterSet = {
66
var invalidCharacters = CharacterSet()
77

@@ -21,11 +21,8 @@ extension NSString {
2121
return invalidCharacters
2222
}()
2323

24-
/// This API is not meant to be used outside Quick, so will be unavailable in
25-
/// a next major version.
26-
@objc(qck_c99ExtendedIdentifier)
27-
public var c99ExtendedIdentifier: String {
28-
let validComponents = components(separatedBy: NSString.invalidCharacters)
24+
internal var c99ExtendedIdentifier: String {
25+
let validComponents = components(separatedBy: String.invalidCharacters)
2926
let result = validComponents.joined(separator: "_")
3027

3128
return result.isEmpty ? "_" : result

Sources/QuickObjectiveC/QuickSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
/**
5151
Returns the currently executing spec. Use in specs that require XCTestCase
52-
methds, e.g. expectationWithDescription.
52+
methods, e.g. expectationWithDescription.
5353
*/
5454
@property (class, nonatomic, readonly) QuickSpec *current;
5555

Tests/QuickTests/QuickTests/FunctionalTests/CurrentSpecTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import Quick
22
import Nimble
3+
import Dispatch
34

4-
#if !SWIFT_PACKAGE
5+
#if canImport(Darwin)
56

67
class CurrentSpecTests: QuickSpec {
78
override func spec() {
89
it("returns the currently executing spec") {
9-
expect(QuickSpec.current?.name).to(match("currently_executing_spec"))
10+
expect(QuickSpec.current.name).to(match("currently_executing_spec"))
1011
}
1112

1213
let currentSpecDuringSpecSetup = QuickSpec.current

0 commit comments

Comments
 (0)