Skip to content

Commit 591e2a7

Browse files
committed
more integration tests fixes
1 parent b418ed2 commit 591e2a7

File tree

2 files changed

+65
-21
lines changed

2 files changed

+65
-21
lines changed

IntegrationTests/Tests/IntegrationTests/BasicTests.swift

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ final class BasicTests: XCTestCase {
9393
}
9494

9595
func testSwiftPackageInitExec() throws {
96-
try XCTSkipUnless(swiftcSupportsRenamingMainSymbol(), "skipping because host compiler doesn't support `-entry-point-function-name`")
96+
#if swift(<5.5)
97+
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
98+
#endif
9799

98100
try withTemporaryDirectory { dir in
99101
// Create a new package with an executable target.
@@ -106,31 +108,73 @@ final class BasicTests: XCTestCase {
106108
XCTAssertContents(buildOutput) { checker in
107109
checker.check(.regex("Compiling .*Project.*"))
108110
checker.check(.regex("Linking .*Project"))
111+
checker.check(.contains("Build complete"))
109112
}
110113

111114
// Verify that the tool was built and works.
112115
let toolOutput = try sh(projectDir.appending(components: ".build", "debug", "Project")).stdout
113-
XCTAssertEqual(toolOutput, "Hello, world!\n")
116+
XCTAssertMatch(toolOutput.lowercased(), .contains("hello, world!"))
114117

115118
// Check there were no compile errors or warnings.
116119
XCTAssertNoMatch(buildOutput, .contains("error"))
117120
XCTAssertNoMatch(buildOutput, .contains("warning"))
118121
}
119122
}
120123

121-
func testSwiftPackageInitLib() throws {
124+
func testSwiftPackageInitExecTests() throws {
125+
#if swift(<5.5)
126+
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
127+
#endif
128+
122129
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
123130

131+
try withTemporaryDirectory { dir in
132+
// Create a new package with an executable target.
133+
let projectDir = dir.appending(component: "Project")
134+
try localFileSystem.createDirectory(projectDir)
135+
try sh(swiftPackage, "--package-path", projectDir, "init", "--type", "executable")
136+
let testOutput = try sh(swiftTest, "--package-path", projectDir).stdout
137+
138+
// Check the test log.
139+
XCTAssertContents(testOutput) { checker in
140+
checker.check(.regex("Compiling .*ProjectTests.*"))
141+
checker.check("Test Suite 'All tests' passed")
142+
checker.checkNext("Executed 1 test")
143+
}
144+
145+
// Check there were no compile errors or warnings.
146+
XCTAssertNoMatch(testOutput, .contains("error"))
147+
XCTAssertNoMatch(testOutput, .contains("warning"))
148+
}
149+
}
150+
151+
func testSwiftPackageInitLib() throws {
124152
try withTemporaryDirectory { dir in
125153
// Create a new package with an executable target.
126154
let projectDir = dir.appending(component: "Project")
127155
try localFileSystem.createDirectory(projectDir)
128156
try sh(swiftPackage, "--package-path", projectDir, "init", "--type", "library")
129157
let buildOutput = try sh(swiftBuild, "--package-path", projectDir).stdout
130-
let testOutput = try sh(swiftTest, "--package-path", projectDir).stdout
131158

132159
// Check the build log.
133160
XCTAssertMatch(buildOutput, .regex("Compiling .*Project.*"))
161+
XCTAssertMatch(buildOutput, .contains("Build complete"))
162+
163+
// Check there were no compile errors or warnings.
164+
XCTAssertNoMatch(buildOutput, .contains("error"))
165+
XCTAssertNoMatch(buildOutput, .contains("warning"))
166+
}
167+
}
168+
169+
func testSwiftPackageLibsTests() throws {
170+
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
171+
172+
try withTemporaryDirectory { dir in
173+
// Create a new package with an executable target.
174+
let projectDir = dir.appending(component: "Project")
175+
try localFileSystem.createDirectory(projectDir)
176+
try sh(swiftPackage, "--package-path", projectDir, "init", "--type", "library")
177+
let testOutput = try sh(swiftTest, "--package-path", projectDir).stdout
134178

135179
// Check the test log.
136180
XCTAssertContents(testOutput) { checker in
@@ -140,8 +184,8 @@ final class BasicTests: XCTestCase {
140184
}
141185

142186
// Check there were no compile errors or warnings.
143-
XCTAssertNoMatch(buildOutput, .contains("error"))
144-
XCTAssertNoMatch(buildOutput, .contains("warning"))
187+
XCTAssertNoMatch(testOutput, .contains("error"))
188+
XCTAssertNoMatch(testOutput, .contains("warning"))
145189
}
146190
}
147191

@@ -172,6 +216,7 @@ final class BasicTests: XCTestCase {
172216
// Check the build.
173217
let buildOutput = try sh(swiftBuild, "--package-path", toolDir, "-v").stdout
174218
XCTAssertMatch(buildOutput, .regex(#"swiftc.* -module-name special_tool .* ".*/more spaces/special tool/some file.swift""#))
219+
XCTAssertMatch(buildOutput, .contains("Build complete"))
175220

176221
// Verify that the tool exists and works.
177222
let toolOutput = try sh(toolDir.appending(components: ".build", "debug", "special tool")).stdout
@@ -180,12 +225,18 @@ final class BasicTests: XCTestCase {
180225
}
181226

182227
func testSwiftRun() throws {
183-
try XCTSkipUnless(swiftcSupportsRenamingMainSymbol(), "skipping because host compiler doesn't support `-entry-point-function-name`")
228+
#if swift(<5.5)
229+
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
230+
#endif
184231

185232
try withTemporaryDirectory { dir in
186233
let toolDir = dir.appending(component: "secho")
187234
try localFileSystem.createDirectory(toolDir)
188235
try sh(swiftPackage, "--package-path", toolDir, "init", "--type", "executable")
236+
// delete any files generated
237+
for entry in try localFileSystem.getDirectoryContents(toolDir.appending(components: "Sources", "secho")) {
238+
try localFileSystem.removeFileTree(toolDir.appending(components: "Sources", "secho", entry))
239+
}
189240
try localFileSystem.writeFileContents(
190241
toolDir.appending(components: "Sources", "secho", "main.swift"),
191242
bytes: ByteString(encodingAsUTF8: """
@@ -198,6 +249,7 @@ final class BasicTests: XCTestCase {
198249
XCTAssertContents(runError) { checker in
199250
checker.check(.regex("Compiling .*secho.*"))
200251
checker.check(.regex("Linking .*secho"))
252+
checker.check(.contains("Build complete"))
201253
}
202254
XCTAssertEqual(runOutput, "1 \"two\"\n")
203255
}
@@ -305,12 +357,12 @@ final class BasicTests: XCTestCase {
305357

306358
let testOutput = try sh(swiftTest, "--package-path", toolDir, "--filter", "MyTests.*").stderr
307359

308-
// Check the test log.
309-
XCTAssertContents(testOutput) { checker in
310-
checker.check(.contains("Test Suite 'MyTests' started"))
311-
checker.check(.contains("Test Suite 'MyTests' passed"))
312-
checker.check(.contains("Executed 2 tests, with 0 failures"))
313-
}
360+
// Check the test log.
361+
XCTAssertContents(testOutput) { checker in
362+
checker.check(.contains("Test Suite 'MyTests' started"))
363+
checker.check(.contains("Test Suite 'MyTests' passed"))
364+
checker.check(.contains("Executed 2 tests, with 0 failures"))
365+
}
314366
}
315367
}
316368
}

IntegrationTests/Tests/IntegrationTests/Helpers.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,3 @@ extension ProcessResult {
343343
"""
344344
}
345345
}
346-
347-
func swiftcSupportsRenamingMainSymbol() throws -> Bool {
348-
try withTemporaryDirectory { tmpDir in
349-
FileManager.default.createFile(atPath: "\(tmpDir)/foo.swift", contents: Data())
350-
let result = try Process.popen(args: swiftc.pathString, "-c", "-Xfrontend", "-entry-point-function-name", "-Xfrontend", "foo", "\(tmpDir)/foo.swift", "-o", "\(tmpDir)/foo.o")
351-
return try !result.utf8stderrOutput().contains("unknown argument: '-entry-point-function-name'")
352-
}
353-
}

0 commit comments

Comments
 (0)