Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tests compilation for watchOS #89

Merged
merged 4 commits into from
Nov 10, 2023
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
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build buildSdk buildExample format swiftLint swiftFormat test testOnSimulator lint bootstrap releaseCocoaPods
.PHONY: build buildSdk buildExample format swiftLint swiftFormat test testOniOSSimulator testOnMacSimulator lint bootstrap releaseCocoaPods

build: buildSdk buildExample

Expand All @@ -16,9 +16,12 @@ swiftLint:
swiftFormat:
swiftformat . --swiftversion 5.3

testOnSimulator:
testOniOSSimulator:
set -o pipefail && xcodebuild test -project PostHog.xcodeproj -scheme PostHog -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.0.1' | xcpretty

testOnMacSimulator:
set -o pipefail && xcodebuild test -project PostHog.xcodeproj -scheme PostHog -destination 'platform=macOS' | xcpretty

test:
swift test

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "PostHog",
platforms: [
.macOS(.v10_14), .iOS(.v13), .tvOS(.v13), .watchOS(.v6),
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even our testing targets are min. 10.15 already, so we cannot even test unless we change our testing infra, since it's very old, it's ok to drop it.

],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
2 changes: 1 addition & 1 deletion PostHog.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|

s.ios.deployment_target = '13.0'
s.tvos.deployment_target = '13.0'
s.osx.deployment_target = "10.14"
s.osx.deployment_target = "10.15"
s.watchos.deployment_target = "6.0"
s.swift_versions = "5.3"

Expand Down
257 changes: 231 additions & 26 deletions PostHog.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "699991842AFE1B37000DCB78"
BuildableName = "PostHogExampleMacOS.app"
BlueprintName = "PostHogExampleMacOS"
ReferencedContainer = "container:PostHog.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "699991842AFE1B37000DCB78"
BuildableName = "PostHogExampleMacOS.app"
BlueprintName = "PostHogExampleMacOS"
ReferencedContainer = "container:PostHog.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "699991842AFE1B37000DCB78"
BuildableName = "PostHogExampleMacOS.app"
BlueprintName = "PostHogExampleMacOS"
ReferencedContainer = "container:PostHog.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
9 changes: 7 additions & 2 deletions PostHog/PostHogQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ class PostHogQueue {
}

take(config.maxBatchSize) { payload in
self.eventHandler(payload)
if !payload.events.isEmpty {
self.eventHandler(payload)
} else {
// there's nothing to be sent
payload.completion(true)
}
}
}

Expand Down Expand Up @@ -199,7 +204,7 @@ class PostHogQueue {

completion(PostHogConsumerPayload(events: processing) { success in
hedgeLog("Completed!")
if success {
if success, items.count > 0 {
self.fileQueue.pop(items.count)
}

Expand Down
10 changes: 10 additions & 0 deletions PostHogExample/PostHogExample.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
18 changes: 18 additions & 0 deletions PostHogExampleMacOS/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Cocoa
import PostHog

class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_: Notification) {
let config = PostHogConfig(
apiKey: "_6SG-F7I1vCuZ-HdJL3VZQqjBlaSb1_20hDPwqMNnGI"
)
config.debug = true

PostHogSDK.shared.setup(config)
// PostHogSDK.shared.capture("Event from MacOS example!")
}

func applicationWillTerminate(_: Notification) {
// Insert code here to tear down your application
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions PostHogExampleMacOS/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
24 changes: 24 additions & 0 deletions PostHogExampleMacOS/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ContentView.swift
// PostHogExampleMacOS
//
// Created by Manoel Aranda Neto on 10.11.23.
//

import SwiftUI

struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
}
}

#Preview {
ContentView()
}
5 changes: 5 additions & 0 deletions PostHogExampleMacOS/PostHogExampleMacOS.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
19 changes: 19 additions & 0 deletions PostHogExampleMacOS/PostHogExampleMacOSApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// PostHogExampleMacOSApp.swift
// PostHogExampleMacOS
//
// Created by Manoel Aranda Neto on 10.11.23.
//

import SwiftUI

@main
struct PostHogExampleMacOSApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
18 changes: 11 additions & 7 deletions PostHogTests/PostHogContextTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import Quick

class PostHogContextTest: QuickSpec {
func getSut() -> PostHogContext {
var reachability: Reachability?
do {
reachability = try Reachability()
} catch {
// ignored
}
return PostHogContext(reachability)
#if !os(watchOS)
var reachability: Reachability?
do {
reachability = try Reachability()
} catch {
// ignored
}
return PostHogContext(reachability)
#else
return PostHogContext()
#endif
}

override func spec() {
Expand Down