Skip to content

Commit 0a9b8fa

Browse files
author
Harlan Haskins
authored
Merge pull request #22191 from harlanhaskins/fatality
[Diagnostics] Mark invalid ‘@testable import’ as fatal
2 parents 283de9f + f4b0e0e commit 0a9b8fa

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ ERROR(imported_decl_is_wrong_kind_typealias,none,
761761
ERROR(ambiguous_decl_in_module,none,
762762
"ambiguous name %0 in module %1", (Identifier, Identifier))
763763

764-
ERROR(module_not_testable,none,
764+
ERROR(module_not_testable,Fatal,
765765
"module %0 was not compiled for testing", (Identifier))
766766

767767
ERROR(module_not_compiled_for_private_import,none,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t/single_int.swiftmodule %S/Inputs/single_int.swift
3+
// RUN: not %target-swift-frontend -typecheck %s -I %t 2>&1 | %FileCheck %s
4+
5+
@testable import single_int // CHECK: module 'single_int' was not compiled for testing
6+
7+
x = 8 // CHECK-NOT: unresolved identifier

test/attr/testable.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -enable-testing -o %t %S/../Inputs/empty.swift
3+
4+
// Make sure we don't get any errors when importing the modules that were compiled for testing
35
// RUN: %target-swift-frontend -typecheck -I %t -I %S/Inputs/custom-modules %s -verify
4-
// RUN: %target-swift-frontend -typecheck -I %t -I %S/Inputs/custom-modules %s -disable-testable-attr-requires-testable-module -DIMPORTS_ONLY
56

6-
@testable import Swift // expected-error {{module 'Swift' was not compiled for testing}}
7+
// Make sure no errors are thrown if we disable the @testable check
8+
// RUN: %target-swift-frontend -typecheck -I %t -I %S/Inputs/custom-modules %s -verify -disable-testable-attr-requires-testable-module
9+
10+
// Make sure we get the one fatal error for the stdlib not being compiled for testing
11+
// RUN: not %target-swift-frontend -typecheck -I %t -I %S/Inputs/custom-modules %s 2>&1 -DINCLUDE_STDLIB | %FileCheck %s
12+
13+
14+
#if INCLUDE_STDLIB
15+
// CHECK: module 'Swift' was not compiled for testing
16+
@testable import Swift
17+
#endif
18+
19+
// CHECK-NOT: module 'empty' was not compiled for testing
720
@testable import empty // no-error
21+
// CHECK-NOT: module 'Testable_ClangModule' was not compiled for testing
822
@testable import Testable_ClangModule // no-error
923

1024
_ = clangGlobal
11-
12-
#if !IMPORTS_ONLY
13-
@testable func foo() {} // expected-error {{@testable may only be used on 'import' declarations}} {{1-11=}}
14-
#endif

test/attr/testable_invalid_decl.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: %target-swift-frontend -typecheck -verify %s
2+
3+
@testable func foo() {} // expected-error {{@testable may only be used on 'import' declarations}} {{1-11=}}

0 commit comments

Comments
 (0)