Skip to content

Conversation

madsodgaard
Copy link
Contributor

Adds support for writing "..." in any assertOutput in tests. "..." will match zero or more lines until the next line is found, or fail otherwise.

Makes it easier to write new tests that only test important logic and not repetitive scaffolding.

@ktoso
Copy link
Collaborator

ktoso commented Aug 15, 2025

Nice improvement!

The failed match we get now is a bit hard to follow:


error: Number of not matching lines: 1!
==== ---------------------------------------------------------------
Expected output:
0: @_cdecl("Java_com_example_swift_MyClass__00024isBoolean__J")
1: func Java_com_example_swift_MyClass__00024isBoolean__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, self: jlong) -> jboolean {
2:   ...
3:   return self$.pointee.isBoolean.getJNIValue(in: environment!) NOPE
4: }
==== ---------------------------------------------------------------
Got output:
112: @_cdecl("Java_com_example_swift_MyClass__00024isBoolean__J")
113: func Java_com_example_swift_MyClass__00024isBoolean__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, self: jlong) -> jboolean {
114:   assert(self != 0, "self memory address was null")
115:   let selfBits$ = Int(Int64(fromJNI: self, in: environment!))
116:   let self$ = UnsafeMutablePointer<MyClass>(bitPattern: selfBits$)
117:   guard let self$ else {

we don't see the bad line at all. I think we need to dump "everything after the last matched line"

@ktoso
Copy link
Collaborator

ktoso commented Aug 15, 2025

Silly but improved a bit:

  • dumping the whole output, realistically we do need it when we fail to match
  • marking the line from which we're trying to match more explicitly
error: Number of not matching lines: 1!
==== ---------------------------------------------------------------
Expected output:
0: @_cdecl("Java_com_example_swift_MyClass__00024isBoolean__J")
1: func Java_com_example_swift_MyClass__00024isBoolean__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, self: jlong) -> jboolean {
2:   ...
􁁛  Test computedThrowing_swiftThunks() passed after 0.019 seconds.
3:   return self$.pointee.isBoolean.getJNIValue(in: environment!) NOPE
4: }
==== ---------------------------------------------------------------
Got output:
112: @_cdecl("Java_com_example_swift_MyClass__00024isBoolean__J")
113: func Java_com_example_swift_MyClass__00024isBoolean__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, self: jlong) -> jboolean {
114:   assert(self != 0, "self memory address was null")
115:   let selfBits$ = Int(Int64(fromJNI: self, in: environment!))
     ^^^^^^^^ EXPECTED MATCH OR SEARCHING FROM HERE ^^^^^^^^^^^^^^^
116:   let self$ = UnsafeMutablePointer<MyClass>(bitPattern: selfBits$)
117:   guard let self$ else {
118:     fatalError("self memory address was null in call to \(#function)!")
119:   }
120:   return self$.pointee.isBoolean.getJNIValue(in: environment!)
121: }

It's a bit inspired by CheckFile tests;

Screenshot 2025-08-15 at 11 48 47

@ktoso ktoso merged commit 94cb7ec into swiftlang:main Aug 15, 2025
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants