From: <cr...@us...> - 2009-01-26 10:18:20
|
Revision: 4914 http://jnode.svn.sourceforge.net/jnode/?rev=4914&view=rev Author: crawley Date: 2009-01-26 10:18:09 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Implemented 'for' loop execution. Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/bjorne/ForCommandNode.java trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/ForCommandNode.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/bjorne/ForCommandNode.java 2009-01-26 09:39:14 UTC (rev 4913) +++ trunk/shell/src/shell/org/jnode/shell/bjorne/ForCommandNode.java 2009-01-26 10:18:09 UTC (rev 4914) @@ -20,6 +20,8 @@ */ package org.jnode.shell.bjorne; +import org.jnode.shell.ShellException; + public class ForCommandNode extends CommandNode { private final CommandNode body; @@ -60,7 +62,12 @@ } @Override - public int execute(BjorneContext context) { - return -1; + public int execute(BjorneContext context) throws ShellException { + int rc = 0; + for (BjorneToken word : words) { + context.setVariable(var.getText(), word.getText()); + rc = body.execute(context); + } + return rc; } } Modified: trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-01-26 09:39:14 UTC (rev 4913) +++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-01-26 10:18:09 UTC (rev 4914) @@ -19,6 +19,21 @@ <rc>0</rc> </testSpec> <testSpec> + <title>$?</title> + <command>test</command> + <runMode>AS_SCRIPT</runMode> + <script>#!bjorne +true +echo $? +false +echo $? +</script> + <output>0 +1 +</output> + <rc>0</rc> + </testSpec> + <testSpec> <title>if ... then ... fi</title> <command>test</command> <runMode>AS_SCRIPT</runMode> @@ -30,18 +45,44 @@ <rc>0</rc> </testSpec> <testSpec> - <title>$?</title> + <title>if ... then ... else ... fi</title> <command>test</command> <runMode>AS_SCRIPT</runMode> <script>#!bjorne -true -echo $? -false -echo $? -</script> - <output>0 -1 +if true ; then echo HI ; else echo HO; fi +if false ; then echo HI ; else echo HO; fi + </script> + <output>HI +HO </output> <rc>0</rc> </testSpec> + <testSpec> + <title>if ... then ... elif ... else ... fi</title> + <command>test</command> + <runMode>AS_SCRIPT</runMode> + <script>#!bjorne +if true ; then echo HI ; elif false ; then echo HO ; else echo HUM; fi +if false ; then echo HI ; elif true ; then echo HO ; else echo HUM; fi +if false ; then echo HI ; elif false ; then echo HO ; else echo HUM; fi + </script> + <output>HI +HO +HUM +</output> + <rc>0</rc> + </testSpec> + <testSpec> + <title>for ... do ... done</title> + <command>test</command> + <runMode>AS_SCRIPT</runMode> + <script>#!bjorne +for A in 1 2 3 ; do echo $A ; done + </script> + <output>1 +2 +3 +</output> + <rc>0</rc> + </testSpec> </testSpecs> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |