Skip to content

Share helper functions used between package loading tests #2422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 3 additions & 37 deletions Tests/PackageLoadingTests/PD4LoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,13 @@ import XCTest

import TSCBasic
import TSCUtility

import PackageModel
import SPMTestSupport

import PackageLoading

class PackageDescription4LoadingTests: XCTestCase {
let manifestLoader = ManifestLoader(manifestResources: Resources.default)

private func loadManifestThrowing(
_ contents: ByteString,
line: UInt = #line,
body: (Manifest) -> Void) throws
{
let fs = InMemoryFileSystem()
let manifestPath = AbsolutePath.root.appending(component: Manifest.filename)
try fs.writeFileContents(manifestPath, bytes: contents)
let m = try manifestLoader.load(
package: AbsolutePath.root,
baseURL: "/foo",
toolsVersion: .v4,
fileSystem: fs)
guard m.toolsVersion == .v4 else {
return XCTFail("Invalid manfiest version")
}
body(m)
}

private func loadManifest(
_ contents: ByteString,
line: UInt = #line,
body: (Manifest) -> Void)
{
do {
try loadManifestThrowing(contents, line: line, body: body)
} catch ManifestParseError.invalidManifestFormat(let error, _) {
print(error)
XCTFail(file: #file, line: line)
} catch {
XCTFail("Unexpected error: \(error)", file: #file, line: line)
}
class PackageDescription4LoadingTests: PackageDescriptionLoadingTests {
override var toolsVersion: ToolsVersion {
.v4
}

func testTrivial() {
Expand Down
39 changes: 3 additions & 36 deletions Tests/PackageLoadingTests/PD4_2LoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,9 @@ import SPMTestSupport
import PackageModel
import PackageLoading

// FIXME: We should share the infra with other loading tests.
class PackageDescription4_2LoadingTests: XCTestCase {
let manifestLoader = ManifestLoader(manifestResources: Resources.default)

private func loadManifestThrowing(
_ contents: ByteString,
line: UInt = #line,
body: (Manifest) -> Void
) throws {
let fs = InMemoryFileSystem()
let manifestPath = AbsolutePath.root.appending(component: Manifest.filename)
try fs.writeFileContents(manifestPath, bytes: contents)
let m = try manifestLoader.load(
package: AbsolutePath.root,
baseURL: "/foo",
toolsVersion: .v4_2,
fileSystem: fs)
guard m.toolsVersion == .v4_2 else {
return XCTFail("Invalid manfiest version")
}
body(m)
}

private func loadManifest(
_ contents: ByteString,
line: UInt = #line,
body: (Manifest) -> Void
) {
do {
try loadManifestThrowing(contents, line: line, body: body)
} catch ManifestParseError.invalidManifestFormat(let error, _) {
print(error)
XCTFail(file: #file, line: line)
} catch {
XCTFail("Unexpected error: \(error)", file: #file, line: line)
}
class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
override var toolsVersion: ToolsVersion {
.v4_2
}

func testBasics() {
Expand Down
41 changes: 3 additions & 38 deletions Tests/PackageLoadingTests/PD5LoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,9 @@ import SPMTestSupport
import PackageModel
import PackageLoading

// FIXME: We should share the infra with other loading tests.
class PackageDescription5LoadingTests: XCTestCase {
let manifestLoader = ManifestLoader(manifestResources: Resources.default)

private func loadManifestThrowing(
_ contents: ByteString,
toolsVersion: ToolsVersion = .v5,
line: UInt = #line,
body: (Manifest) -> Void
) throws {
let fs = InMemoryFileSystem()
let manifestPath = AbsolutePath.root.appending(component: Manifest.filename)
try fs.writeFileContents(manifestPath, bytes: contents)
let m = try manifestLoader.load(
package: AbsolutePath.root,
baseURL: "/foo",
toolsVersion: toolsVersion,
fileSystem: fs)
guard m.toolsVersion == toolsVersion else {
return XCTFail("Invalid manfiest version")
}
body(m)
}

private func loadManifest(
_ contents: ByteString,
toolsVersion: ToolsVersion = .v5,
line: UInt = #line,
body: (Manifest) -> Void
) {
do {
try loadManifestThrowing(contents, toolsVersion: toolsVersion, line: line, body: body)
} catch ManifestParseError.invalidManifestFormat(let error, _) {
print(error)
XCTFail(file: #file, line: line)
} catch {
XCTFail("Unexpected error: \(error)", file: #file, line: line)
}
class PackageDescription5LoadingTests: PackageDescriptionLoadingTests {
override var toolsVersion: ToolsVersion {
.v5
}

func testBasics() {
Expand Down
63 changes: 63 additions & 0 deletions Tests/PackageLoadingTests/PDLoadingTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import XCTest

import TSCBasic
import TSCUtility
import SPMTestSupport
import PackageModel
import PackageLoading

class PackageDescriptionLoadingTests: XCTestCase {
let manifestLoader = ManifestLoader(manifestResources: Resources.default)

var toolsVersion: ToolsVersion {
fatalError("implement in subclass")
}

func loadManifestThrowing(
_ contents: ByteString,
toolsVersion: ToolsVersion? = nil,
line: UInt = #line,
body: (Manifest) -> Void
) throws {
let toolsVersion = toolsVersion ?? self.toolsVersion
let fs = InMemoryFileSystem()
let manifestPath = AbsolutePath.root.appending(component: Manifest.filename)
try fs.writeFileContents(manifestPath, bytes: contents)
let m = try manifestLoader.load(
package: AbsolutePath.root,
baseURL: "/foo",
toolsVersion: toolsVersion,
fileSystem: fs)
guard m.toolsVersion == toolsVersion else {
return XCTFail("Invalid manfiest version")
}
body(m)
}

func loadManifest(
_ contents: ByteString,
toolsVersion: ToolsVersion? = nil,
line: UInt = #line,
body: (Manifest) -> Void
) {
do {
let toolsVersion = toolsVersion ?? self.toolsVersion
try loadManifestThrowing(contents, toolsVersion: toolsVersion, line: line, body: body)
} catch ManifestParseError.invalidManifestFormat(let error, _) {
print(error)
XCTFail(file: #file, line: line)
} catch {
XCTFail("Unexpected error: \(error)", file: #file, line: line)
}
}
}