Skip to content

Commit 552d4ce

Browse files
authored
Integration: Add simple test filtering (#479)
Just does simple string contains logic
1 parent 26f3dcc commit 552d4ce

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

Sources/Integration/Suite.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ struct IntegrationSuite: AsyncParsableCommand {
154154
@Option(name: .shortAndLong, help: "Maximum number of concurrent tests")
155155
var maxConcurrency: Int = 4
156156

157+
@Option(name: .shortAndLong, help: "Only run tests whose names contain this string")
158+
var filter: String?
159+
157160
static func binPath(name: String) -> URL {
158161
URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
159162
.appendingPathComponent("bin")
@@ -339,11 +342,19 @@ struct IntegrationSuite: AsyncParsableCommand {
339342
Test("pod read-only rootfs DNS", testPodReadOnlyRootfsDNSConfigured),
340343
]
341344

345+
let filteredTests: [Test]
346+
if let filter {
347+
filteredTests = tests.filter { $0.name.contains(filter) }
348+
log.info("filter '\(filter)' matched \(filteredTests.count)/\(tests.count) tests")
349+
} else {
350+
filteredTests = tests
351+
}
352+
342353
let passed: Atomic<Int> = Atomic(0)
343354
let skipped: Atomic<Int> = Atomic(0)
344355

345356
await withTaskGroup(of: Void.self) { group in
346-
let jobQueue = JobQueue(tests)
357+
let jobQueue = JobQueue(filteredTests)
347358
for _ in 0..<maxConcurrency {
348359
group.addTask { @Sendable in
349360
while let job = jobQueue.pop() {
@@ -372,16 +383,16 @@ struct IntegrationSuite: AsyncParsableCommand {
372383
let skippedCount = skipped.load(ordering: .acquiring)
373384

374385
let ended = CFAbsoluteTimeGetCurrent() - suiteStarted
375-
var finishingText = "\n\nIntegration suite completed in \(ended)s with \(passedCount)/\(tests.count) passed"
386+
var finishingText = "\n\nIntegration suite completed in \(ended)s with \(passedCount)/\(filteredTests.count) passed"
376387
if skipped.load(ordering: .acquiring) > 0 {
377-
finishingText += " and \(skippedCount)/\(tests.count) skipped"
388+
finishingText += " and \(skippedCount)/\(filteredTests.count) skipped"
378389
}
379390
finishingText += "!"
380391

381392
log.info("\(finishingText)")
382393

383394
try? FileManager.default.removeItem(at: Self.testDir)
384-
if passedCount + skippedCount < tests.count {
395+
if passedCount + skippedCount < filteredTests.count {
385396
log.error("")
386397
throw ExitCode(1)
387398
}

0 commit comments

Comments
 (0)