Repository navigation
Only replace @CsvSource values that CSV parsing leaves unchanged in CsvSourceToValueSource - #1244
Merged
Merged
Conversation
… `CsvSourceToValueSource`
The `value` path skipped the checks the `textBlock` path made, so `@CsvSource({"x, y", "z, w"}) void t(String s)` became `@ValueSource(strings = {"x, y", "z, w"})` and passed `"x, y"` instead of `"x"`. Quoted values such as `"'a'"`, surrounding whitespace, blank values and values spanning several lines were changed too. Both paths now skip the conversion unless every value is a literal that CSV parsing passes through unchanged.
Reading the values from the literals rather than the `Literal` trait also covers Kotlin array attributes, so Kotlin non-`String` parameters are now converted, and a single Kotlin value becomes `["apple"]` instead of the non-compiling `strings = "apple"`.
23 of 76 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CsvSourceToValueSourceonly checked the values of@CsvSource(textBlock = ...). For thevalueattribute it copied the strings into@ValueSourceas they were, although JUnit's CSV parsing changes them.@CsvSource({"x, y", "z, w"}) void t(String s)passed"x"and"z", but after the conversion it passed"x, y"and"z, w". A probe against the JUnit on this project's test classpath showed the parser also strips single quotes, trims surrounding whitespace, rejects blank records, and splits a value with line breaks into several records. For example, the multi-line text block passed asvaluein the oldpreserveTextBlockAsValuetest ran three times, with# Lower-case letters,asdfanda, not once with the whole string.Both paths now share one check. They skip the conversion unless every value is a string literal without a comma, single quote or line break, is not blank, and has no surrounding whitespace. Non-
Stringparameters also reject inner whitespace. Non-literal values such as constants are left alone. The old text-block test now expects no change.The values are now read from the literals directly instead of through the
Literaltrait, which does not resolve Kotlin array attributes. Because of that:Stringparameters are now converted (@ValueSource(ints = [1, 2, 3])) where they were left unchanged before.strings = ["apple"]instead ofstrings = "apple", which does not compile.Verified with
./gradlew test --offline --tests '*CsvSourceToValueSourceTest', which passed.Fixes item C8 of #1211.