Skip to content

Unable to mock 'bat' step if 'label' contains Unicode character #130

Description

@mdealer

Expected Behavior

Proper Unicode handling and mock of the step.

Actual Behavior

It does not mock the step.

Steps to Reproduce

  1. Create a Jenkins Shared Groovy Library
  2. Implement some function to be called later that contains a 'bat' step with a 'label' that contains a Unicode char.
  3. Add tests using jenkins-spock and mock the 'bat' step

Additional Information

The bat step in question is roughly:
output = script.bat script: '@echo off && aaa aaaaaaaaa aaaaaaaaaaaaaaaaa@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa', returnStdout: true, encoding: 'UTF-8', label: 'Batch Script (💻myhostname)'

The setup function / test class is roughly:
import com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification

class createBuilderSpec extends JenkinsPipelineSpecification {
    def setup() {
        // ...
        getPipelineMock('bat')([returnStdout: true, script: 'hostname']) >> 'myhostname' // Some other step which just works fine
	getPipelineMock("bat")([script:'@echo off && aaa aaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa', returnStdout:true, encoding:'UTF-8', label:'Batch Script (💻myhostname)']) >> 'someresult'
         // ...
    }
// ...

Spock does not handle the Unicode character, I can see it in the console:

10:11:07.598 [main] DEBUG com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification - TEST FIXTURE intercepted & redirected a call:
	Test         : class com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification
	Note         : pipeline step 
	Via          : createBuilder@4cb773c5.methodMissing
	    (types)  : createBuilder.methodMissing
	Invocation   : createBuilder@4cb773c5.bat([[script:@echo off && aaa aaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa, returnStdout:true, encoding:UTF-8, label:Batch Script (­ƒÆ╗myhostname)]])
	    (types)  : createBuilder.bat(Object[])
	Forwarded To : Mock for type 'Closure' named 'getPipelineMock("bat")'.call([script:aaa aaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa, returnStdout:true, encoding:UTF-8, label:Batch Script (­ƒÆ╗myhostname)])
	    (types)  : Closure$$EnhancerByCGLIB$$923b74da.call(LinkedHashMap)

As long as the character is in there, the mock is not actually called and the 'bat' step returns null.

I'm on Windows with Java 11 64-bit and Groovy 2.4.12.

Having Unicode in Strings works fine in Jenkins.

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