[ 
https://issues.apache.org/jira/browse/GROOVY-9258?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Juaneda updated GROOVY-9258:
----------------------------
    Description: 
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.

 

Tested with hamcrest 2.1 and hamcrest-all 1.3.

Also tested with hamcrest-core/hamcrest-library 2.1.

 
{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}
 

 

  was:
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}
 

 


> 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: 2.5.8, 3.0.0-beta-3
>         Environment: Windows 10 Pro. JDK1.8.0_131-win64 or JRE1.8.0_211-win64 
> or JRE1.7-0_80. 
>            Reporter: Juaneda
>            Priority: Major
>         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.
>  
> Tested with hamcrest 2.1 and hamcrest-all 1.3.
> Also tested with hamcrest-core/hamcrest-library 2.1.
>  
> {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