Skip to content

Commit 4b0f924

Browse files
committed
[PlaygroundSupport] De-duplicated much of the test files between macOS, iOS, and tvOS, and fixed the build for tests.
PlaygroundSupport and XCPlayground each had a lot of duplication in their test suites, when all that was different was UIView vs. NSView. This makes each test suite use a single file for the live view-related tests, and also renames the test files to be more functionality-based. This is in preparation to migrate the PlaygroundSupport project to Swift 4.2.
1 parent 0f54d26 commit 4b0f924

File tree

8 files changed

+91
-459
lines changed

8 files changed

+91
-459
lines changed

PlaygroundSupport/PlaygroundSupport.xcodeproj/project.pbxproj

Lines changed: 24 additions & 83 deletions
Large diffs are not rendered by default.
Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -13,62 +13,74 @@
1313
import XCTest
1414
import PlaygroundSupport
1515

16-
class PlaygroundTests_OSX: XCTestCase {
17-
16+
#if os(macOS)
17+
import AppKit
18+
19+
fileprivate typealias ViewType = NSView
20+
fileprivate typealias ViewControllerType = NSViewController
21+
#elseif os(iOS) || os(tvOS)
22+
import UIKit
23+
24+
fileprivate typealias ViewType = UIView
25+
fileprivate typealias ViewControllerType = UIViewController
26+
#endif
27+
28+
class LiveViewTests: XCTestCase {
29+
1830
override func setUp() {
1931
super.setUp()
2032
// Put setup code here. This method is called before the invocation of each test method in the class.
2133
}
22-
34+
2335
override func tearDown() {
2436
PlaygroundPage.current.liveView = nil
2537
super.tearDown()
2638
}
27-
39+
2840
func testLiveViewWithView() {
29-
let view = NSView()
30-
41+
let view = ViewType()
42+
3143
// Test setting to a view
3244
expectation(forNotification: "PlaygroundPageLiveViewDidChangeNotification", object: PlaygroundPage.current) { (notification) in
33-
guard let userInfoView = notification.userInfo?["PlaygroundPageLiveView"] as? NSView else { return false }
45+
guard let userInfoView = notification.userInfo?["PlaygroundPageLiveView"] as? ViewType else { return false }
3446
guard notification.userInfo?["PlaygroundPageLiveViewController"] == nil else { return false }
3547
XCTAssertEqual(userInfoView, view)
3648
return true
3749
}
3850
PlaygroundPage.current.liveView = view
39-
waitForExpectations(withTimeout: 0.1, handler: nil)
40-
51+
waitForExpectations(timeout: 0.1, handler: nil)
52+
4153
// Test setting back to nil
4254
expectation(forNotification: "PlaygroundPageLiveViewDidChangeNotification", object: PlaygroundPage.current) { (notification) in
4355
guard notification.userInfo?["PlaygroundPageLiveView"] == nil else { return false }
4456
guard notification.userInfo?["PlaygroundPageLiveViewController"] == nil else { return false }
4557
return true
4658
}
4759
PlaygroundPage.current.liveView = nil
48-
waitForExpectations(withTimeout: 0.1, handler: nil)
60+
waitForExpectations(timeout: 0.1, handler: nil)
4961
}
50-
62+
5163
func testLiveViewWithViewController() {
52-
let viewController = NSViewController()
53-
64+
let viewController = ViewControllerType()
65+
5466
// Test setting to a view controller
5567
expectation(forNotification: "PlaygroundPageLiveViewDidChangeNotification", object: PlaygroundPage.current) { (notification) in
56-
guard let userInfoViewController = notification.userInfo?["PlaygroundPageLiveViewController"] as? NSViewController else { return false }
68+
guard let userInfoViewController = notification.userInfo?["PlaygroundPageLiveViewController"] as? ViewControllerType else { return false }
5769
guard notification.userInfo?["PlaygroundPageLiveView"] == nil else { return false }
5870
XCTAssertEqual(userInfoViewController, viewController)
5971
return true
6072
}
6173
PlaygroundPage.current.liveView = viewController
62-
waitForExpectations(withTimeout: 0.1, handler: nil)
63-
74+
waitForExpectations(timeout: 0.1, handler: nil)
75+
6476
// Test setting back to nil
6577
expectation(forNotification: "PlaygroundPageLiveViewDidChangeNotification", object: PlaygroundPage.current) { (notification) in
6678
guard notification.userInfo?["PlaygroundPageLiveView"] == nil else { return false }
6779
guard notification.userInfo?["PlaygroundPageLiveViewController"] == nil else { return false }
6880
return true
6981
}
7082
PlaygroundPage.current.liveView = nil
71-
waitForExpectations(withTimeout: 0.1, handler: nil)
83+
waitForExpectations(timeout: 0.1, handler: nil)
7284
}
73-
85+
7486
}

PlaygroundSupport/PlaygroundSupportTests/PlaygroundSupportTests_iOS/PlaygroundSupportTests_iOS.swift

Lines changed: 0 additions & 73 deletions
This file was deleted.

PlaygroundSupport/PlaygroundSupportTests/PlaygroundSupportTests_tvOS/PlaygroundSupportTests_tvOS.swift

Lines changed: 0 additions & 74 deletions
This file was deleted.

PlaygroundSupport/XCPlaygroundTests/XCPlaygroundCommonTests.swift renamed to PlaygroundSupport/XCPlaygroundTests/CaptureValueTests.swift

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -13,18 +13,8 @@
1313
import XCTest
1414
import XCPlayground
1515

16-
class XCPlaygroundCommonTests: XCTestCase {
17-
18-
// MARK:
19-
20-
/*
21-
func testFinishExecution() {
22-
expectation(forNotification: "XCPFinishExecution", object: XCPlaygroundPage.currentPage, handler: nil)
23-
XCPlaygroundPage.currentPage.finishExecution()
24-
waitForExpectationsWithTimeout(0.1, handler: nil)
25-
}
26-
*/
27-
16+
class CaptureValueTests: XCTestCase {
17+
2818
// MARK: Deprected XCPlaygroundPage
2919

3020
func testPlaygroundPageCaptureValue() {
@@ -40,7 +30,7 @@ class XCPlaygroundCommonTests: XCTestCase {
4030
return true
4131
}
4232
XCPlaygroundPage.currentPage.captureValue(value: value, withIdentifier: identifier)
43-
waitForExpectations(withTimeout: 0.1, handler: nil)
33+
waitForExpectations(timeout: 0.1, handler: nil)
4434
}
4535

4636
// MARK: Deprecated Functions
@@ -57,7 +47,7 @@ class XCPlaygroundCommonTests: XCTestCase {
5747
return true
5848
}
5949
XCPCaptureValue(identifier: identifier, value: value)
60-
waitForExpectations(withTimeout: 0.1, handler: nil)
50+
waitForExpectations(timeout: 0.1, handler: nil)
6151
}
6252

6353
func testXCPExecutionShouldContinueIndefinitely() {

0 commit comments

Comments
 (0)