geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r409764 - in /geronimo/sandbox/gshell/trunk/gshell-core/src: main/grammar/ main/java/org/apache/geronimo/gshell/command/ main/java/org/apache/geronimo/gshell/commandline/ main/java/org/apache/geronimo/gshell/console/ test/java/org/apache/ge...
Date Fri, 26 May 2006 22:05:52 GMT
Author: jdillon
Date: Fri May 26 15:05:52 2006
New Revision: 409764

URL: http://svn.apache.org/viewvc?rev=409764&view=rev
Log:
Improved test coverage
Fixed problem with single expression w/ ';' terminators

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandSupportTest.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/IOTest.java
  (with props)
Modified:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt   (contents,
props changed)
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/IO.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/parser/CommandLineParserTest.java

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt?rev=409764&r1=409763&r2=409764&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt Fri May
26 15:05:52 2006
@@ -62,11 +62,11 @@
 
 SKIP :
 {
-  " "
-| "\t"
-| "\n"
-| "\r"
-| "\f"
+    " "
+|   "\t"
+|   "\n"
+|   "\r"
+|   "\f"
 }
 
 //
@@ -75,7 +75,7 @@
 
 SPECIAL_TOKEN :
 {
-  < COMMENT: "#" (~["\n", "\r"])* ("\n" | "\r" | "\r\n")? >
+    < COMMENT: "#" (~["\n", "\r"])* ("\n" | "\r" | "\r\n")? >
 }
 
 //
@@ -84,7 +84,7 @@
 
 TOKEN :
 {
-  < STRING:
+    < STRING:
       (   (~["\"","\\"," ","\t","\n","\r","\f",";"])
         | ("\\"
             ( ["n","t","b","r","f","\\","'","\"",";"]
@@ -93,9 +93,9 @@
             )
           )
       )+
-  >
+    >
 |
-  < OPAQUE_STRING:
+    < OPAQUE_STRING:
       "'"
       (   (~["\"","\\","\n","\r"])
         | ("\\"
@@ -106,9 +106,9 @@
           )
       )*
       "'"
-  >
+    >
 |
-  < QUOTED_STRING:
+    < QUOTED_STRING:
       "\""
       (   (~["\"","\\","\n","\r"])
         | ("\\"
@@ -119,7 +119,7 @@
           )
       )*
       "\""
-  >
+    >
 }
 
 //
@@ -128,7 +128,7 @@
 
 TOKEN :
 {
-  < SEMICOLON: ";" >
+    < SEMICOLON: ";" >
 }
 
 
