geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r411681 - in /geronimo/sandbox/gshell/trunk: gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/ gshell-testsuite/src/test/java/org/apache/geronimo/gshell/tests...
Date Mon, 05 Jun 2006 05:50:31 GMT
Author: jdillon
Date: Sun Jun  4 22:50:31 2006
New Revision: 411681

URL: http://svn.apache.org/viewvc?rev=411681&view=rev
Log:
Fixed bug when evaluating stuff like 'set a=1; echo ${a}', the expression parser only takes
a snapshot of variables, so need to create a new one for each node

Added:
    geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/MultiExpressionVariablesTest.java
  (with props)
Modified:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java?rev=411681&r1=411680&r2=411681&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
Sun Jun  4 22:50:31 2006
@@ -45,15 +45,12 @@
 
     private final Shell shell;
 
-    private final VariableExpressionParser exprParser;
-
     public ExecutingVisitor(final Shell shell) {
         if (shell == null) {
             throw new NullArgumentException("shell");
         }
 
         this.shell = shell;
-        this.exprParser = new VariableExpressionParser(shell.getVariables());
     }
 
     public Object visit(final SimpleNode node, final Object data) {
@@ -127,6 +124,7 @@
     //
 
     public Object visit(final ASTQuotedString node, final Object data) {
+        VariableExpressionParser exprParser = new VariableExpressionParser(shell.getVariables());
         String value = exprParser.parse(node.getValue());
         return appendString(value, data);
     }
@@ -136,6 +134,7 @@
     }
 
     public Object visit(final ASTPlainString node, final Object data) {
+        VariableExpressionParser exprParser = new VariableExpressionParser(shell.getVariables());
         String value = exprParser.parse(node.getValue());
         return appendString(value, data);
     }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java?rev=411681&r1=411680&r2=411681&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java
Sun Jun  4 22:50:31 2006
@@ -50,7 +50,7 @@
 
     public void testVariable() throws Exception {
         String myvar = "this is my variable";
-        parser.getVariables().put("my.var", myvar);
+        parser.setVariable("my.var", myvar);
 
         String value = "${my.var}";
         String result = parser.parse(value);
@@ -59,8 +59,8 @@
 
     public void testFlatVariable() throws Exception {
         String myvar = "this is my variable";
-        parser.getVariables().put("my.var", myvar);
-        parser.getVariables().put("my", "not used");
+        parser.setVariable("my.var", myvar);
+        parser.setVariable("my", "not used");
 
         String value = "${my.var}";
         String result = parser.parse(value);

Added: geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/MultiExpressionVariablesTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/MultiExpressionVariablesTest.java?rev=411681&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/MultiExpressionVariablesTest.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/MultiExpressionVariablesTest.java
Sun Jun  4 22:50:31 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell.testsuite;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.gshell.Shell;
+import org.apache.geronimo.gshell.console.IO;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+
+/**
+ * ???
+ *
+ * @version $Id$
+ */
+public class MultiExpressionVariablesTest
+    extends TestCase
+{
+    public void testSimple() throws Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        IO io = new IO(System.in, out);
+
+        Shell shell = new Shell(io);
+        shell.execute("set a=1; echo ${a}");
+
+        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+
+        String line1 = reader.readLine();
+        assertNotNull(line1);
+        assertEquals("1", line1);
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/MultiExpressionVariablesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/MultiExpressionVariablesTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/MultiExpressionVariablesTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message