File: implementation-only-testable.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (66 lines) | stat: -rw-r--r-- 2,601 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/// Implementation-only dependencies of modules imported as testable are
/// optional, we attempt to load them but don't error if they are missing.

// RUN: %empty-directory(%t)
// RUN: split-file %s %t

/// Build the hidden implementation-only dependency and the testable module.
// RUN: %target-swift-frontend -emit-module %t/HiddenDep.swift -o %t \
// RUN:   -swift-version 5 -enable-library-evolution
// RUN: %target-swift-frontend -emit-module %t/TestedLib.swift -o %t \
// RUN:   -swift-version 5 -enable-library-evolution -I %t \
// RUN:   -enable-testing

/// A client should ignore the transitive implementation-only dependency for a
/// normal import.
// RUN: %target-swift-frontend -typecheck %t/ClientNormalImport.swift -o %t \
// RUN:   -swift-version 5 -I %t -Rmodule-loading 2>&1 | \
// RUN:   %FileCheck --check-prefix=CHECK-NOT-LOADED %s

/// A client should load the transitive implementation-only dependency of
/// a module imported @testable.
// RUN: %target-swift-frontend -typecheck %t/ClientTestableImport.swift -o %t \
// RUN:   -swift-version 5 -I %t -Rmodule-loading 2>&1 | %FileCheck %s

/// If the dependency is missing we don't fail at loading, but we may still
/// fail later accessing decls missing because of references to the not-loaded module.
// RUN: rm %t/HiddenDep.swiftmodule

/// The transitive dependency is not loaded but a client can still build fine.
// RUN: %target-swift-frontend -typecheck %t/ClientNormalImport.swift -o %t \
// RUN:   -swift-version 5 -I %t -Rmodule-loading 2>&1 | \
// RUN:   %FileCheck %s --check-prefix=CHECK-NOT-LOADED

/// Clients referencing a decl that depends on the hidden module don't see the
/// decl, it is dropped by deserialization recovery.
// RUN: %target-swift-frontend -typecheck %t/ClientTestableImport.swift -o %t \
// RUN:   -swift-version 5 -I %t -verify

//--- HiddenDep.swift

public struct HiddenType {}

//--- TestedLib.swift

@_implementationOnly import HiddenDep

internal func dependsOnHiddenType() -> HiddenType { fatalError() }

//--- ClientNormalImport.swift

/// Note that the import doesn't have to be testable, only the imported module
/// needs to enable testing. We may want to improve upon this in the future.
import TestedLib

// Note: extra newlines below ensure that context printing doesn't show the
// lines that we shouldn't see.


// CHECK-NOT-LOADED-NOT: remark: loaded module 'HiddenDep'

//--- ClientTestableImport.swift

@testable import TestedLib
// CHECK: remark: loaded module 'HiddenDep'

let _ = dependsOnHiddenType() // expected-error {{cannot find 'dependsOnHiddenType' in scope}}