Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ matrix:
env:
- PLATFORM=macos
- XCODE_ACTION="build-for-testing test-without-building"
- os: osx
osx_image: xcode9.3
env:
- PLATFORM=macos_static
- XCODE_ACTION="build-for-testing test-without-building"
- os: osx
env:
- PLATFORM=ios
Expand Down
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ namespace "test" do
run "xcodebuild -workspace Quick.xcworkspace -scheme Quick-macOS clean #{xcode_action}"
end

desc "Run unit tests for all macOS targets using static linking"
task :macos_static do |t|
run " MACH_O_TYPE=staticlib xcodebuild -workspace Quick.xcworkspace -scheme Quick-macOS clean #{xcode_action}"
end

desc "Run unit tests for the current platform built by the Swift Package Manager"
task :swiftpm do |t|
env = { "SWIFT_PACKAGE_TEST_Quick" => "true" }
Expand Down
22 changes: 19 additions & 3 deletions Sources/Quick/NSString+C99ExtendedIdentifier.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
import Foundation

public extension NSString {

extension NSString {
private static var invalidCharacters: CharacterSet = {
var invalidCharacters = CharacterSet()

Expand All @@ -22,12 +21,29 @@ public extension NSString {
return invalidCharacters
}()

/// This API is not meant to be used outside Quick, so will be unavaialbe in
/// a next major version.
@objc(qck_c99ExtendedIdentifier)
var c99ExtendedIdentifier: String {
public var c99ExtendedIdentifier: String {
let validComponents = components(separatedBy: NSString.invalidCharacters)
let result = validComponents.joined(separator: "_")

return result.isEmpty ? "_" : result
}
}

/// Extension methods or properties for NSObject subclasses are invisible from
/// the Objective-C runtime on static linking unless the consumers add `-ObjC`
/// linker flag, so let's make a wrapper class to mitigate that situation.
///
/// See: https://github.com/Quick/Quick/issues/785 and https://github.com/Quick/Quick/pull/803
@objc
class QCKObjCStringUtils: NSObject {
override private init() {}

@objc
static func c99ExtendedIdentifier(from string: String) -> String {
return string.c99ExtendedIdentifier
}
}
#endif
4 changes: 2 additions & 2 deletions Sources/QuickObjectiveC/QuickSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ + (SEL)addInstanceMethodForExample:(Example *)example classSelectorNames:(NSMuta
});

const char *types = [[NSString stringWithFormat:@"%s%s%s", @encode(void), @encode(id), @encode(SEL)] UTF8String];
NSString *originalName = example.name.qck_c99ExtendedIdentifier;

NSString *originalName = [QCKObjCStringUtils c99ExtendedIdentifierFrom:example.name];
NSString *selectorName = originalName;
NSUInteger i = 2;

Expand Down