Skip to content

Commit 4bf7182

Browse files
committed
Make PlannedNode conform to CustomStringConvertible.
Some checking logic in the test infrastructure reports errors with lists of PlannedNodes, and it is much easier to triage those errors if the identity of the nodes are present in the error message. Also changed one such method to include this information rather than raw counts.
1 parent de06eb5 commit 4bf7182

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Sources/SWBCore/PlannedNode.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public import SWBUtil
1515

1616
/// A node that represents an input or output of a task (often, but not necessarily, representing the path of a file system entity). Every node has a name, even if it doesn’t have a path. If it does have a path, the name will be the same as the last path component of a path.
1717
/// PlannedNode are AnyObject-type and all instances are interned to allow for reference equality.
18-
public protocol PlannedNode: AnyObject, Sendable {
18+
public protocol PlannedNode: AnyObject, Sendable, CustomStringConvertible {
1919
/// Node name (never empty, and constant through the lifetime of the node).
2020
var name: String { get }
2121

@@ -34,6 +34,10 @@ public final class PlannedPathNode: PlannedNode {
3434
self.path = path
3535
self.name = path.basename
3636
}
37+
38+
public var description: String {
39+
return "<\(type(of: self)):\(path.str)>"
40+
}
3741
}
3842

3943
/// A node that represents a directory *tree* as a file system entity.
@@ -52,6 +56,10 @@ public final class PlannedDirectoryTreeNode: PlannedNode {
5256
self.name = path.basename + "/"
5357
self.exclusionPatterns = excluding
5458
}
59+
60+
public var description: String {
61+
return "<\(type(of: self)):\(path.str)>"
62+
}
5563
}
5664

5765
/// A node that represents a conceptual entity that is not a path.
@@ -63,6 +71,10 @@ public final class PlannedVirtualNode: PlannedNode {
6371
assert(!name.isEmpty)
6472
self.name = name
6573
}
74+
75+
public var description: String {
76+
return "<\(type(of: self)):\(name)>"
77+
}
6678
}
6779

6880
// Intern planned nodes to allow for reference equality

Sources/SWBTestSupport/TaskConstructionTester.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ package extension PlannedTaskInputsOutputs {
11981198
}
11991199

12001200
private func checkNodes(nodes: [any PlannedNode], name: String, contain patterns: [NodePattern], sourceLocation: SourceLocation = #_sourceLocation) {
1201-
#expect(nodes.count >= patterns.count, "too many patterns (\(patterns.count) > \(nodes.count)) for \(name)", sourceLocation: sourceLocation)
1201+
#expect(nodes.count >= patterns.count, "too many patterns for \(name) (\(nodes) vs \(patterns))", sourceLocation: sourceLocation)
12021202
if nodes.count >= patterns.count {
12031203
for pattern in patterns {
12041204
var foundPattern = false

0 commit comments

Comments
 (0)