Skip to content
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

Track double writes (prepare for literal snapshots). #15

Merged
merged 9 commits into from
Sep 9, 2023

Conversation

nedtwigg
Copy link
Member

Implementation of

Also the very beginnings of inline literal snapshots.

@jknack I'm hoping that you will write the whole literal snapshot system if you're interested in it. This PR is the first step of that feature. It's a good next step after #13 gets finished.

- all build was failing bc of recordCall
@jknack
Copy link
Collaborator

jknack commented Sep 4, 2023

@nedtwigg was expecting some tests to fail, like: DuplicateWriteTest but it doesn't. What else need to be done here?

@jknack
Copy link
Collaborator

jknack commented Sep 7, 2023

@nedtwigg can we merge this?

fun cannot_write_multiple_things_to_one_snapshot() {
ut_mirror().linesFrom("fun shouldFail()").toFirst("}").uncomment()
ut_mirror().linesFrom("fun shouldPass()").toFirst("}").commentOut()
gradlew("underTest", "-Pselfie=write")?.printStackTrace()
Copy link
Member Author

Choose a reason for hiding this comment

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

This test is expected to fail, and in fact it is failing with:

org.opentest4j.AssertionFailedError: Snapshot was set to multiple values:
first time:com.diffplug.selfie.junit5.CallStack@6d5620ce

this time:com.diffplug.selfie.junit5.CallStack@311bf055
	at app//com.diffplug.selfie.junit5.WriteTracker.recordInternal(WriteTracker.kt:53)
	at app//com.diffplug.selfie.junit5.DiskWriteTracker.record(WriteTracker.kt:67)
	at app//com.diffplug.selfie.junit5.ClassProgress.write(SelfieTestExecutionListener.kt:151)
	at app//com.diffplug.selfie.junit5.Router.readOrWriteOrKeep(SelfieTestExecutionListener.kt:49)
	at app//com.diffplug.selfie.DiskSelfie.toMatchDisk(Selfie.kt:37)
	at app//com.diffplug.selfie.DiskSelfie.toMatchDisk$default(Selfie.kt:36)
	at app//undertest.junit5.UT_DuplicateWriteTest.shouldFail(UT_DuplicateWriteTest.kt:9)
	at [email protected]/java.lang.reflect.Method.invoke(Method.java:568)
	at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1511)
	at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1511)

We should make assertions about the error message (e.g. the current error message is not great).

Same thing is true of the writeonce_mode test below. It is supposed to fail, and it is, but we are not making any assertions about what the failure should be, which means it's hard for us to have good failure messages.

I'm not sure what the best way to make these assertions is. It's easy to catch an exception in the UT_ build and make the assertions there. The alternative is to parse the JUnit test result and pull the assertions into the "puppetmaster" build. No opinion which way to go, just that the message should have an assertion against it.

Once we are making assertions on the error message somehow, this PR is ready to merge, and you can move on to

@nedtwigg
Copy link
Member Author

nedtwigg commented Sep 7, 2023

Sorry, I had this review comment stuck as pending. Yes you can merge this if you want, but we'll need to revisit it to make sure we're doing assertions on the error messages somehow. I think most natural to do in this PR, but we could do that in a future PR too.

- keep using `AssertionFailedError`
- parse message and stacktrace (error are nice now)
@jknack
Copy link
Collaborator

jknack commented Sep 8, 2023

@nedtwigg updated with nice error handling/stacktraces.

@nedtwigg
Copy link
Member Author

nedtwigg commented Sep 9, 2023

Amazing! I love your solution. Next up:

class BinarySelfie(private val actual: ByteArray) : DiskSelfie(Snapshot.of(actual)) {
fun toBeBase64(expected: String): ByteArray = TODO()
fun toBeBase64_TODO(): ByteArray = TODO()
}
fun expectSelfie(actual: ByteArray) = BinarySelfie(actual)
class IntSelfie(private val actual: Int) {
fun toBe(expected: Int): Int = TODO()
fun toBe_TODO(): Int = TODO()
}
fun expectSelfie(actual: Int) = IntSelfie(actual)

@nedtwigg nedtwigg merged commit 91c1048 into main Sep 9, 2023
@nedtwigg nedtwigg deleted the feat/track-writes branch September 9, 2023 00:18
nedtwigg added a commit that referenced this pull request Feb 27, 2024
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