Skip to content

Commit

Permalink
Bugsnag test stubs (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpgalligan authored Oct 31, 2021
1 parent 624df13 commit 62490b4
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 14 deletions.
17 changes: 17 additions & 0 deletions kermit-bugsnag-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# kermit-bugsnag-test

This is a stub library to use for testing if you are using `kermit-bugsnag` in your build and want to run Kotlin
tests. `kermit-bugsnag` defines the cinterop for Bugsnag, but does not provide the implementation. When you
build your final application, your final link will include Bugsnag definitions. That works if you don't run
Kotlin/Native tests. If you do, you'll get linker errors when those tests are being built.

To avoid those errors, include `kermit-bugsnag-test` in your Kotlin/Native test dependencies.

```kotlin
sourceSets["iosTest"].dependencies {
implementation("co.touchlab:kermit-bugsnag-test:x.y.z")
}
```

These stubs don't actually work, but they'll satisfy the linker so you can run your Kotlin build tests. When your
framework is built into an app, you'll need to supply the Bugsnag implementation.
75 changes: 75 additions & 0 deletions kermit-bugsnag-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2021 Touchlab
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

plugins {
kotlin("multiplatform")
id("co.touchlab.cklib")
}

kotlin {
macosX64()
macosArm64()
iosX64()
iosArm64()
iosArm32()
iosSimulatorArm64()
tvosArm64()
tvosSimulatorArm64()
tvosX64()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
watchosX86()
watchosX64()

sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
}
}

val commonTest by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-test-common")
implementation("org.jetbrains.kotlin:kotlin-test-annotations-common")
}
}

val darwinMain by creating
darwinMain.dependsOn(commonMain)

val darwinTest by creating
darwinTest.dependsOn(commonTest)

targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
val main by compilations.getting
main.defaultSourceSet.dependsOn(darwinMain)
val test by compilations.getting
test.defaultSourceSet.dependsOn(darwinTest)
}
}
}

cklib {
create("objcsample") {
language = co.touchlab.cklib.gradle.CompileToBitcode.Language.OBJC
compilerArgs.addAll(
listOf(
"-DKONAN_MI_MALLOC=1", "-DNS_FORMAT_ARGUMENT(A)=", "-D_Nullable_result=_Nullable"
)
)
}
}

apply(from = "../gradle/gradle-mvn-mpp-push.gradle")
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2021 Touchlab
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

package co.touchlab.kermit.crashlytics

class Dummy {
}
25 changes: 25 additions & 0 deletions kermit-bugsnag-test/src/objcsample/cpp/Bugsnag.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Created by Kevin Galligan on 10/30/21.
//

#import "Bugsnag.h"


@implementation Bugsnag
- (instancetype)init {
return nil;
}

+ (void)notify:(NSException *)exception {

}

+ (void)leaveBreadcrumbWithMessage:(NSString *)message {

}

+ (void)leaveBreadcrumbWithMessage:(NSString *)message metadata:(NSDictionary *)metadata andType:(BSGBreadcrumbType)type {

}

@end
116 changes: 116 additions & 0 deletions kermit-bugsnag-test/src/objcsample/headers/Bugsnag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// Bugsnag.h
//
// Created by Conrad Irwin on 2014-10-01.
//
// Copyright (c) 2014 Bugsnag, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall remain in place
// in this source code.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <Foundation/Foundation.h>

/**
* Types of breadcrumbs
*/
typedef NS_ENUM(NSUInteger, BSGBreadcrumbType) {
/**
* Any breadcrumb sent via Bugsnag.leaveBreadcrumb()
*/
BSGBreadcrumbTypeManual,
/**
* A call to Bugsnag.notify() (internal use only)
*/
BSGBreadcrumbTypeError,
/**
* A log message
*/
BSGBreadcrumbTypeLog,
/**
* A navigation action, such as pushing a view controller or dismissing an alert
*/
BSGBreadcrumbTypeNavigation,
/**
* A background process, such performing a database query
*/
BSGBreadcrumbTypeProcess,
/**
* A network request
*/
BSGBreadcrumbTypeRequest,
/**
* Change in application or view state
*/
BSGBreadcrumbTypeState,
/**
* A user event, such as authentication or control events
*/
BSGBreadcrumbTypeUser,
};

