You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/03/19 12:04:02 UTC

cvs commit: jakarta-avalon-excalibur/cli/src/test/org/apache/avalon/excalibur/cli/test ClutilTestCase.java

donaldp     02/03/19 03:04:02

  Modified:    cli/src/test/org/apache/avalon/excalibur/cli/test
                        ClutilTestCase.java
  Log:
  Add unit test to test for null long forms or null descriptions
  
  Revision  Changes    Path
  1.12      +80 -36    jakarta-avalon-excalibur/cli/src/test/org/apache/avalon/excalibur/cli/test/ClutilTestCase.java
  
  Index: ClutilTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/cli/src/test/org/apache/avalon/excalibur/cli/test/ClutilTestCase.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ClutilTestCase.java	16 Mar 2002 00:04:27 -0000	1.11
  +++ ClutilTestCase.java	19 Mar 2002 11:04:02 -0000	1.12
  @@ -14,6 +14,7 @@
   import org.apache.avalon.excalibur.cli.CLOption;
   import org.apache.avalon.excalibur.cli.CLOptionDescriptor;
   import org.apache.avalon.excalibur.cli.ParserControl;
  +import org.apache.avalon.excalibur.cli.CLUtil;
   
   /**
    *
  @@ -22,42 +23,32 @@
   public final class ClutilTestCase
       extends TestCase
   {
  -    public ClutilTestCase()
  +    private final static String[] ARGLIST1 = new String[]
       {
  -        this( "Command Line Interpreter Test Case" );
  -    }
  +        "--you", "are", "--all", "-cler", "kid"
  +    };
   
  -    public ClutilTestCase( String name )
  +    private final static String[] ARGLIST2 = new String[]
       {
  -        super( name );
  -    }
  +        "-Dstupid=idiot", "are", "--all", "here", "-d"
  +    };
   
  -    private final static String[] ARGLIST1 =
  -        {
  -            "--you", "are", "--all", "-cler", "kid"
  -        };
  -
  -    private final static String[] ARGLIST2 =
  -        {
  -            "-Dstupid=idiot", "are", "--all", "here", "-d"
  -        };
  -
  -    private final static String[] ARGLIST3 =
  -        {
  -            //duplicates
  -            "-Dstupid=idiot", "are", "--all", "--all", "here"
  -        };
  +    private final static String[] ARGLIST3 = new String[]
  +    {
  +        //duplicates
  +        "-Dstupid=idiot", "are", "--all", "--all", "here"
  +    };
   
  -    private final static String[] ARGLIST4 =
  -        {
  -            //incompatable (blee/all)
  -            "-Dstupid=idiot", "are", "--all", "--blee", "here"
  -        };
  +    private final static String[] ARGLIST4 = new String[]
  +    {
  +        //incompatable (blee/all)
  +        "-Dstupid=idiot", "are", "--all", "--blee", "here"
  +    };
   
  -    private final static String[] ARGLIST5 =
  -        {
  -            "-f", "myfile.txt"
  -        };
  +    private final static String[] ARGLIST5 = new String[]
  +    {
  +        "-f", "myfile.txt"
  +    };
   
       private static final int DEFINE_OPT = 'D';
       private static final int CASE_CHECK_OPT = 'd';
  @@ -115,6 +106,16 @@
                                   TAINT_OPT,
                                   "turn on tainting checks (optional level)." );
   
  +    public ClutilTestCase()
  +    {
  +        this( "Command Line Interpreter Test Case" );
  +    }
  +
  +    public ClutilTestCase( String name )
  +    {
  +        super( name );
  +    }
  +
       public static void main( final String[] args )
       {
           final ClutilTestCase test = new ClutilTestCase();
  @@ -455,12 +456,6 @@
               YOU, ALL, CLEAR1, CLEAR2, CLEAR3, CLEAR5
           };
   
  -        //duplicate as
  -        final String[] DUPLICATE_ARGLIST =
  -            {
  -                "--you", "are", "--all", "-clear", "kid"
  -            };
  -
           final CLArgsParser parser = new CLArgsParser( ARGLIST1, options );
   
           assertNull( parser.getErrorString(), parser.getErrorString() );
  @@ -554,5 +549,54 @@
           CLOption optionByName = parser.getArgumentByName( FILE.getName() );
           assertNotNull( optionByName );
           assertEquals( FILE_OPT, optionByName.getId() );
  +    }
  +
  +    /**
  +     * Test that you can have null long forms.
  +     */
  +    public void testNullLongForm()
  +    {
  +        final CLOptionDescriptor test =
  +            new CLOptionDescriptor( null,
  +                                    CLOptionDescriptor.ARGUMENT_DISALLOWED,
  +                                    'n',
  +                                    "test null long form" );
  +
  +        final String[] args = {"-n", "testarg"};
  +        final CLOptionDescriptor[] options = {test};
  +        final CLArgsParser parser = new CLArgsParser( args, options );
  +
  +        final CLOption optionByID = parser.getArgumentById( 'n' );
  +        assertNotNull( optionByID );
  +        assertEquals( 'n', optionByID.getId() );
  +
  +        final CLOption optionByName = parser.getArgumentByName( FILE.getName() );
  +        assertNull( "Looking for non-existent option by name", optionByName );
  +    }
  +
  +    /**
  +     * Test that you can have null descriptions.
  +     */
  +    public void testNullDescription()
  +    {
  +        final CLOptionDescriptor test =
  +            new CLOptionDescriptor( "nulltest",
  +                                    CLOptionDescriptor.ARGUMENT_DISALLOWED,
  +                                    'n',
  +                                    null );
  +
  +        final String[] args = {"-n", "testarg"};
  +        final CLOptionDescriptor[] options = {test};
  +        final CLArgsParser parser = new CLArgsParser( args, options );
  +
  +        final CLOption optionByID = parser.getArgumentById( 'n' );
  +        assertNotNull( optionByID );
  +        assertEquals( 'n', optionByID.getId() );
  +
  +        final StringBuffer sb = CLUtil.describeOptions( options );
  +        final String lineSeparator = System.getProperty( "line.separator" );
  +        assertEquals( "Testing display of null description",
  +                      "\t-n, --nulltest" + lineSeparator,
  +                      sb.toString() );
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>