Skip to content

“There is an error in LiteralString, the following value isn't round tripping” exception thrown #560

@unleashy

Description

@unleashy

This code, in Java 25:

expectSelfie("\n\r").toBe_TODO();

Throws the following exception:

WARNING: TestExecutionListener [com.diffplug.selfie.junit5.SelfieTestExecutionListener] threw exception for method: testPlanExecutionFinished(org.junit.platform.launcher.TestPlan@2d0566ba)
java.lang.Error: There is an error in LiteralString, the following value isn't round tripping.
Please this error and the data below at https://github.com/diffplug/selfie/issues/new

ORIGINAL


ROUNDTRIPPED



ENCODED ORIGINAL
"""


"""

	at com.diffplug.selfie.guts.SourceFile$ToBeLiteral.setLiteralAndGetNewlineDelta(SourceFile.kt:59)
	at com.diffplug.selfie.guts.InlineWriteTracker.persistWrites(WriteTracker.kt:215)
	at com.diffplug.selfie.junit5.SnapshotSystemJUnit5.finishedAllTests(SnapshotSystemJUnit5.kt:111)
	at com.diffplug.selfie.junit5.SelfieTestExecutionListener.testPlanExecutionFinished(SelfieTestExecutionListener.kt:81)
	at org.junit.platform.launcher.core.CompositeTestExecutionListener.lambda$testPlanExecutionFinished$0(CompositeTestExecutionListener.java:86)
	at org.junit.platform.launcher.core.CompositeTestExecutionListener.lambda$notifyEach$0(CompositeTestExecutionListener.java:108)
	at org.junit.platform.commons.util.CollectionUtils.forEachInReverseOrder(CollectionUtils.java:213)
	at org.junit.platform.launcher.core.IterationOrder$2.forEach(IterationOrder.java:30)
<35 folded frames>

Just \r, or \n, or \r\n seems to work fine. \n\r does not.

I tried debugging a bit and I'm not sure exactly what's happening but it seems that the encoder fails to account for bare \r in the presence of \n? See line 226 of Literals.kt

I think ideally bare \r would just get encoded by itself, alongside all other escape characters, instead of interpreted as a line terminator by .lines(). Of course \n and \r\n would get special treatment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions