JMeter中的Groovy脚本:错误"除了' \ n'&#39 ;;无论如何得到它@ line ..."包含使用GString插值的闭包

时间:2015-03-02 07:33:19

标签: groovy scripting jmeter jsr223

我有这个groovy脚本定义了一个正常工作的闭包。

escape = { str -> 
    str.collect{ ch ->
        def escaped = ch
        switch (ch) {
            case "\"" : escaped = "\\\"" ; break
            // other cases omitted for simplicity
        }
        escaped
    }.join()
}

assert escape("\"") == "\\\""       //Sucess

但是当我添加另一个使用GString插值的闭包时。

escape = { str -> 
    //Same as above
}

dummy = {
    aStr = "abc"
    "123${aStr}456"
}

//Compilation fails

我收到错误

javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script650.groovy: 7: expecting anything but ''\n''; got it anyway @ line 7, column 39.
        case "\"" : escaped = "\\"" ; break
                                 ^

1 error

即使添加了关闭的注释。

escape = { str -> 
    //Same as above
}

/*dummy = {
    aStr = "abc"
    "123${aStr}456"
}*/

//Compilation fails

仍然失败!是什么给了什么?

0 个答案:

没有答案