Skip to content

Commit 46013a5

Browse files
committed
Tests: Fix and re-enable @_spi_available tests
The main issue was that the tests specified `-library-level=api` in `swift-frontend` invocations instead of `-library-level api`. The former seems to have no effect and therefore expected diagnostics were not being emitted. Additional clean up: - Make every test require `OS=macosx` for ease of local testing. - Avoid unnecessarily specifying target arches (this makes tests slow). - Add missing `FileCheck` invocation. - Add some missing test coverage. Resolves rdar://91325474
1 parent 55e9e28 commit 46013a5

File tree

5 files changed

+50
-40
lines changed

5 files changed

+50
-40
lines changed

test/ModuleInterface/spi-available.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -parse-as-library %s -emit-module -library-level=api -emit-module-path %t/Foo.swiftmodule -module-name Foo -emit-module-interface-path %t/Foo.swiftinterface -emit-private-module-interface-path %t/Foo.private.swiftinterface
2+
// RUN: %target-swift-emit-module-interfaces(%t/Foo.swiftinterface, %t/Foo.private.swiftinterface) -parse-as-library %s -library-level api
33

44
// RUN: %target-swift-frontend -compile-module-from-interface %t/Foo.swiftinterface -o %t/Foo.public.swiftmodule -module-name Foo
55
// RUN: %target-swift-frontend -compile-module-from-interface %t/Foo.private.swiftinterface -o %t/Foo.private.swiftmodule -module-name Foo
6+
// RUN: %FileCheck %s --check-prefix=CHECK-PUBLIC < %t/Foo.swiftinterface
7+
// RUN: %FileCheck %s --check-prefix=CHECK-PRIVATE < %t/Foo.private.swiftinterface
68

79
@_spi_available(macOS 10.10, tvOS 14.0, *)
810
@available(iOS 8.0, *)

test/Sema/spi-available-context.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
// REQUIRES: VENDOR=apple
21
// REQUIRES: OS=macosx
3-
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx11.9 -library-level api
2+
// RUN: %target-typecheck-verify-swift -library-level api
43

5-
@_spi_available(macOS 10.4, *)
4+
@_spi_available(macOS 10.10, *)
65
@available(iOS 8.0, *)
7-
public protocol Foo { }
6+
public protocol MacOSSPIProto {} // expected-note {{type declared here}}
87

9-
@_spi_available(macOS 10.4, *)
8+
@_spi_available(iOS 8.0, *)
9+
@available(macOS 10.10, *)
10+
public protocol iOSSPIProto {}
11+
12+
@_spi_available(macOS 10.10, *)
1013
@available(iOS 8.0, *)
1114
public class Bar {
12-
public var foo: Foo?
15+
public var macos: MacOSSPIProto?
16+
public var ios: iOSSPIProto?
17+
}
18+
19+
@available(macOS 10.10, iOS 8.0, *)
20+
public class Baz {
21+
public var macos: MacOSSPIProto? // expected-error {{cannot use protocol 'MacOSSPIProto' here; it is SPI}}
22+
public var ios: iOSSPIProto?
1323
}

test/Sema/spi-available-inline.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
// REQUIRES: VENDOR=apple
21
// REQUIRES: OS=macosx
3-
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx11.9 -library-level api
2+
// RUN: %target-typecheck-verify-swift -library-level api
43

5-
@_spi_available(macOS 10.4, *)
4+
@_spi_available(macOS 10.10, *)
65
@available(iOS 8.0, *)
76
public class MacOSSPIClass { public init() {} }
87

98
@_spi_available(iOS 8.0, *)
10-
@available(macOS 10.4, *)
9+
@available(macOS 10.10, *)
1110
public class iOSSPIClass { public init() {} }
1211

