Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let package = Package(
)

for target in package.targets {
target.swiftSettings = [
target.swiftSettings = (target.swiftSettings ?? []) + [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ImmutableWeakCaptures"),
.enableUpcomingFeature("InferIsolatedConformances"),
Expand Down
11 changes: 10 additions & 1 deletion Sources/Tests/SampleData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import Foundation


struct SampleData : Sendable {
static let sourceDirectoryEnvironmentVariable = "XC_PROJECT_FORMAT_TEST_PROJECT_SOURCE_DIR"

static var sourceDirectory: String? {
ProcessInfo.processInfo.environment[sourceDirectoryEnvironmentVariable]
}

static let sharedInstance = Result {
try SampleData()
}
Expand All @@ -32,11 +38,14 @@ struct SampleData : Sendable {
let records: [Record]
init(sourceDirectory: String) throws {
let paths = try FileManager.default.recursivelyFindFiles(matchingExtension: "xcproj", in: sourceDirectory)
guard !paths.isEmpty else {
throw NSError("No .xcproj files found in \(sourceDirectory.quoted)")
}
self.records = try paths.map(Record.init(path:))
}

init() throws {
try self.init(sourceDirectory: ProcessInfo.processInfo.environment["XC_PROJECT_FORMAT_TEST_PROJECT_SOURCE_DIR"].unwrap(orThrow: "Missing environment variable for \("XC_PROJECT_FORMAT_TEST_PROJECT_SOURCE_DIR".quoted)"))
try self.init(sourceDirectory: Self.sourceDirectory.unwrap(orThrow: "Missing environment variable for \(Self.sourceDirectoryEnvironmentVariable.quoted)"))
}
}

Expand Down
16 changes: 10 additions & 6 deletions Sources/Tests/TestPerformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ extension TimeInterval {
}
}

#if ENABLE_PERFORMANCE_TESTS
private let arePerformanceTestsEnabled = true
#else
private let arePerformanceTestsEnabled = false
#endif

@Suite(
.enabled(if: arePerformanceTestsEnabled, "Performance tests are only enabled in release builds."),
.enabled(if: SampleData.sourceDirectory != nil, "Set \(SampleData.sourceDirectoryEnvironmentVariable) to a directory of sample projects to run performance tests.")
)
struct TestPerformance {
func measureTransformingSampleProjectData<Result>(testName: String = #function, body: (SampleData.Record) throws -> Result) throws {
#if ENABLE_PERFORMANCE_TESTS
let sampleData = try SampleData.sharedInstance.get()
let testDurations = try Array(repetitions: 100) {
try measureDuration {
Expand All @@ -38,11 +47,6 @@ struct TestPerformance {
print(" mean: \(mean?.formattedSeconds() ?? "N/A")")
print(" median: \(median?.formattedSeconds() ?? "N/A")")
print(" total: \(total.formattedSeconds())")
#else
#if compiler(>=6.3)
try Test.cancel("Performance tests are only enabled in release builds.")
#endif
#endif
}

@Test func testAnyJSONSerializationInstantiationPerformance() throws {
Expand Down
Loading