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 unit tests and add CI jobs #467

Merged
merged 11 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
19 changes: 12 additions & 7 deletions .github/workflows/cocoapods-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,32 @@ name: CocoaPods Lint
on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: macos-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- platform: iOS
config: ''
config: ""
- platform: iOS
config: '--use-libraries'
config: "--use-libraries"
- platform: iOS
config: '--use-libraries --use-modular-headers'
config: "--use-libraries --use-modular-headers"
- platform: iOS
config: '--use-static-frameworks'
config: "--use-static-frameworks"
- platform: macOS
config: ''
config: ""
- platform: tvOS
config: ''
config: ""
- platform: watchOS
config: ''
config: ""
Comment on lines -14 to +31
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@GLinnik21 FYI: These changes are generated by VSCode auto-format-on-save. Hope you don't mind

steps:
- name: Checkout Code
uses: actions/checkout@v4
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run Unit Tests

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
unit-tests:
runs-on: macos-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
platform:
- iOS
- macOS
- watchOS
- tvOS
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Use Latest Stable Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable

- name: Run Unit Tests
uses: mxcl/xcodebuild@v2
with:
workspace: ".swiftpm/xcode/package.xcworkspace"
scheme: "KSCrash-Package"
platform: ${{ matrix.platform }}
18 changes: 18 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/KSCrash-Package.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
BlueprintName = "KSCrashFiltersTests"
ReferencedContainer = "container:">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "KSCrashReportFilterAlert_Tests">
</Test>
</SkippedTests>
</TestableReference>
<TestableReference
skipped = "NO">
Expand All @@ -125,6 +130,14 @@
BlueprintName = "KSCrashRecordingCoreTests"
ReferencedContainer = "container:">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "KSDebug_Tests">
</Test>
<Test
Identifier = "KSObjC_Tests">
</Test>
</SkippedTests>
</TestableReference>
<TestableReference
skipped = "NO">
Expand All @@ -135,6 +148,11 @@
BlueprintName = "KSCrashRecordingTests"
ReferencedContainer = "container:">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "KSCrashMonitor_AppState_Tests">
</Test>
</SkippedTests>
</TestableReference>
<TestableReference
skipped = "NO">
Expand Down
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ let package = Package(
"KSCrashRecording",
"KSCrashRecordingCore",
],
resources: [
.process("Resources"),
GLinnik21 marked this conversation as resolved.
Show resolved Hide resolved
],
cSettings: [
.headerSearchPath("../../Sources/KSCrashRecording"),
.headerSearchPath("../../Sources/KSCrashRecording/Monitors"),
Expand Down
19 changes: 17 additions & 2 deletions Sources/KSCrashRecording/Monitors/KSCrashMonitor_Signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,32 @@ static void addContextualInfoToEvent(struct KSCrash_MonitorContext* eventContext
}
}

#else

static void setEnabled(bool isEnabled)
{
// Not supported
}

static bool isEnabled(void)
{
return false;
}

static void addContextualInfoToEvent(struct KSCrash_MonitorContext* eventContext)
{
// Not supported
}

#endif

KSCrashMonitorAPI* kscm_signal_getAPI(void)
{
static KSCrashMonitorAPI api =
{
#if KSCRASH_HAS_SIGNAL
.setEnabled = setEnabled,
.isEnabled = isEnabled,
.addContextualInfoToEvent = addContextualInfoToEvent
#endif
};
return &api;
}
4 changes: 4 additions & 0 deletions Tests/KSCrashFiltersTests/KSCrashReportFilterAlert_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ - (void) testAlert
yesAnswer:@"YES"
noAnswer:@"NO"];

XCTestExpectation *expectation = [self expectationWithDescription:@"Filter completion"];
[filter filterReports:[NSArray array] onCompletion:^(__unused NSArray* filteredReports,
BOOL completed,
NSError* error)
{
XCTAssertTrue(completed, @"");
XCTAssertNil(error, @"");
[expectation fulfill];
}];

[self waitForExpectations:@[expectation] timeout:0.2];
}

@end
4 changes: 4 additions & 0 deletions Tests/KSCrashRecordingCoreTests/KSCPU_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@

#import <XCTest/XCTest.h>

#import "KSSystemCapabilities.h"
#import "KSCPU.h"
#import "KSMachineContext.h"
#import "TestThread.h"

#import <mach/mach.h>

#if KSCRASH_HAS_THREADS_API

@interface KSCPU_Tests : XCTestCase @end

Expand Down Expand Up @@ -97,3 +99,5 @@ - (void) testStackGrowDirection
}

@end

#endif
21 changes: 20 additions & 1 deletion Tests/KSCrashRecordingTests/KSCrashMonitor_Signal_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@

#import <XCTest/XCTest.h>

#import "KSSystemCapabilities.h"
#import "KSCrashMonitorContext.h"
#import "KSCrashMonitor_Signal.h"


@interface KSCrashMonitor_Signal_Tests : XCTestCase @end


@implementation KSCrashMonitor_Signal_Tests

#if KSCRASH_HAS_SIGNAL

- (void) testInstallAndRemove
{
KSCrashMonitorAPI* api = kscm_signal_getAPI();
Expand All @@ -61,4 +63,21 @@ - (void) testDoubleInstallAndRemove
XCTAssertFalse(api->isEnabled());
}

#else

- (void) testNoImplementation
{
KSCrashMonitorAPI* api = kscm_signal_getAPI();

KSCrash_MonitorContext context;
api->addContextualInfoToEvent(&context);

api->setEnabled(true);
XCTAssertFalse(api->isEnabled());
api->setEnabled(false);
XCTAssertFalse(api->isEnabled());
}

#endif

@end
8 changes: 7 additions & 1 deletion Tests/KSCrashRecordingTests/KSCrashReportFixer_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
#import <XCTest/XCTest.h>
#import "KSCrashReportFixer.h"

#ifdef SWIFTPM_MODULE_BUNDLE
#define KS_TEST_MODULE_BUNDLE SWIFTPM_MODULE_BUNDLE
#else
#define KS_TEST_MODULE_BUNDLE ([NSBundle bundleForClass:[self class]])
#endif

@interface KSCrashReportFixer_Tests : XCTestCase

@end
Expand All @@ -27,7 +33,7 @@ - (void)tearDown {

- (void)testLoadCrash
{
NSBundle* bundle = [NSBundle bundleForClass:[self class]];
NSBundle* bundle = KS_TEST_MODULE_BUNDLE;
NSString* rawPath = [bundle pathForResource:@"raw" ofType:@"json"];
NSData* rawData = [NSData dataWithContentsOfFile:rawPath];
char* fixedBytes = kscrf_fixupCrashReport(rawData.bytes);
Expand Down
Loading