Skip to content

Commit b43c310

Browse files
committed
[Tests] Remove dylib asserts
We can't assert for dylib anymore because we will not always create them.
1 parent 27b9853 commit b43c310

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

Tests/FunctionalTests/ClangModuleTests.swift

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,39 @@ import PackageModel
1616
import SourceControl
1717
import Utility
1818

19-
extension String {
20-
// FIXME: It doesn't seem right for this to be an extension on String; it isn't inherent "string behavior".
21-
fileprivate var soname: String {
22-
return "lib\(self).\(Product.dynamicLibraryExtension)"
19+
/// Asserts if a directory (recursively) contains a file.
20+
private func XCTAssertDirectoryContainsFile(dir: AbsolutePath, filename: String, file: StaticString = #file, line: UInt = #line) {
21+
do {
22+
for entry in try walk(dir) {
23+
if entry.basename == filename { return }
24+
}
25+
} catch {
26+
XCTFail("Failed with error \(error)", file: file, line: line)
2327
}
28+
XCTFail("Directory \(dir) does not contain \(file)", file: file, line: line)
2429
}
2530

2631
class ClangModulesTestCase: XCTestCase {
2732
func testSingleModuleFlatCLibrary() {
2833
fixture(name: "ClangModules/CLibraryFlat") { prefix in
2934
XCTAssertBuilds(prefix)
3035
let debugPath = prefix.appending(components: ".build", "debug")
31-
XCTAssertFileExists(debugPath.appending(components: "CLibraryFlat".soname))
36+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
3237
}
3338
}
3439

3540
func testSingleModuleCLibraryInSources() {
3641
fixture(name: "ClangModules/CLibrarySources") { prefix in
3742
XCTAssertBuilds(prefix)
3843
let debugPath = prefix.appending(components: ".build", "debug")
39-
XCTAssertFileExists(debugPath.appending(component: "CLibrarySources".soname))
44+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
4045
}
4146
}
4247

4348
func testMixedSwiftAndC() {
4449
fixture(name: "ClangModules/SwiftCMixed") { prefix in
4550
XCTAssertBuilds(prefix)
4651
let debugPath = prefix.appending(components: ".build", "debug")
47-
XCTAssertFileExists(debugPath.appending(component: "SeaLib".soname))
4852
XCTAssertFileExists(debugPath.appending(component: "SeaExec"))
4953
var output = try popen([debugPath.appending(component: "SeaExec").asString], environment: [:])
5054
XCTAssertEqual(output, "a = 5\n")
@@ -57,7 +61,6 @@ class ClangModulesTestCase: XCTestCase {
5761
fixture(name: "ClangModules/SwiftCMixed2") { prefix in
5862
XCTAssertBuilds(prefix)
5963
let debugPath = prefix.appending(components: ".build", "debug")
60-
XCTAssertFileExists(debugPath.appending(component: "SeaLib".soname))
6164
let output = try popen([debugPath.appending(component: "SeaExec").asString], environment: [:])
6265
XCTAssertEqual(output, "a = 5\n")
6366
}
@@ -69,7 +72,6 @@ class ClangModulesTestCase: XCTestCase {
6972
XCTAssertBuilds(packageRoot)
7073
let debugPath = prefix.appending(components: "Bar", ".build", "debug")
7174
XCTAssertFileExists(debugPath.appending(component: "Bar"))
72-
XCTAssertFileExists(debugPath.appending(component: "Foo".soname))
7375
let path = try SwiftPMProduct.packagePath(for: "Foo", packageRoot: packageRoot)
7476
XCTAssertEqual(GitRepository(path: path).tags, ["1.2.3"])
7577
}
@@ -79,9 +81,8 @@ class ClangModulesTestCase: XCTestCase {
7981
fixture(name: "ClangModules/CLibraryiquote") { prefix in
8082
XCTAssertBuilds(prefix)
8183
let debugPath = prefix.appending(components: ".build", "debug")
82-
XCTAssertFileExists(debugPath.appending(component: "Foo".soname))
83-
XCTAssertFileExists(debugPath.appending(component: "Bar".soname))
84-
XCTAssertFileExists(debugPath.appending(component: "Bar with spaces".soname))
84+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Bar.c.o")
85+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
8586
}
8687
}
8788

@@ -90,7 +91,8 @@ class ClangModulesTestCase: XCTestCase {
9091
let packageRoot = prefix.appending(component: "Bar")
9192
XCTAssertBuilds(packageRoot)
9293
let debugPath = prefix.appending(components: "Bar", ".build", "debug")
93-
XCTAssertFileExists(debugPath.appending(component: "Foo".soname))
94+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Sea.c.o")
95+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
9496
let path = try SwiftPMProduct.packagePath(for: "Foo", packageRoot: packageRoot)
9597
XCTAssertEqual(GitRepository(path: path).tags, ["1.2.3"])
9698
}
@@ -112,7 +114,8 @@ class ClangModulesTestCase: XCTestCase {
112114
let packageRoot = prefix.appending(component: "Bar")
113115
XCTAssertBuilds(packageRoot)
114116
let debugPath = prefix.appending(components: "Bar", ".build", "debug")
115-
XCTAssertFileExists(debugPath.appending(component: "Foo".soname))
117+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Sea.c.o")
118+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
116119
let path = try SwiftPMProduct.packagePath(for: "Foo", packageRoot: packageRoot)
117120
XCTAssertEqual(GitRepository(path: path).tags, ["1.2.3"])
118121
}
@@ -122,11 +125,10 @@ class ClangModulesTestCase: XCTestCase {
122125
fixture(name: "ClangModules/ModuleMapGenerationCases") { prefix in
123126
XCTAssertBuilds(prefix)
124127
let debugPath = prefix.appending(components: ".build", "debug")
125-
XCTAssertFileExists(debugPath.appending(component: "UmbrellaHeader".soname))
126-
XCTAssertFileExists(debugPath.appending(component: "FlatInclude".soname))
127-
XCTAssertFileExists(debugPath.appending(component: "UmbellaModuleNameInclude".soname))
128-
XCTAssertFileExists(debugPath.appending(component: "NoIncludeDir".soname))
129-
XCTAssertFileExists(debugPath.appending(component: "Baz"))
128+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Jaz.c.o")
129+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "main.swift.o")
130+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "FlatInclude.c.o")
131+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "UmbrellaHeader.c.o")
130132
}
131133
}
132134

@@ -135,7 +137,7 @@ class ClangModulesTestCase: XCTestCase {
135137
fixture(name: "ClangModules/CDynamicLookup") { prefix in
136138
XCTAssertBuilds(prefix, Xld: ["-undefined", "dynamic_lookup"])
137139
let debugPath = prefix.appending(components: ".build", "debug")
138-
XCTAssertFileExists(debugPath.appending(component: "CDynamicLookup".soname))
140+
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
139141
}
140142
}
141143

@@ -144,7 +146,7 @@ class ClangModulesTestCase: XCTestCase {
144146
fixture(name: "ClangModules/ObjCmacOSPackage") { prefix in
145147
// Build the package.
146148
XCTAssertBuilds(prefix)
147-
XCTAssertFileExists(prefix.appending(components: ".build", "debug", "ObjCmacOSPackage".soname))
149+
XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", "debug"), filename: "HelloWorldExample.m.o")
148150
// Run swift-test on package.
149151
XCTAssertSwiftTest(prefix)
150152
}

0 commit comments

Comments
 (0)