Skip to content

Commit 4365e8e

Browse files
authored
Merge pull request #64 from MxIris-Reverse-Engineering/feat/ci-snapshot-testing
CI snapshot testing: SymbolTestsCore-only per-category coverage
2 parents c7c2b3a + d725aa5 commit 4365e8e

83 files changed

Lines changed: 6033 additions & 28389 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/macOS.yml‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ on:
99
jobs:
1010
macos_test:
1111
name: Execute tests on macOS
12+
runs-on: ${{ matrix.os }}
1213
strategy:
1314
fail-fast: false
1415
matrix:
16+
# Apple Silicon runners only: MachOFileTests.preferredArchitecture == .arm64.
17+
# Adding an Intel runner would load a different arch slice and drift snapshots.
1518
os: [macos-15]
1619
xcode-version: ["16.3"]
17-
release: [2024]
18-
runs-on: ${{ matrix.os }}
1920
env:
2021
MACHO_SWIFT_SECTION_SILENT_TEST: 1
2122
GH_TOKEN: ${{ github.token }}
@@ -27,11 +28,43 @@ jobs:
2728
xcode-version: ${{ matrix.xcode-version }}
2829
- name: Swift version
2930
run: swift --version
31+
32+
- name: Resolve SPM dependencies
33+
run: swift package update
34+
35+
- name: Cache SymbolTests DerivedData
36+
uses: actions/cache@v4
37+
with:
38+
path: Tests/Projects/SymbolTests/DerivedData
39+
key: symboltests-${{ matrix.xcode-version }}-${{ hashFiles('Tests/Projects/SymbolTests/**/*.swift', 'Tests/Projects/SymbolTests/**/*.pbxproj') }}
40+
41+
- name: Build SymbolTestsCore fixture
42+
working-directory: ${{ github.workspace }}
43+
run: |
44+
set -o pipefail
45+
xcodebuild \
46+
-project Tests/Projects/SymbolTests/SymbolTests.xcodeproj \
47+
-scheme SymbolTestsCore \
48+
-configuration Release \
49+
-derivedDataPath Tests/Projects/SymbolTests/DerivedData \
50+
-destination 'generic/platform=macOS' \
51+
-quiet \
52+
build
53+
54+
- name: Upload xcodebuild logs on failure
55+
if: failure()
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: symboltests-derived-data-logs
59+
path: Tests/Projects/SymbolTests/DerivedData/Logs
60+
if-no-files-found: ignore
61+
3062
- name: Build and run tests in debug mode
3163
run: |
3264
swift test \
3365
-c debug \
3466
--build-path .build-test-debug
67+
3568
- name: Build and run tests in release mode
3669
run: |
3770
swift test \

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Tests/__Snapshots__
1515
.claude
1616
.codex
1717
.opencode
18+
.worktrees/
1819
PrecompiledLibraries/swift-syntax/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
1920
.derived-data-log-*
2021
.package.env

‎README.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,33 @@ swift-section interface --uses-system-dyld-shared-cache --cache-image-name Swift
160160
swift-section interface --dyld-shared-cache --cache-image-path /path/to/cache /path/to/dyld_shared_cache
161161
```
162162

163+
## Running Tests
164+
165+
The snapshot tests in this repository rely on a fixture framework (`SymbolTestsCore`) built from an Xcode project in `Tests/Projects/SymbolTests/`. The framework binary is not checked in — rebuild it once after cloning:
166+
167+
```bash
168+
./Scripts/build-test-fixtures.sh
169+
```
170+
171+
Then run the tests:
172+
173+
```bash
174+
swift package update
175+
swift test
176+
```
177+
178+
Skipping the fixture build causes `MachOFileTests` to throw a "file not found" error at `Tests/Projects/SymbolTests/DerivedData/.../SymbolTestsCore` during test `init()`, before any assertions run.
179+
180+
To regenerate snapshots after a legitimate Swift-compiler / metadata change:
181+
182+
```bash
183+
SNAPSHOT_TESTING_RECORD=all swift test \
184+
--filter SymbolTestsCoreDumpSnapshotTests \
185+
--filter SymbolTestsCoreInterfaceSnapshotTests
186+
```
187+
188+
Commit the updated `__Snapshots__/` files alongside the source change that prompted the regeneration.
189+
163190
## License
164191

165192
[MachOObjCSection](https://github.com/p-x9/MachOObjCSection)

‎Scripts/build-test-fixtures.sh‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Builds the SymbolTestsCore fixture framework consumed by MachOSwiftSection's
4+
# snapshot tests. Run once after cloning, and again whenever
5+
# Tests/Projects/SymbolTests/SymbolTestsCore/**/*.swift (or the Xcode project
6+
# itself) changes. Output lands in Tests/Projects/SymbolTests/DerivedData/,
7+
# which is gitignored.
8+
#
9+
# If you skip this step, MachOFileTests.init() throws a "file not found" error
10+
# at the configured path under Tests/Projects/SymbolTests/DerivedData/…, and
11+
# every snapshot test aborts before asserting.
12+
13+
set -euo pipefail
14+
15+
# Resolve the script's own directory so the command works from any CWD.
16+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
18+
19+
cd "$REPO_ROOT"
20+
21+
xcodebuild \
22+
-project Tests/Projects/SymbolTests/SymbolTests.xcodeproj \
23+
-scheme SymbolTestsCore \
24+
-configuration Release \
25+
-derivedDataPath Tests/Projects/SymbolTests/DerivedData \
26+
-destination 'generic/platform=macOS' \
27+
-quiet \
28+
build
29+
30+
echo "SymbolTestsCore fixture built. Next: swift package update && swift test"

0 commit comments

Comments
 (0)