Skip to content

Tests: prefer to use first rather than indexing #6503

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 1 commit into from
May 1, 2023
Merged
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
36 changes: 18 additions & 18 deletions Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -596,17 +596,17 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {

let manifestLoader = ManifestLoader(toolchain: try UserToolchain.default, cacheDir: path, delegate: delegate)

func check(loader: ManifestLoader, expectCached: Bool) {
func check(loader: ManifestLoader, expectCached: Bool) throws {
delegate.clear()
delegate.prepare(expectParsing: !expectCached)

let manifest = try! loader.load(
let manifest = try XCTUnwrap(loader.load(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably we don't even need XCTUnwrap?

manifestPath: manifestPath,
packageKind: .fileSystem(manifestPath.parentDirectory),
toolsVersion: .v4_2,
fileSystem: fs,
observabilityScope: observability.topScope
)
))

XCTAssertNoDiagnostics(observability.diagnostics)
XCTAssertEqual(try delegate.loaded(timeout: .now() + 1), [manifestPath])
Expand All @@ -615,20 +615,20 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
XCTAssertEqual(manifest.targets[0].name, "foo")
}

check(loader: manifestLoader, expectCached: false)
check(loader: manifestLoader, expectCached: true)
try check(loader: manifestLoader, expectCached: false)
try check(loader: manifestLoader, expectCached: true)

try withCustomEnv(["SWIFTPM_MANIFEST_CACHE_TEST": "1"]) {
check(loader: manifestLoader, expectCached: false)
check(loader: manifestLoader, expectCached: true)
try check(loader: manifestLoader, expectCached: false)
try check(loader: manifestLoader, expectCached: true)
}

try withCustomEnv(["SWIFTPM_MANIFEST_CACHE_TEST": "2"]) {
check(loader: manifestLoader, expectCached: false)
check(loader: manifestLoader, expectCached: true)
try check(loader: manifestLoader, expectCached: false)
try check(loader: manifestLoader, expectCached: true)
}

check(loader: manifestLoader, expectCached: true)
try check(loader: manifestLoader, expectCached: true)
}
}

Expand Down Expand Up @@ -658,17 +658,17 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {

let manifestLoader = ManifestLoader(toolchain: try UserToolchain.default, cacheDir: path, delegate: delegate)

func check(loader: ManifestLoader, expectCached: Bool) {
func check(loader: ManifestLoader, expectCached: Bool) throws {
delegate.clear()
delegate.prepare(expectParsing: !expectCached)

let manifest = try! loader.load(
let manifest = try XCTUnwrap(loader.load(
manifestPath: manifestPath,
packageKind: .fileSystem(manifestPath.parentDirectory),
toolsVersion: .v4_2,
fileSystem: fs,
observabilityScope: observability.topScope
)
))

XCTAssertNoDiagnostics(observability.diagnostics)
XCTAssertEqual(try delegate.loaded(timeout: .now() + 1), [manifestPath])
Expand All @@ -677,9 +677,9 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
XCTAssertEqual(manifest.targets[0].name, "foo")
}

check(loader: manifestLoader, expectCached: false)
try check(loader: manifestLoader, expectCached: false)
for _ in 0..<2 {
check(loader: manifestLoader, expectCached: true)
try check(loader: manifestLoader, expectCached: true)
}

try fs.writeFileContents(
Expand All @@ -700,14 +700,14 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
"""
)

check(loader: manifestLoader, expectCached: false)
try check(loader: manifestLoader, expectCached: false)
for _ in 0..<2 {
check(loader: manifestLoader, expectCached: true)
try check(loader: manifestLoader, expectCached: true)
}

let noCacheLoader = ManifestLoader(toolchain: try UserToolchain.default, delegate: delegate)
for _ in 0..<2 {
check(loader: noCacheLoader, expectCached: false)
try check(loader: noCacheLoader, expectCached: false)
}

// Resetting the cache should allow us to remove the cache
Expand Down