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

Autofix of UnnecessaryGString leaves invalid code in data provider of Spock tests #436

Open
sdoeringNew opened this issue Nov 20, 2024 · 0 comments

Comments

@sdoeringNew
Copy link

sdoeringNew commented Nov 20, 2024

Hi,

I'm using npm-groovy-lint with my Spock tests that have a data provider for several test cases.

def "Test: #testCaseTitle"() {
    when:
    def result = testedMethod(json)

    then:
    result != null

    where:
    testCaseTitle     | json                                                      || errorMessage
    'missing image'   | """{ "view": "available", "options": ["empty"] }"""       || """JSON is missing image"""
    'missing options' | """{ "view": "available", "image": "${placeholder}" }"""  || """JSON is missing options"""
    'missing view'    | """{ "image": "${placeholder}", "options": ["empty"] }""" || """JSON is missing view"""
    'all missing'     | """{ }"""                                                 || """JSON is missing image, JSON is missing options, JSON is missing view"""
}

After auto-fixing the code using npm-groovy-lint the source code got uncompilable because of wrongly replaced GString quotes.

def "Test: #testCaseTitle"() {
    when:
    def result = testedMethod(json)

    then:
    result != null

    where:
    testCaseTitle     | json                                                      || errorMessage
    'missing image'   | '''{ "view": "available", "options": ["empty"] }"""       || ""'JSON is missing image'""
    'missing options' | '''{ "view": "available", "image": "${placeholder}" }"""  || ""'JSON is missing options'""
    'missing view'    | """{ "image": "${placeholder}", "options": ["empty"] }""" || ""'JSON is missing view'""
    'all missing'     | ""'{ }'""                                                 || ""'JSON is missing image, JSON is missing options, JSON is missing view'""
}

npm-groovy-lint does not detect the end of the GStrings correctly and therefore replaces the the quotes at the wrong place leaving the source code uncompilable.

This:

"""{ "view": "available", "options": ["empty"] }"""

Becomes that:

'''{ "view": "available", "options": ["empty"] }"""

This:

"""JSON is missing image"""

Becomes that:

""'JSON is missing image'""

That behaviour is not good.

Kind regards

@sdoeringNew sdoeringNew changed the title UnnecessaryGString leaves invalid code in data provider of Spock tests Autofix of UnnecessaryGString leaves invalid code in data provider of Spock tests Nov 20, 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

No branches or pull requests

1 participant