Juaneda created GROOVY-9258:
-------------------------------

             Summary: GroovyShell fails to import statically a Hamcrest matcher 
Class
                 Key: GROOVY-9258
                 URL: https://issues.apache.org/jira/browse/GROOVY-9258
             Project: Groovy
          Issue Type: Bug
          Components: GroovyScriptEngine
    Affects Versions: 3.0.0-beta-3, 2.5.8
         Environment: Windows 10 Pro. JDK1.8.0_131-win64 or JRE1.8.0_211-win64 
or JRE1.7-0_80. 
            Reporter: Juaneda
         Attachments: GROOVY-JIRA-x.png

Evaluation of a Hamcrest assertion fails with GroovyShell when importing 
dependencies(static import).

The same code behaves normally when run straight from groovy script level.

See attachement for failure details.

 
{code:java}
@Grapes([
  @Grab('org.hamcrest:hamcrest:2.1')]
)
import static org.hamcrest.Matchers.*
import static org.hamcrest.MatcherAssert.*

import org.codehaus.groovy.control.customizers.ImportCustomizer
import org.codehaus.groovy.control.CompilerConfiguration

def key = 7
assertThat key, allOf(is(key), equalTo(key))

def importCustomizer = new ImportCustomizer()
importCustomizer.addStaticStars 'org.hamcrest.MatcherAssert', 
'org.hamcrest.Matchers'

def configuration = new CompilerConfiguration()
configuration.addCompilationCustomizers importCustomizer

def shell = new GroovyShell(configuration)
def value = "allOf(is($key), equalTo($key))"

def script = """
assertThat $key, $value
"""

def p = shell.evaluate script

println 'OK'
 {code}
 

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to