13-
@inlinable public func foo() { // expected-warning{{public declarations should have an availability attribute with an introduction version}}
12+
@available(macOS 10.10, iOS 8.0, *)
13+
@inlinable public func foo() {
1414
_ = MacOSSPIClass() // expected-error {{class 'MacOSSPIClass' cannot be used in an '@inlinable' function because it is SPI}}
1515
_ = iOSSPIClass()
1616
}

test/Sema/spi-available-local.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
// REQUIRES: OS=ios
2-
// REQUIRES: rdar91325474
3-
// RUN: %empty-directory(%t)
4-
// RUN: not %target-swift-frontend -target x86_64-apple-macosx11.9 -parse-as-library %s -typecheck -library-level=api >& %t/macos.txt
5-
// RUN: %FileCheck %s < %t/macos.txt
6-
7-
// RUN: %target-swift-frontend -target arm64-apple-ios13.0 -parse-as-library %s -typecheck -library-level=api
1+
// REQUIRES: OS=macosx
2+
// RUN: %target-typecheck-verify-swift -parse-as-library -library-level api
83

94
@_spi_available(macOS 10.10, *)
105
@available(iOS 8.0, *)
11-
public class SPIClass {}
6+
public class MacOSSPIClass {} // expected-note {{type declared here}}
7+
8+
@_spi_available(iOS 8.0, *)
9+
@available(macOS 10.10, *)
10+
public class iOSSPIClass {}
1211

13-
public func foo(_ c: SPIClass) {}
12+
@available(macOS 10.10, iOS 8.0, *)
13+
public class MacOSDerived: MacOSSPIClass {} // expected-error {{cannot use class 'MacOSSPIClass' here; it is SPI}}
1414

15-
// CHECK: cannot use class 'SPIClass' here; it is SPI
15+
@available(macOS 10.10, iOS 8.0, *)
16+
public class iOSDerived: iOSSPIClass {}
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
// REQUIRES: OS=ios
2-
// REQUIRES: rdar91325474
31
// RUN: %empty-directory(%t)
4-
// RUN: %empty-directory(%t/macos)
5-
// RUN: %empty-directory(%t/ios)
2+
// RUN: split-file %s %t
63

7-
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -parse-as-library %s -emit-module -library-level=api -emit-module-path %t/macos/Foo.swiftmodule -module-name Foo -DFoo
8-
// RUN: %target-swift-frontend -target arm64-apple-ios13.0 -parse-as-library %s -emit-module -library-level=api -emit-module-path %t/ios/Foo.swiftmodule -module-name Foo -DFoo
4+
// RUN: %target-swift-frontend -parse-as-library %t/Foo.swift -emit-module -library-level api -emit-module-path %t/Foo.swiftmodule -module-name Foo
5+
// RUN: %target-swift-frontend-typecheck -parse-as-library %t/Client.swift -verify -library-level api -I %t
96

10-
// RUN: not %target-swift-frontend -target x86_64-apple-macosx11.9 -parse-as-library %s -typecheck -library-level=api -I %t/macos >& %t/macos.txt
11-
// RUN: %FileCheck %s < %t/macos.txt
12-
13-
// RUN: %target-swift-frontend -target arm64-apple-ios13.0 -parse-as-library %s -typecheck -library-level=api -I %t/ios
14-
15-
#if Foo
7+
//--- Foo.swift
168

179
@_spi_available(macOS 10.10, *)
1810
@available(iOS 8.0, *)
19-
public class SPIClass {}
11+
public class MacOSSPIClass {}
2012

21-
#else
13+
@_spi_available(iOS 8.0, *)
14+
@available(macOS 10.10, *)
15+
public class iOSSPIClass {}
2216

23-
import Foo
24-
public func foo(_ c: SPIClass) {}
17+
//--- Client.swift
2518

26-
#endif
19+
import Foo
2720

28-
// CHECK: cannot use class 'SPIClass' here; it is an SPI imported from 'Foo'
21+
@available(macOS 10.10, iOS 8.0, *)
22+
public struct Foo {
23+
public var macos: MacOSSPIClass // expected-error {{cannot use class 'MacOSSPIClass' here; it is an SPI imported from 'Foo'}}
24+
public var ios: iOSSPIClass
25+
}

0 commit comments

Comments
 (0)