~Escapable support in Swift Testing

What's the status on ~Escapable support and is there any way I can help?

Motivation: I've been working on Swift embedded and am writing a package to access flattened device trees as a view -- RawSpan and UTF8Span everywhere.

As I'm writing tests I have to go through a number of workarounds, here's one:

@Test
func `read child nodes`() throws {
	let dtb = try include_bytes("test_children")
	let fdt = try Fdt(parsing: dtb.bytes)
	let root = fdt.root
	var children = root.children.makeIterableIterator()

	//TODO: #require does not support ~Escapable yet
	let child1 = try children.next()!
	let t1 = child1.name.charactersEqual(to: "child1")
	#expect(t1)
	let t2 = child1.nameWithoutAddress.charactersEqual(to: "child1")
	#expect(t2)

	let child2 = try children.next()!
	let t3 = child2.name.charactersEqual(to: "child2@42")
	#expect(t3)
	let t4 = child2.nameWithoutAddress.charactersEqual(to: "child2")
	#expect(t4)

	let child3 = try children.next()
	let t5 = child3 == nil
	#expect(t5)
}

In which fdt, root, children, child1, child2 and child3 are all ~Escapable.
Also name and nameWithoutAddress are UTF8Span where I'd love to be able to use == instead.

2 Likes

For technical reasons, it is not possible for us to accept values with suppressed conformances to Copyable or Escapable here. We hope to eventually relax this constraint with [WIP] Rethink how we capture expectation conditions and their subexpressions. by grynspan · Pull Request #840 · swiftlang/swift-testing · GitHub, but I don't expect that will be merged in the near term.

2 Likes