/**
* Static access to a Bugsnag Client, the easiest way to use Bugsnag in your app.
*/
@interface Bugsnag : NSObject// <BugsnagClassLevelMetadataStore>

/**
* All Bugsnag access is class-level. Prevent the creation of instances.
*/
- (instancetype _Nonnull )init NS_UNAVAILABLE NS_SWIFT_UNAVAILABLE("Use class methods to initialise Bugsnag.");

// =============================================================================
// MARK: - Notify
// =============================================================================

/**
* Send a custom or caught exception to Bugsnag.
*
* The exception will be sent to Bugsnag in the background allowing your
* app to continue running.
*
* @param exception The exception.
*/
+ (void)notify:(NSException *_Nonnull)exception;

// =============================================================================
// MARK: - Breadcrumbs
// =============================================================================

/**
* Leave a "breadcrumb" log message, representing an action that occurred
* in your app, to aid with debugging.
*
* @param message the log message to leave
*/
+ (void)leaveBreadcrumbWithMessage:(NSString *_Nonnull)message;

/**
* Leave a "breadcrumb" log message, representing an action that occurred
* in your app, to aid with debugging, along with additional metadata and
* a type.
*
* @param message The log message to leave.
* @param metadata Diagnostic data relating to the breadcrumb.
* Values should be serializable to JSON with NSJSONSerialization.
* @param type A BSGBreadcrumbTypeValue denoting the type of breadcrumb.
*/
+ (void)leaveBreadcrumbWithMessage:(NSString *_Nonnull)message
metadata:(NSDictionary *_Nullable)metadata
andType:(BSGBreadcrumbType)type
NS_SWIFT_NAME(leaveBreadcrumb(_:metadata:type:));
@end
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ actual class BugsnagLogWriter actual constructor(
private class BugsnagNSException(stackTrace: List<Long>, exceptionType: String, message: String) : NSException(name = exceptionType, reason = message, userInfo = null) {
private val _callStackReturnAddresses:List<NSNumber>
init {
_callStackReturnAddresses = stackTrace.map { it.convert<NSInteger>() as NSNumber }
_callStackReturnAddresses = stackTrace.map {
@Suppress("CAST_NEVER_SUCCEEDS")
it.convert<NSInteger>() as NSNumber
}
}

override fun callStackReturnAddresses(): List<*> {
Expand Down
2 changes: 1 addition & 1 deletion kermit-crashlytics-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ kotlin {
macosArm64()
iosX64()
iosArm64()
// iosArm32()
iosArm32()
iosSimulatorArm64()
tvosArm64()
tvosSimulatorArm64()
Expand Down
12 changes: 0 additions & 12 deletions kermit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,20 @@ kotlin {
testSourceSet.dependsOn(commonTest)
}

commonMain.dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
}

commonTest.dependencies {
implementation("org.jetbrains.kotlin:kotlin-test-common")
implementation("org.jetbrains.kotlin:kotlin-test-annotations-common")
implementation("co.touchlab:stately-collections:$STATELY_VERSION")
implementation("co.touchlab:testhelp:0.5.5")
}

androidMain.dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
}

androidTest.dependencies {
implementation("org.jetbrains.kotlin:kotlin-test")
implementation("org.jetbrains.kotlin:kotlin-test-junit")
implementation("androidx.test:runner:1.4.0")
implementation("org.robolectric:robolectric:4.5.1")
}

jvmMain.dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
}

jvmTest.dependencies {
implementation("org.jetbrains.kotlin:kotlin-test")
implementation("org.jetbrains.kotlin:kotlin-test-junit")
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ include(":kermit")
include(":kermit-crashlytics")
include(":kermit-crashlytics-test")
include(":kermit-bugsnag")
include(":kermit-bugsnag-test")

include(":kermit-gradle-plugin")
include(":kermit-ir-plugin")
Expand Down

0 comments on commit 62490b4

Please sign in to comment.