Use this guide before merging changes to metadata, parsing, formatting, geocoding, short-number behavior, or public APIs.
The Swift package includes both the stable Objective-C targets and the Swift-first facade target, so swift test is the baseline check for Swift and Objective-C package users.
Run the Swift Package Manager test suite:
swift testRun it with a non-English locale to catch locale-sensitive assumptions:
LC_ALL=ko_KR.UTF-8 LANG=ko_KR.UTF-8 swift testRun a release build:
swift build -c releaseCheck whitespace before committing:
git diff --checkCheck package and README version alignment:
swift scripts/checkVersionConsistency.swiftThe Swift facades are declared @unchecked Sendable on the strength of the
Objective-C core's internal locking, so the guarantee has to be exercised rather
than trusted. Run the suite under the thread sanitizer whenever you touch
mutable state in the Objective-C targets or add a facade entry point:
swift test --sanitize=threadThe concurrency suites live in libPhoneNumberSwiftCoreTests and in each
optional module's test target. They drive the shared instances from many tasks
at once; under the sanitizer an unguarded write is reported even when the
assertions still pass. CI runs this on every pull request.
swift test only covers macOS. Package.swift declares six platforms, so build
the package for each of the others before merging a packaging, linking, or
availability change:
for destination in \
'generic/platform=iOS' \
'generic/platform=tvOS' \
'generic/platform=watchOS' \
'generic/platform=visionOS' \
'platform=macOS,variant=Mac Catalyst'
do
xcodebuild build \
-workspace .swiftpm/xcode/package.xcworkspace \
-scheme libPhoneNumber-Package \
-destination "$destination" \
-derivedDataPath "/tmp/libphone-dd"
doneCI runs the same matrix on every pull request.
swift test --enable-code-coverage
xcrun llvm-cov report \
-instr-profile "$(dirname "$(swift test --show-codecov-path)")/default.profdata" \
"$(swift build --show-bin-path)/libPhoneNumberPackageTests.xctest/Contents/MacOS/libPhoneNumberPackageTests"Coverage is a review aid, not a merge gate. Use it to find untested branches in a module you changed, not to chase a number.
Run the upstream test parity check:
swift scripts/checkUpstreamTestParity.swiftRun the upstream API parity check:
swift scripts/checkUpstreamAPIParity.swiftWhen validating a specific Google libphonenumber version or commit, pin the ref:
swift scripts/checkUpstreamTestParity.swift --upstream-ref <version-or-commit>
swift scripts/checkUpstreamAPIParity.swift --upstream-ref <version-or-commit>See docs/UPSTREAM_PARITY.md for the full parity workflow.
Run the three main schemes on an iOS Simulator:
swift scripts/testXcodeSchemes.swiftIf the destination name is ambiguous or unavailable, list destinations and use a simulator UDID:
xcodebuild -scheme libPhoneNumber -showdestinations
swift scripts/testXcodeSchemes.swift --destination 'id=<simulator-udid>'Using a fresh -derivedDataPath is useful when code coverage files or stale derived data create noisy warnings:
swift scripts/testXcodeSchemes.swift \
--destination 'id=<simulator-udid>' \
--derived-data-root /tmp/libphone-xc-dd \
libPhoneNumberShortNumberFor a small implementation or test-only change:
swift testswift build -c releasegit diff --check
For metadata updates:
- Use a patch version for metadata-only releases. Use a minor version only when the change also adds public API, new modules, or additive behavior beyond metadata freshness.
swift scripts/checkMetadataFreshness.swift --output .build/metadata-freshnessswift scripts/updateMetadata.swift <metadata-ref> --dry-runswift scripts/checkUpstreamTestParity.swift --upstream-ref <metadata-ref>swift scripts/checkUpstreamAPIParity.swift --upstream-ref <metadata-ref>scripts/testGeocodingMetadataUpdater.shif the geocoding updater changed.- Update
docs/METADATA_UPDATE_LOG.mdwith the upstream comparison and validation results. swift testLC_ALL=ko_KR.UTF-8 LANG=ko_KR.UTF-8 swift testswift build -c releaseswift scripts/testXcodeSchemes.swiftgit diff --check
For public API or parser/formatter behavior changes:
swift scripts/checkUpstreamTestParity.swiftswift scripts/checkUpstreamAPIParity.swiftswift testLC_ALL=ko_KR.UTF-8 LANG=ko_KR.UTF-8 swift testswift build -c release- affected Xcode schemes, usually
libPhoneNumber git diff --check
For geocoding behavior changes:
swift testLC_ALL=ko_KR.UTF-8 LANG=ko_KR.UTF-8 swift testswift scripts/testXcodeSchemes.swift --destination 'id=<simulator-udid>' libPhoneNumberGeocodinggit diff --check
For short-number behavior changes:
swift testswift scripts/testXcodeSchemes.swift --destination 'id=<simulator-udid>' libPhoneNumberShortNumbergit diff --check
For Swift facade changes:
swift testLC_ALL=ko_KR.UTF-8 LANG=ko_KR.UTF-8 swift testswift test --sanitize=threadwhen the change touches shared state or adds a facade entry pointswift build -c releaseswift scripts/publishPodspecs.swift --lint- Confirm the facade remains a thin wrapper over the Objective-C core instead of duplicating phone-number logic.
- See the historical module split note in
docs/archive/SWIFT_FACADE_MODULE_SPLIT.mdbefore changing module boundaries.
For packaging changes:
swift scripts/checkVersionConsistency.swiftswift scripts/publishPodspecs.swift --lint- the per-platform build matrix above, since
swift testonly covers macOS
Do not assert user-preferred localized strings from convenience APIs unless the test controls locale. Prefer APIs that accept explicit language and region parameters when asserting exact geocoder descriptions.
At minimum, run:
LC_ALL=ko_KR.UTF-8 LANG=ko_KR.UTF-8 swift testThis catches tests that only pass on machines configured for English.
New tests use Swift Testing
(import Testing, @Suite, @Test, #expect). Both frameworks run under
swift test and each reports its own totals, so a green run shows two summary
lines.
The XCTest suites stay as they are. The Objective-C ones in particular mirror
upstream test names one for one, which is what makes
scripts/checkUpstreamTestParity.swift meaningful; converting them would break
that mapping for no benefit.
When porting an upstream JS test:
- Keep the local test name close to the upstream
test...function name. - Add the test to the matching XCTest file:
NBPhoneNumberUtilTest.mNBAsYouTypeFormatterTest.mNBShortNumberInfoTest.m
- Assert concrete behavior, not only that a call does not crash.
- If the ObjC behavior differs intentionally, document the reason in the test comment and PR.
- Re-run
swift scripts/checkUpstreamTestParity.swift. - Re-run
swift scripts/checkUpstreamAPIParity.swiftif the upstream public API surface changed.
Some Xcode test runs may print coverage or SQLite diagnostic messages even when tests pass. Treat them as warnings only after confirming:
xcodebuildexits with status0.- The output ends with
** TEST SUCCEEDED **. - The affected XCTest suite reports
0 failures.
If warnings are caused by reused derived data, rerun with a fresh -derivedDataPath.