Skip to content

[Diagnostics] Mark invalid ‘@testable import’ as fatal #22191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ ERROR(imported_decl_is_wrong_kind_typealias,none,
ERROR(ambiguous_decl_in_module,none,
"ambiguous name %0 in module %1", (Identifier, Identifier))

ERROR(module_not_testable,none,
ERROR(module_not_testable,Fatal,
"module %0 was not compiled for testing", (Identifier))

ERROR(module_not_compiled_for_private_import,none,
Expand Down
7 changes: 7 additions & 0 deletions test/Frontend/invalid-testable-import.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/single_int.swiftmodule %S/Inputs/single_int.swift
// RUN: not %target-swift-frontend -typecheck %s -I %t 2>&1 | %FileCheck %s

@testable import single_int // CHECK: module 'single_int' was not compiled for testing

x = 8 // CHECK-NOT: unresolved identifier
22 changes: 16 additions & 6 deletions test/attr/testable.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -enable-testing -o %t %S/../Inputs/empty.swift

// Make sure we don't get any errors when importing the modules that were compiled for testing
// RUN: %target-swift-frontend -typecheck -I %t -I %S/Inputs/custom-modules %s -verify
// RUN: %target-swift-frontend -typecheck -I %t -I %S/Inputs/custom-modules %s -disable-testable-attr-requires-testable-module -DIMPORTS_ONLY

@testable import Swift // expected-error {{module 'Swift' was not compiled for testing}}
// Make sure no errors are thrown if we disable the @testable check
// RUN: %target-swift-frontend -typecheck -I %t -I %S/Inputs/custom-modules %s -verify -disable-testable-attr-requires-testable-module

// Make sure we get the one fatal error for the stdlib not being compiled for testing
// RUN: not %target-swift-frontend -typecheck -I %t -I %S/Inputs/custom-modules %s 2>&1 -DINCLUDE_STDLIB | %FileCheck %s


#if INCLUDE_STDLIB
// CHECK: module 'Swift' was not compiled for testing
@testable import Swift
#endif

// CHECK-NOT: module 'empty' was not compiled for testing
@testable import empty // no-error
// CHECK-NOT: module 'Testable_ClangModule' was not compiled for testing
@testable import Testable_ClangModule // no-error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now these aren't being checked anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about now? I'm trying to be a bit more explicit than before.


_ = clangGlobal

#if !IMPORTS_ONLY
@testable func foo() {} // expected-error {{@testable may only be used on 'import' declarations}} {{1-11=}}
#endif
3 changes: 3 additions & 0 deletions test/attr/testable_invalid_decl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// RUN: %target-swift-frontend -typecheck -verify %s

@testable func foo() {} // expected-error {{@testable may only be used on 'import' declarations}} {{1-11=}}