junit5 icon indicating copy to clipboard operation
junit5 copied to clipboard

CsvSource drops backslash character from input

Open xazap opened this issue 1 year ago • 0 comments

I am seeing issues with backslash characters getting dropped while processing input from @CsvSource annotated tests. I observed that its occurrence depends on the test case that preceded it as is shown in the reproduction steps. I have considered it might be related to having single quote characters in the input so I deliberately set quoteCharacter='x' in the @CsvSource annotation.

Steps to reproduce

This test passes as expected:

@ParameterizedTest(name = "[{index}] {arguments}")
@CsvSource(useHeadersInDisplayName = true, delimiterString = "||", quoteCharacter = 'x', textBlock = """
	INPUT		|| EXPECTED LENGTH
	\\M\\\\o\\\'	|| 7
	\\M\\q\\\'	|| 6
""")
void test1(String input, int expectedLength) {
	Assertions.assertTrue(input.length() == expectedLength);
}

If I swap the input lines, the test unexpectedly fails because the String "\\M\\\\o\\\'" is missing a backslash character before 'o' resulting in a length of 6 and thus failing the test:

@ParameterizedTest(name = "[{index}] {arguments}")
@CsvSource(useHeadersInDisplayName = true, delimiterString = "||", quoteCharacter = 'x', textBlock = """
	INPUT		|| EXPECTED LENGTH
	\\M\\q\\\'	|| 6
	\\M\\\\o\\\'	|| 7
""")
void test2(String input, int expectedLength) {
	Assertions.assertTrue(input.length() == expectedLength);
}

To further show that a backlash character gets eaten, I added an extra '\\' character to the input. The test now passes, but note that the String "\\M\\\\\\o\\\'" should have a length of 8, not 7!

@ParameterizedTest(name = "[{index}] {arguments}")
@CsvSource(useHeadersInDisplayName = true, delimiterString = "||", quoteCharacter = 'x', textBlock = """
	INPUT		|| EXPECTED LENGTH
	\\M\\q\\\'	|| 6
	\\M\\\\\\o\\\'	|| 7
""")
void test3(String input, int expectedLength) {
	Assertions.assertTrue(input.length() == expectedLength);
}

Context

  • Jupiter version: 5.11.0-M1 (also tried: 5.10.2, same results)
  • Plaform version: 1.11.0-M1 (also tried: 1.10.2, same results)
  • Java 17
  • Build Tool/IDE: Maven 3.9.4 / Eclipse 2024.3

xazap avatar Apr 28 '24 17:04 xazap