@@ -137,7 +137,7 @@
 ASTCommandLine commandLine() #CommandLine: {}
 {
     (
-        expression() ( ";" expression() )* | <EOF>
+        expression() ( ";" ( expression() )? )* | <EOF>
     )
     {
         return jjtThis;

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java?rev=409764&r1=409763&r2=409764&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
Fri May 26 15:05:52 2006
@@ -31,6 +31,7 @@
     protected Log log;
     
     private String name;
+
     private CommandContext context;
     
     protected CommandSupport(final String name) {
@@ -42,15 +43,21 @@
     }
     
     public void setName(final String name) {
-        assert name != null;
-        assert name.trim().length() != 0;
+        if (name == null) {
+            throw new IllegalArgumentException("Name is null");
+        }
+        if (name.trim().length() == 0) {
+            throw new IllegalArgumentException("Name is empty");
+        }
         
         this.name = name;
     }
     
     public String getName() {
-        assert name != null;
-        
+        if (name == null) {
+            throw new IllegalStateException("Name was not set");
+        }
+
         return name;
     }
     

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java?rev=409764&r1=409763&r2=409764&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
Fri May 26 15:05:52 2006
@@ -16,6 +16,8 @@
 
 package org.apache.geronimo.gshell.commandline;
 
+import org.apache.geronimo.gshell.commandline.parser.CommandLineParser;
+
 /**
  * ???
  *
@@ -23,6 +25,12 @@
  */
 public class CommandLineBuilder
 {
+    private CommandLineParser parser;
+
+    public CommandLineBuilder() {
+        this.parser = new CommandLineParser();
+    }
+
     public CommandLine create() {
         //
         // TODO:

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/IO.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/IO.java?rev=409764&r1=409763&r2=409764&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/IO.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/IO.java
Fri May 26 15:05:52 2006
@@ -65,10 +65,23 @@
      */
     public final PrintWriter err;
 
+    /**
+     * Construct a new IO container.
+     *
+     * @param in    The input steam; must not be null
+     * @param out   The output stream; must not be null
+     * @param err   The error output stream; must not be null
+     */
     public IO(final InputStream in, final PrintStream out, final PrintStream err) {
-        assert in != null;
-        assert out != null;
-        assert err != null;
+        if (in == null) {
+            throw new IllegalArgumentException("Input stream is null");
+        }
+        if (out == null) {
+            throw new IllegalArgumentException("Output stream is null");
+        }
+        if (err == null) {
+            throw new IllegalArgumentException("Error output stream is null");
+        }
 
         this.inputStream = in;
         this.outputStream = out;
@@ -78,11 +91,17 @@
         this.out = new PrintWriter(out);
         this.err = new PrintWriter(err);
     }
-    
+
+    /**
+     * Helper which uses current values from {@link System}.
+     */
     public IO() {
         this(System.in, System.out, System.err);
     }
-    
+
+    /**
+     * Flush both output streams.
+     */
     public void flush() {
         out.flush();
         err.flush();

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandSupportTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandSupportTest.java?rev=409764&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandSupportTest.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandSupportTest.java
Fri May 26 15:05:52 2006
@@ -0,0 +1,74 @@
+/*
+ * 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.command;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the {@link CommandSupport} class.
+ *
+ * @version $Id$
+ */
+public class CommandSupportTest
+    extends TestCase
+{
+    public void testConstructorNameIsNull() throws Exception {
+        try {
+            new MockCommand(null);
+            fail("Accepted null value");
+        }
+        catch (IllegalArgumentException expected) {
+            // ignore
+        }
+    }
+
+    public void testSetNameIsNull() throws Exception {
+        try {
+            MockCommand cmd = new MockCommand();
+            cmd.setName(null);
+            fail("Accepted null value");
+        }
+        catch (IllegalArgumentException expected) {
+            // ignore
+        }
+    }
+
+    public void testGetNameNotSet() throws Exception {
+        try {
+            MockCommand cmd = new MockCommand();
+            cmd.getName();
+            fail("Get returned when name was unset");
+        }
+        catch (IllegalStateException expected) {
+            // ignore
+        }
+    }
+
+    //
+    // MockCommand
+    //
+
+    private static class MockCommand
+        extends CommandSupport
+    {
+        public MockCommand() {}
+
+        public MockCommand(final String name) {
+            super(name);
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandSupportTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java?rev=409764&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java
Fri May 26 15:05:52 2006
@@ -0,0 +1,36 @@
+/*
+ * 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.commandline;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the {@link CommandLineBuilder} class.
+ *
+ * @version $Id$
+ */
+public class CommandLineBuilderTest
+    extends TestCase
+{
+    public void testConstructor() throws Exception {
+        //
+        // NOTE: This is a lame duck test, remove once there is functionality to test
+        //
+        
+        new CommandLineBuilder();
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/parser/CommandLineParserTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/parser/CommandLineParserTest.java?rev=409764&r1=409763&r2=409764&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/parser/CommandLineParserTest.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/parser/CommandLineParserTest.java
Fri May 26 15:05:52 2006
@@ -36,6 +36,10 @@
         CommandLineParser parser = new CommandLineParser();
         ASTCommandLine cl = parser.parse(reader);
 
+        //
+        // TODO: Remove eventually, may want to make nodes use logging to dump too
+        //
+
         cl.dump("> ");
 
         assertNotNull(cl);
@@ -186,6 +190,54 @@
 
         //
         // TODO: Verify 2 expressions
+        //
+    }
+
+    public void testCompoundCommandLine2() throws Exception {
+        String input = "a b c;";
+
+        ASTCommandLine cl = parse(input);
+
+        assertEquals(1, cl.jjtGetNumChildren());
+
+        //
+        // TODO: Verify ...
+        //
+    }
+
+    public void testCompoundCommandLine3() throws Exception {
+        String input = "a b c;;;;";
+
+        ASTCommandLine cl = parse(input);
+
+        assertEquals(1, cl.jjtGetNumChildren());
+
+        //
+        // TODO: Verify ...
+        //
+    }
+
+    public void testCompoundCommandLine4() throws Exception {
+        String input = "a b c;;;;d e f";
+
+        ASTCommandLine cl = parse(input);
+
+        assertEquals(2, cl.jjtGetNumChildren());
+
+        //
+        // TODO: Verify ...
+        //
+    }
+
+    public void testNotCompoundCommandLine1() throws Exception {
+        String input = "a b c\\; d e f";
+
+        ASTCommandLine cl = parse(input);
+
+        assertEquals(1, cl.jjtGetNumChildren());
+
+        //
+        // TODO: Verify 1 expression
         //
     }
 }

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/IOTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/IOTest.java?rev=409764&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/IOTest.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/IOTest.java
Fri May 26 15:05:52 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.console;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the {@link IO} class.
+ *
+ * @version $Id$
+ */
+public class IOTest
+    extends TestCase
+{
+    public void testConstructorArgs() throws Exception {
+        try {
+            new IO(null, null, null);
+            fail("Accepted null value");
+        }
+        catch (IllegalArgumentException expected) {
+            // ignore
+        }
+
+        try {
+            new IO(System.in, null, null);
+            fail("Accepted null value");
+        }
+        catch (IllegalArgumentException expected) {
+            // ignore
+        }
+
+        try {
+            new IO(System.in, System.out, null);
+            fail("Accepted null value");
+        }
+        catch (IllegalArgumentException expected) {
+            // ignore
+        }
+
+        // Happy day...
+        new IO(System.in, System.out, System.err);
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/IOTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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



Mime
View raw message