Skip to content

Instantly share code, notes, and snippets.

@tcamin
tcamin / create_lldb_project.sh
Created November 12, 2020 15:07
Create a Xcode project that builds lldb
cd /tmp
git clone https://github.com/llvm/llvm-project
cmake -B /tmp/llvm-project/llvm-build -G Ninja \
-C /tmp/llvm-project/lldb/cmake/caches/Apple-lldb-base.cmake \
-DLLVM_ENABLE_PROJECTS="clang;libcxx" \
-DLIBCXX_ENABLE_STATIC=YES \
llvm-project/llvm
ninja -C /tmp/llvm-project/llvm-build
import XCTest
class PushNotificationsUITests: XCTestCase {
func testInteractionWithPushNotificationByLooping() {
XCUIApplication().launch()
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
springboard.activate()
let predicate = NSPredicate(format: "label BEGINSWITH %@", "PUSHNOTIFICATION")
import UserNotifications
func applicationWillResignActive(_ application: UIApplication) {
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 2.0, repeats: false)
let content = UNMutableNotificationContent()
content.title = "title"
content.body = "body"
let notification = UNNotificationRequest(identifier: "com.company.app.push.test", content: content, trigger: trigger)
final class SBTFavoritesTrackingUITests_AnyDeviceAnyEnvironment: XCTestCase, SBTTestOnAnyDevice, SBTTestOnAnyEnvironment {
func testTracking_whenAddingFavoriteFromAdView_shouldTrackTheRightParameters() {
// ...
}
func testTracking_whenRemovingFavoriteFromAdView_shouldTrackTheRightParameters() {
// ...
}
func testTracking_whenAddingFavoriteFromListing_shouldTrackTheRightParameters() {
@objc protocol SBTTestOnAnyEnvironment {}
@objc protocol SBTTestOnNotProductionEnvironment {}
@objc protocol SBTTestOnRegressEnvironment {}
@objc protocol SBTTestOnAdHocEnvironment {}
@objc protocol SBTTestOnStageEnvironment {}
@objc protocol SBTTestOnProductionEnvironment {}
@objc protocol SBTTestOnPreProdEnvironment {}
@objc protocol SBTTestOnReleaseEnvironment {}
@objc protocol SBTTestOnAnyDevice {}
func testSignup_whenSentWithInvalidEmailMx_handlesServerSideFailure() {
stubSignUpError("ACCOUNT_SAVE:invalid-mx")
openSignUp()
enterRequiredFields()
sendForm()
expectEmailError(.invalidDomain, expectingAlert: true)
}
func setAutocompleteKeyWhenInListing() {
// Scenario
// A button (`Go to listing`) takes you to a listing that has a text field (`search_box`) that filters a set of results
// Changes to `search_box` are saved to user defaults in a key `listing_search_leyword`
app.launchTunnel()
// Inject listing's search keyword in user defaults
let searchKeyword = "A random keyword"
app.userDefaultsSetObject(expectedSearchKeyword, forKey: "listing_search_keyword")
func testLoginShowsWarningOnNetworkError() {
// Scenario: at launch a login form is presented to the user. When a network error (503) occurs on login a specific error message is shown to the user
app.launchTunnel() // an app property is added to XCTest classes (no need to instantiate one every time
// fill the initial login form
app.textFields["username"].clearAndEnterText("valid@domain.com")
app.secureTextFields["password"].clearAndEnterText("valid_password")
// enable stubbing for all requests matching "https://myservice.com/login"
app.stubRequests(matching: SBTRequestMatch.url("https://myservice.com/login"),
@tcamin
tcamin / AlignPreprocessorMacros.rb
Last active August 28, 2022 18:30
Objective-C preprocessor macros -> Other Swift Flags
require 'xcodeproj'
require 'digest/md5'
project_path = '<path to your project.xcproj>'
project_file = "#{project_path}/project.pbxproj"
project_file_hash = Digest::MD5.hexdigest(File.read(project_file))
project_lock_path = "/tmp/#{project_path}.lock"
# Cache xcode_proj last md5 to avoid unnecessary parsing
//: Playground
import Foundation
import XCTest
DispatchQueue.main.async {
// check that you're running playground in Swift 3.0 ;)
}
let thisIsPerformSelector = #selector(NSObject.perform(_:)) // performSelector