Skip to content

Commit 8ad5297

Browse files
committed
Don't complain when using '@testable import' on a Clang-only module.
Justification: if you delete all the Swift code out of a framework, you shouldn't have to change your tests. rdar://problem/21207346 Swift SVN r29452
1 parent 006a016 commit 8ad5297

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,8 @@ Module *ClangImporter::Implementation::finishLoadingClangModule(
878878
// but that's not correct for submodules.
879879
Identifier name = SwiftContext.getIdentifier((*clangModule).Name);
880880
result = Module::create(name, SwiftContext);
881+
// Silence error messages about testably importing a Clang module.
882+
result->setTestingEnabled();
881883

882884
wrapperUnit =
883885
new (SwiftContext) ClangModuleUnit(*result, owner, clangModule);
@@ -1019,6 +1021,8 @@ ClangModuleUnit *ClangImporter::Implementation::getWrapperForModule(
10191021
// FIXME: Handle hierarchical names better.
10201022
Identifier name = SwiftContext.getIdentifier(underlying->Name);
10211023
auto wrapper = Module::create(name, SwiftContext);
1024+
// Silence error messages about testably importing a Clang module.
1025+
wrapper->setTestingEnabled();
10221026

10231027
auto file = new (SwiftContext) ClangModuleUnit(*wrapper, importer,
10241028
underlying);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
module AttrObjc_FooClangModule { header "attr_objc_foo_clang_module.h" }
2+
module Testable_ClangModule { header "testable_clang.h" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern int clangGlobal;

test/attr/testable.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// RUN: rm -rf %t && mkdir %t
22
// RUN: %target-swift-frontend -emit-module -enable-testing -o %t %S/../Inputs/empty.swift
3-
// RUN: %target-swift-frontend -parse -I %t %s -verify
4-
// RUN: %target-swift-frontend -parse -I %t %s -disable-testable-attr-requires-testable-module -DIMPORTS_ONLY
3+
// RUN: %target-swift-frontend -parse -I %t -I %S/Inputs/custom-modules %s -verify
4+
// RUN: %target-swift-frontend -parse -I %t -I %S/Inputs/custom-modules %s -disable-testable-attr-requires-testable-module -DIMPORTS_ONLY
55

66
@testable import Swift // expected-error {{module 'Swift' was not compiled for testing}}
77
@testable import empty // no-error
8+
@testable import Testable_ClangModule // no-error
9+
10+
_ = clangGlobal
811

912
#if !IMPORTS_ONLY
1013
@testable func foo() {} // expected-error {{@testable may only be used on 'import' declarations}}

0 commit comments

Comments
 (0)