This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-4721
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY-4721 by this push:
new fef0b8cf6a GROOVY-4721: Failed to find bound variables in Groovysh
fef0b8cf6a is described below
commit fef0b8cf6a6e7c4a472afa207808d091fdac354d
Author: Paul King <[email protected]>
AuthorDate: Thu Apr 10 03:07:20 2025 +0900
GROOVY-4721: Failed to find bound variables in Groovysh
Co-authored-by: Daniel Sun <[email protected]>
---
.../org/apache/groovy/groovysh/Groovysh.groovy | 2 +-
.../org/apache/groovy/groovysh/GroovyshTest.groovy | 23 ++--------------------
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
index 8be4ba6795..6f1553c77d 100644
---
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
+++
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
@@ -291,7 +291,7 @@ try {$COLLECTED_BOUND_VARS_MAP_VARNAME[\"$varname\"] =
$varname;
// Evaluate the current buffer w/imports and dummy statement
List<String> buff
if (variableBlocks) {
- buff = [importsSpec] + ['try {', 'true'] + current + ['} finally
{' + variableBlocks + '}']
+ buff = [importsSpec] + ['try {', 'true'] + current +
[variableBlocks, '} finally {' + variableBlocks + '}']
} else {
buff = [importsSpec] + ['true'] + current
}
diff --git
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy
index bdec18b4cf..504f3b123e 100644
---
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy
+++
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy
@@ -19,15 +19,13 @@
package org.apache.groovy.groovysh
import groovy.test.GroovyTestCase
-import groovy.test.NotYetImplemented
+import org.apache.groovy.groovysh.completion.antlr4.ReflectionCompleter
import org.apache.groovy.groovysh.completion.ReflectionCompletionCandidate
import org.apache.groovy.groovysh.completion.TokenUtilTest
-import org.apache.groovy.groovysh.completion.antlr4.ReflectionCompleter
import org.codehaus.groovy.GroovyException
import org.codehaus.groovy.control.MultipleCompilationErrorsException
import org.codehaus.groovy.tools.shell.IO
import org.fusesource.jansi.AnsiOutputStream
-import org.junit.jupiter.api.Disabled
class GroovyshTest extends GroovyTestCase {
@@ -394,19 +392,10 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
- // groovy:000> int x = 3
- // ===> 3
- // groovy:000> x
- // Unknown property: x
- // groovy:000> x = 3
- // ===> 3
- // groovy:000> x
- // ===> 3
- // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('x = 3')
+ groovysh.execute('int x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
@@ -414,14 +403,6 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
- // collecting variables relies on GROOVY-4721, e.g. accessing variable
declared in try block is in scope in finally block
- // but after GROOVY-4721 is fixed, this test will fail, but it is aligned
with the behavior of the groovySh:
- // groovy:000> int x, y, z
- // ===> 0
- // groovy:000> y
- // Unknown property: y
- // groovy:000>
- @NotYetImplemented
void testBoundVarmultiple() {
Groovysh groovysh = createGroovysh()
groovysh.execute('int x, y, z')