File: main.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (108 lines) | stat: -rw-r--r-- 7,812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// RUN: %{swiftc} %s -o %T/Asynchronous-Notifications
// RUN: %T/Asynchronous-Notifications > %t || true
// RUN: %{xctest_checker} %t %s

#if os(macOS)
    import SwiftXCTest
#else
    import XCTest
#endif

// CHECK: Test Suite 'All tests' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: Test Suite '.*\.xctest' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+

// CHECK: Test Suite 'NotificationExpectationsTestCase' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
class NotificationExpectationsTestCase: XCTestCase {
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithName_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithName_passes' passed \(\d+\.\d+ seconds\)
    func test_observeNotificationWithName_passes() {
        let notificationName = "notificationWithNameTest"
        expectation(forNotification: notificationName, object:nil)
        NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: nil)
        waitForExpectations(timeout: 0.0)
    }
    
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithName_standalone_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithName_standalone_passes' passed \(\d+\.\d+ seconds\)
    func test_observeNotificationWithName_standalone_passes() {
        let notificationName = Notification.Name(rawValue: "notificationWithNameTest")
        let notificationCenter = NotificationCenter()
        let expectation = XCTNSNotificationExpectation(name: notificationName, notificationCenter: notificationCenter)
        notificationCenter.post(name: notificationName, object: nil)
        wait(for: [expectation], timeout: 0.0)
    }

// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithNameAndObject_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithNameAndObject_passes' passed \(\d+\.\d+ seconds\)
    func test_observeNotificationWithNameAndObject_passes() {
        let notificationName = "notificationWithNameAndObjectTest"
        let dummyObject = NSObject()
        expectation(forNotification: notificationName, object:dummyObject)
        NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: dummyObject)
        waitForExpectations(timeout: 0.0)
    }
    
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithNameAndObject_standalone_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithNameAndObject_standalone_passes' passed \(\d+\.\d+ seconds\)
    func test_observeNotificationWithNameAndObject_standalone_passes() {
        let notificationName = Notification.Name(rawValue: "notificationWithNameAndObjectTest")
        let notificationCenter = NotificationCenter()
        let dummyObject = NSObject()
        let expectation = XCTNSNotificationExpectation(name: notificationName, object: dummyObject, notificationCenter: notificationCenter)
        notificationCenter.post(name: notificationName, object: dummyObject)
        wait(for: [expectation], timeout: 0.0)
    }

// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithNameAndObject_butExpectingNoObject_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithNameAndObject_butExpectingNoObject_passes' passed \(\d+\.\d+ seconds\)
    func test_observeNotificationWithNameAndObject_butExpectingNoObject_passes() {
        let notificationName = "notificationWithNameAndObject_expectNoObjectTest"
        let notificationCenter = NotificationCenter()
        expectation(forNotification: notificationName, object: nil, notificationCenter: notificationCenter)
        let dummyObject = NSObject()
        notificationCenter.post(name: Notification.Name(rawValue: notificationName), object: dummyObject)
        waitForExpectations(timeout: 0.0)
    }
    
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithIncorrectName_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: .*[/\\]Tests[/\\]Functional[/\\]Asynchronous[/\\]Notifications[/\\]Expectations[/\\]main.swift:[[@LINE+5]]: error: NotificationExpectationsTestCase.test_observeNotificationWithIncorrectName_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect notification 'expectedName' from any object
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithIncorrectName_fails' failed \(\d+\.\d+ seconds\)
    func test_observeNotificationWithIncorrectName_fails() {
        expectation(forNotification: "expectedName", object: nil)
        NotificationCenter.default.post(name: Notification.Name(rawValue: "actualName"), object: nil)
        waitForExpectations(timeout: 0.1)
    }
    
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithIncorrectObject_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: .*[/\\]Tests[/\\]Functional[/\\]Asynchronous[/\\]Notifications[/\\]Expectations[/\\]main.swift:[[@LINE+8]]: error: NotificationExpectationsTestCase.test_observeNotificationWithIncorrectObject_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect notification 'notificationWithIncorrectObjectTest' from dummyObject
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithIncorrectObject_fails' failed \(\d+\.\d+ seconds\)
    func test_observeNotificationWithIncorrectObject_fails() {
        let notificationName = Notification.Name(rawValue: "notificationWithIncorrectObjectTest")
        let dummyObject: NSString = "dummyObject"
        let anotherDummyObject = NSObject()
        let expectation = XCTNSNotificationExpectation(name: notificationName, object: dummyObject)
        NotificationCenter.default.post(name: notificationName, object:anotherDummyObject)
        wait(for: [expectation], timeout: 0.1)
    }

    static var allTests = {
        return [
                   ("test_observeNotificationWithName_passes", test_observeNotificationWithName_passes),
                   ("test_observeNotificationWithName_standalone_passes", test_observeNotificationWithName_standalone_passes),
                   ("test_observeNotificationWithNameAndObject_passes", test_observeNotificationWithNameAndObject_passes),
                   ("test_observeNotificationWithNameAndObject_standalone_passes", test_observeNotificationWithNameAndObject_standalone_passes),
                   ("test_observeNotificationWithNameAndObject_butExpectingNoObject_passes", test_observeNotificationWithNameAndObject_butExpectingNoObject_passes),
                   ("test_observeNotificationWithIncorrectName_fails", test_observeNotificationWithIncorrectName_fails),
                   ("test_observeNotificationWithIncorrectObject_fails", test_observeNotificationWithIncorrectObject_fails),
        ]
    }()
}
// CHECK: Test Suite 'NotificationExpectationsTestCase' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: \t Executed 7 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

XCTMain([testCase(NotificationExpectationsTestCase.allTests)])

// CHECK: Test Suite '.*\.xctest' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: \t Executed 7 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
// CHECK: Test Suite 'All tests' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: \t Executed 7 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds