Skip to content

Commit dde8851

Browse files
authored
Avoid --test-bundle-path bug in unit-tests. (#182)
Executables used in unit tests are sometimes called with '--test-bundle-path' argument. We work around this by avoiding `@main` in those executables.
1 parent 5a5441e commit dde8851

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Sources/PIRGenerateDatabase/GenerateDatabase.swift renamed to Sources/PIRGenerateDatabase/main.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ enum ValueTypeArguments: String, CaseIterable, ExpressibleByArgument {
2424
case repeated
2525
}
2626

27+
// This executable is used in tests, which breaks `swift test -c release` when used with `@main`.
28+
// So we avoid using `@main` here.
2729
struct ValueSizeArguments: ExpressibleByArgument {
2830
let range: Range<Int>
2931

@@ -57,7 +59,6 @@ extension [UInt8] {
5759
}
5860
}
5961

60-
@main
6162
struct GenerateDatabaseCommand: ParsableCommand {
6263
static let configuration: CommandConfiguration = .init(
6364
commandName: "PIRGenerateDatabase", version: Version.current.description)
@@ -97,3 +98,5 @@ struct GenerateDatabaseCommand: ParsableCommand {
9798
try databaseRows.proto().save(to: outputDatabase)
9899
}
99100
}
101+
102+
GenerateDatabaseCommand.main()

Sources/PIRProcessDatabase/ProcessDatabase.swift renamed to Sources/PIRProcessDatabase/main.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ struct ResolvedArguments: CustomStringConvertible, Encodable {
334334
}
335335
}
336336

337-
@main
337+
// This executable is used in tests, which breaks `swift test -c release` when used with `@main`.
338+
// So we avoid using `@main` here.
338339
struct ProcessDatabase: AsyncParsableCommand {
339340
static let configuration: CommandConfiguration = .init(
340341
commandName: "PIRProcessDatabase", version: Version.current.description)
@@ -549,3 +550,5 @@ extension Duration {
549550
Double(components.seconds) * 1e3 + Double(components.attoseconds) * 1e-15
550551
}
551552
}
553+
554+
ProcessDatabase.main()

0 commit comments

Comments
 (0)