Skip to content

Commit bf3c7db

Browse files
committed
Share helper functions used between package loading tests
1 parent 528da51 commit bf3c7db

File tree

4 files changed

+72
-109
lines changed

4 files changed

+72
-109
lines changed

Tests/PackageLoadingTests/PD4LoadingTests.swift

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,9 @@ import SPMTestSupport
1818

1919
import PackageLoading
2020

21-
class PackageDescription4LoadingTests: XCTestCase {
22-
let manifestLoader = ManifestLoader(manifestResources: Resources.default)
23-
24-
private func loadManifestThrowing(
25-
_ contents: ByteString,
26-
line: UInt = #line,
27-
body: (Manifest) -> Void) throws
28-
{
29-
let fs = InMemoryFileSystem()
30-
let manifestPath = AbsolutePath.root.appending(component: Manifest.filename)
31-
try fs.writeFileContents(manifestPath, bytes: contents)
32-
let m = try manifestLoader.load(
33-
package: AbsolutePath.root,
34-
baseURL: "/foo",
35-
toolsVersion: .v4,
36-
fileSystem: fs)
37-
guard m.toolsVersion == .v4 else {
38-
return XCTFail("Invalid manfiest version")
39-
}
40-
body(m)
41-
}
42-
43-
private func loadManifest(
44-
_ contents: ByteString,
45-
line: UInt = #line,
46-
body: (Manifest) -> Void)
47-
{
48-
do {
49-
try loadManifestThrowing(contents, line: line, body: body)
50-
} catch ManifestParseError.invalidManifestFormat(let error, _) {
51-
print(error)
52-
XCTFail(file: #file, line: line)
53-
} catch {
54-
XCTFail("Unexpected error: \(error)", file: #file, line: line)
55-
}
21+
class PackageDescription4LoadingTests: PackageDescriptionLoadingTests {
22+
override var toolsVersion: ToolsVersion {
23+
.v4
5624
}
5725

5826
func testTrivial() {

Tests/PackageLoadingTests/PD4_2LoadingTests.swift

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,9 @@ import SPMTestSupport
1616
import PackageModel
1717
import PackageLoading
1818

19-
// FIXME: We should share the infra with other loading tests.
20-
class PackageDescription4_2LoadingTests: XCTestCase {
21-
let manifestLoader = ManifestLoader(manifestResources: Resources.default)
22-
23-
private func loadManifestThrowing(
24-
_ contents: ByteString,
25-
line: UInt = #line,
26-
body: (Manifest) -> Void
27-
) throws {
28-
let fs = InMemoryFileSystem()
29-
let manifestPath = AbsolutePath.root.appending(component: Manifest.filename)
30-
try fs.writeFileContents(manifestPath, bytes: contents)
31-
let m = try manifestLoader.load(
32-
package: AbsolutePath.root,
33-
baseURL: "/foo",
34-
toolsVersion: .v4_2,
35-
fileSystem: fs)
36-
guard m.toolsVersion == .v4_2 else {
37-
return XCTFail("Invalid manfiest version")
38-
}
39-
body(m)
40-
}
41-
42-
private func loadManifest(
43-
_ contents: ByteString,
44-
line: UInt = #line,
45-
body: (Manifest) -> Void
46-
) {
47-
do {
48-
try loadManifestThrowing(contents, line: line, body: body)
49-
} catch ManifestParseError.invalidManifestFormat(let error, _) {
50-
print(error)
51-
XCTFail(file: #file, line: line)
52-
} catch {
53-
XCTFail("Unexpected error: \(error)", file: #file, line: line)
54-
}
19+
class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
20+
override var toolsVersion: ToolsVersion {
21+
.v4_2
5522
}
5623

5724
func testBasics() {

Tests/PackageLoadingTests/PD5LoadingTests.swift

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,9 @@ import SPMTestSupport
1616
import PackageModel
1717
import PackageLoading
1818

19-
// FIXME: We should share the infra with other loading tests.
20-
class PackageDescription5LoadingTests: XCTestCase {
21-
let manifestLoader = ManifestLoader(manifestResources: Resources.default)
22-
23-
private func loadManifestThrowing(
24-
_ contents: ByteString,
25-
toolsVersion: ToolsVersion = .v5,
26-
line: UInt = #line,
27-
body: (Manifest) -> Void
28-
) throws {
29-
let fs = InMemoryFileSystem()
30-
let manifestPath = AbsolutePath.root.appending(component: Manifest.filename)
31-
try fs.writeFileContents(manifestPath, bytes: contents)
32-
let m = try manifestLoader.load(
33-
package: AbsolutePath.root,
34-
baseURL: "/foo",
35-
toolsVersion: toolsVersion,
36-
fileSystem: fs)
37-
guard m.toolsVersion == toolsVersion else {
38-
return XCTFail("Invalid manfiest version")
39-
}
40-
body(m)
41-
}
42-
43-
private func loadManifest(
44-
_ contents: ByteString,
45-
toolsVersion: ToolsVersion = .v5,
46-
line: UInt = #line,
47-
body: (Manifest) -> Void
48-
) {
49-
do {
50-
try loadManifestThrowing(contents, toolsVersion: toolsVersion, line: line, body: body)
51-
} catch ManifestParseError.invalidManifestFormat(let error, _) {
52-
print(error)
53-
XCTFail(file: #file, line: line)
54-
} catch {
55-
XCTFail("Unexpected error: \(error)", file: #file, line: line)
56-
}
19+
class PackageDescription5LoadingTests: PackageDescriptionLoadingTests {
20+
override var toolsVersion: ToolsVersion {
21+
.v5
5722
}
5823

5924
func testBasics() {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import XCTest
12+
13+
import TSCBasic
14+
import TSCUtility
15+
import SPMTestSupport
16+
import PackageModel
17+
import PackageLoading
18+
19+
class PackageDescriptionLoadingTests: XCTestCase {
20+
let manifestLoader = ManifestLoader(manifestResources: Resources.default)
21+
22+
var toolsVersion: ToolsVersion {
23+
fatalError("implement in subclass")
24+
}
25+
26+
func loadManifestThrowing(
27+
_ contents: ByteString,
28+
toolsVersion: ToolsVersion? = nil,
29+
line: UInt = #line,
30+
body: (Manifest) -> Void
31+
) throws {
32+
let toolsVersion = toolsVersion ?? self.toolsVersion
33+
let fs = InMemoryFileSystem()
34+
let manifestPath = AbsolutePath.root.appending(component: Manifest.filename)
35+
try fs.writeFileContents(manifestPath, bytes: contents)
36+
let m = try manifestLoader.load(
37+
package: AbsolutePath.root,
38+
baseURL: "/foo",
39+
toolsVersion: toolsVersion,
40+
fileSystem: fs)
41+
guard m.toolsVersion == toolsVersion else {
42+
return XCTFail("Invalid manfiest version")
43+
}
44+
body(m)
45+
}
46+
47+
func loadManifest(
48+
_ contents: ByteString,
49+
toolsVersion: ToolsVersion? = nil,
50+
line: UInt = #line,
51+
body: (Manifest) -> Void
52+
) {
53+
do {
54+
let toolsVersion = toolsVersion ?? self.toolsVersion
55+
try loadManifestThrowing(contents, toolsVersion: toolsVersion, line: line, body: body)
56+
} catch ManifestParseError.invalidManifestFormat(let error, _) {
57+
print(error)
58+
XCTFail(file: #file, line: line)
59+
} catch {
60+
XCTFail("Unexpected error: \(error)", file: #file, line: line)
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)