Skip to content

Commit 62633ac

Browse files
committed
Tests: prefer to use first rather than indexing
In the case of a failure in the test, we would previously continue to perform the slice operation which will fail in the case of an Asserts runtime due to an out of bounds access. The use of `first?` here would unwrap or fail, allowing tests to continue execution.
1 parent e8d79e9 commit 62633ac

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Tests/SPMBuildCoreTests/PluginInvocationTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class PluginInvocationTests: XCTestCase {
299299
XCTAssert(packageGraph.packages.count == 1, "\(packageGraph.packages)")
300300

301301
// Find the build tool plugin.
302-
let buildToolPlugin = try XCTUnwrap(packageGraph.packages[0].targets.map(\.underlyingTarget).first{ $0.name == "MyPlugin" } as? PluginTarget)
302+
let buildToolPlugin = try XCTUnwrap(packageGraph.packages.first?.targets.map(\.underlyingTarget).first{ $0.name == "MyPlugin" } as? PluginTarget)
303303
XCTAssertEqual(buildToolPlugin.name, "MyPlugin")
304304
XCTAssertEqual(buildToolPlugin.capability, .buildTool)
305305

@@ -873,7 +873,7 @@ class PluginInvocationTests: XCTestCase {
873873
XCTAssert(packageGraph.packages.count == 1, "\(packageGraph.packages)")
874874

875875
// Find the build tool plugin.
876-
let buildToolPlugin = try XCTUnwrap(packageGraph.packages[0].targets.map(\.underlyingTarget).filter{ $0.name == "X" }.first as? PluginTarget)
876+
let buildToolPlugin = try XCTUnwrap(packageGraph.packages.first?.targets.map(\.underlyingTarget).filter{ $0.name == "X" }.first as? PluginTarget)
877877
XCTAssertEqual(buildToolPlugin.name, "X")
878878
XCTAssertEqual(buildToolPlugin.capability, .buildTool)
879879

@@ -1203,7 +1203,7 @@ class PluginInvocationTests: XCTestCase {
12031203
XCTAssertNoDiagnostics(observability.diagnostics)
12041204

12051205
// Find the build tool plugin.
1206-
let buildToolPlugin = try XCTUnwrap(packageGraph.packages[0].targets
1206+
let buildToolPlugin = try XCTUnwrap(packageGraph.packages.first?.targets
12071207
.map(\.underlyingTarget)
12081208
.filter { $0.name == "Foo" }
12091209
.first as? PluginTarget)

0 commit comments

Comments
 (0)