Skip to content

Commit 46dfd76

Browse files
committed
[test] Fix expectations in Concurrency/toplevel/main.swift
FileCheck was matching against its own CHECK lines in the diagnostic output here so the test always succeeded. Convert to using the diagnostic verifier now we have `-verify-additional-prefix`.
1 parent 31d5c20 commit 46dfd76

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

test/Concurrency/toplevel/Inputs/foo.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1-
// RUN: not %target-swift-frontend -enable-experimental-async-top-level -swift-version 6 -typecheck %s %S/Inputs/foo.swift 2>&1 | %FileCheck %s --check-prefixes='Swift6-CHECK,CHECK'
2-
// RUN: not %target-swift-frontend -enable-experimental-async-top-level -swift-version 5 -typecheck %s %S/Inputs/foo.swift 2>&1 | %FileCheck %s --check-prefixes='Swift5-CHECK,CHECK'
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file --leading-lines %s %t
33

4-
var a = 10
4+
// RUN: %target-swift-frontend -typecheck -verify %t/main.swift %t/foo.swift -enable-experimental-async-top-level -swift-version 6 -verify-additional-prefix swift6-
5+
// RUN: %target-swift-frontend -typecheck -verify %t/main.swift %t/foo.swift -enable-experimental-async-top-level -swift-version 5 -verify-additional-prefix swift5-
6+
7+
//--- foo.swift
8+
func foo() -> Int {
9+
// expected-swift6-note@-1 {{add '@MainActor' to make global function 'foo()' part of global actor 'MainActor'}}
10+
a + 10
11+
// expected-swift6-error@-1 {{main actor-isolated var 'a' can not be referenced from a nonisolated context}}
12+
}
13+
14+
//--- main.swift
15+
var a = 10 // expected-swift6-note 2{{var declared here}}
516

617
@MainActor
7-
var b = 14
8-
// CHECK: top-level code variables cannot have a global actor
18+
var b = 14 // expected-error {{top-level code variables cannot have a global actor}}
919

1020
func nonIsolatedSynchronous() {
21+
// expected-swift6-note@-1 {{add '@MainActor' to make global function 'nonIsolatedSynchronous()' part of global actor 'MainActor'}}
1122
print(a)
12-
// Swift6-CHECK: main actor-isolated var 'a' can not be referenced from a nonisolated context
13-
// Swift6-CHECK: add '@MainActor' to make global function 'nonIsolatedSynchronous()' part of global actor 'MainActor'
14-
15-
// Swift5-CHECK-NOT: main actor-isolated var 'a' can not be referenced from a nonisolated context
16-
// Swift5-CHECK-NOT: add '@MainActor' to make global function 'nonIsolatedSynchronous()' part of global actor 'MainActor'
23+
// expected-swift6-error@-1 {{main actor-isolated var 'a' can not be referenced from a nonisolated context}}
1724
}
1825

1926
func nonIsolatedAsync() async {
20-
print(a)
21-
// CHECK: expression is 'async' but is not marked with 'await'
22-
// CHECK: property access is 'async'
27+
print(a)
28+
// expected-swift6-error@-1 {{main actor-isolated var 'a' cannot be accessed from outside of the actor}}
29+
// expected-swift5-warning@-2 {{main actor-isolated var 'a' cannot be accessed from outside of the actor}}
2330
}
2431

2532
await nonIsolatedAsync()
2633

27-
// Swift6-CHECK: foo.swift{{.*}}main actor-isolated var 'a' can not be referenced from a nonisolated context
28-
// Swift6-CHECK-DAG: var declared here
29-
// Swift6-CHECK-DAG: add '@MainActor' to make global function 'foo()' part of global actor 'MainActor'
30-
31-
// Swift5-CHECK-NOT: foo.swift{{.*}}main actor-isolated var 'a' can not be referenced from a nonisolated context
32-
// Swift5-CHECK-NOT: var declared here
33-
// Swift5-CHECK-NOT: add '@MainActor' to make global function 'foo()' part of global actor 'MainActor'
34-
3534
@MainActor
3635
func isolated() {
37-
print(a)
36+
print(a)
3837
}
3938

4039
func asyncFun() async {
41-
await print(a)
40+
await print(a)
4241
}
4342

4443
await asyncFun()

0 commit comments

Comments
 (0)