Skip to content

Replace non-printable characters in display names in Jupiter and @SuiteDisplayName #4714

@sbrannen

Description

@sbrannen

Background

While working on #4698, I created tests using blank strings like the following.

@Retention(RetentionPolicy.RUNTIME)
@ParameterizedTest
@NullSource
@ValueSource(strings = { "", " ", "   ", "\t", "\r", "\r\n", "\n" })
@interface EmptyReasonsTest {
}

That produces display names similar to the following, which are not very useful since the last 7 are seemingly identical.

Image

If I wrap the values in single quotes as follows...

@ParameterizedTest(name = "[{index}] reason=''{0}''")

... the results are better.

Image

Proposal

But... I think we can do even better.

Namely if we replace non-printable characters, then configuration like this...

@ParameterizedTest(name = "[{index}] reason=''{0}''")
@NullSource
@ValueSource(strings = { "", " ", "   ", "\t", "\r", "\r\n", "\n", "\u200B" })

... could have display names like this:

Image

Proof of Concept

Invoking the following from ParameterizedInvocationNameFormatter.MessageFormatPartialFormatter's makeReadable() method resulted in the last screenshot in the Proposal section.

private String replaceNonPrintableCharacters(String string) {
	return string
			.replace("\n", "\\n")
			.replace("\r", "\\r")
			.replace("\t", "\\t")
			.replaceAll("[\\p{Cc}\\p{Cf}\\p{Co}\\p{Cn}]", "?");
}

Related Issues

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions