Skip to content

Commit

Permalink
test: make sure getSelectedText will not crash
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed Nov 9, 2024
1 parent 27551af commit e55735f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions EasydictSwiftTests/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2024 izual. All rights reserved.
//

import SelectedTextKit
import Testing
import Translation

Expand Down Expand Up @@ -62,3 +63,24 @@ import Translation
@Test func setAlertVolume() async throws {
try await AppleScriptTask.setAlertVolume(50)
}

@Test func testGetSelectedText() async {
// Run thousands of times to test crash.
for i in 0..<2000 {
print("test index: \(i)")
let selectedText = await (try? getSelectedText()) ?? ""
print("\(i) selectedText: \(selectedText)")
}
}

@Test func testConcurrentGetSelectedText() async throws {
await withTaskGroup(of: Void.self) { group in
for i in 0..<2000 {
group.addTask {
print("test index: \(i)")
let selectedText = (try? await getSelectedText()) ?? ""
print("\(i) selectedText: \(selectedText)")
}
}
}
}

0 comments on commit e55735f

Please sign in to comment.