Memory.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // Memory.swift - Ensures that an allocated terminal is deallocated, this is
  3. // to make sure we do not regress when we use helper classes that might introduce
  4. // a strong cycle.
  5. //
  6. //
  7. // Created by Miguel de Icaza on 4/17/21.
  8. //
  9. import Foundation
  10. import XCTest
  11. @testable import SwiftTerm
  12. final class SwiftTermMemory: XCTestCase {
  13. static var deinited = false
  14. class SimpleTerminal: HeadlessTerminal {
  15. init (queue: DispatchQueue) {
  16. super.init (queue: queue, onEnd: { x in })
  17. }
  18. deinit {
  19. SwiftTermMemory.deinited = true
  20. }
  21. }
  22. func allocate (){
  23. let queue = DispatchQueue(label: "Runner", qos: .userInteractive, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil)
  24. let h = SimpleTerminal(queue: queue)
  25. //h.terminal.close ()
  26. let _ = h.terminal
  27. }
  28. // This test ensures that we are not keeping any strong references
  29. // in the code that would prevent the terminal from being released
  30. func testMemory ()
  31. {
  32. SwiftTermMemory.deinited = false
  33. allocate ()
  34. XCTAssertEqual(SwiftTermMemory.deinited, true)
  35. }
  36. static var allTests = [
  37. ("testMemory", testMemory),
  38. ]
  39. }