Skip to content

Commit

Permalink
coverage on crash
Browse files Browse the repository at this point in the history
  • Loading branch information
qyang-nj committed Oct 19, 2023
1 parent 6409690 commit de832d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This repo is mostly my study notes about low level iOS.
* Testing
* [Behind the scenes: iOS Testing](./articles/iOSTesting.md)
* [Behind the scenes: Code Coverage](./articles/CodeCoverage.md)
* [Code Coverage on Test Crash](./articles/CodeCoverageOnTestCrash.md)
* [Archived] [XCTest](./xctest)
* Xcode
* [Behind the scenes: SwiftUI Previews](./articles/SwiftUIPreview.md)
Expand Down
4 changes: 4 additions & 0 deletions testing/code_coverage/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ class Tests: XCTestCase {
XCTAssert(foo.func1(a: 0) == 0)
XCTAssert(foo.func1(a: 2) == 1)
}

// func testForceCrash() {
// assertionFailure("Crash")
// }
}
6 changes: 5 additions & 1 deletion testing/code_coverage/build_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ xcrun clang -bundle -o $TEST_BINARY build/Test.o \
PROFRAW_FILE="/tmp/test.profraw"
PROFDATA_FILE="/tmp/test.profdata"

export SIMCTL_CHILD_LLVM_PROFILE_FILE="$PROFRAW_FILE"
# %c enables a mode in which profile counter updates are continuously synced to a file
export SIMCTL_CHILD_LLVM_PROFILE_FILE="$PROFRAW_FILE%c"

rm -f $PROFRAW_FILE $PROFDATA_FILE

# Don't exit if test fails
set +e
xcrun simctl spawn --arch=$ARCH --standalone "iPhone 14 Pro" \
"$PLATFORM_DIR/Developer/Library/Xcode/Agents/xctest" \
$PWD/build/Test.xctest
set -e

xcrun llvm-profdata merge -sparse "$PROFRAW_FILE" -o "$PROFDATA_FILE"

Expand Down

0 comments on commit de832d1

Please sign in to comment.