avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 3255] New: - CLArgsParser loops infinitely on OPTIONAL options
Date Fri, 24 Aug 2001 10:23:50 GMT
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3255

           Summary: CLArgsParser loops infinitely on OPTIONAL options
           Product: Avalon
           Version: 4.0b3
          Platform: All
               URL:
        OS/Version: All
            Status: NEW
 Status Whiteboard:
          Keywords:
        Resolution:
          Severity: Normal
          Priority: Other
         Component: Excalibur
        AssignedTo: avalon-dev@jakarta.apache.org
        ReportedBy: frankm@bayarea.net


To reproduce, add the following to 
org.apache.avalon.excalibur.cli.test.ClutilTestCase:

    private static final int                TAINT_OPT         = 'T';

    protected final static CLOptionDescriptor TAINT           =
        new CLOptionDescriptor( "taint",
                                CLOptionDescriptor.ARGUMENT_OPTIONAL,
                                TAINT_OPT,
                                "turn on tainting checks (optional level)." );

    public void testOptionalArgsWithArgShortBeforeOtherOpt()
    {
        //"-T3","-a"
        final CLOptionDescriptor[] options = new CLOptionDescriptor[]
        {
            ALL, TAINT
        };

        final String[] args = new String[] { "-T3", "-a" };

        System.out.println("[before parsing]");

        final CLArgsParser parser = new CLArgsParser( args, options );

        System.out.println("[after parsing]");

        assertNull( parser.getErrorString() );

        final List clOptions = parser.getArguments();
        final int size = clOptions.size();

        assertEquals( size, 2 );
        final CLOption option0 = (CLOption)clOptions.get( 0 );
        assertEquals( option0.getId(), TAINT_OPT );
        assertEquals( option0.getArgument( 0 ), "3" );

        final CLOption option1 = (CLOption)clOptions.get( 1 );
        assertEquals( option1.getId(), ALL_OPT );
        assertEquals( option1.getArgument( 0 ), "" );
    }

    public void testOptionalArgsNoArgShortBeforeOtherOpt()
    {
        //"-T","-a"
        final CLOptionDescriptor[] options = new CLOptionDescriptor[]
        {
            ALL, TAINT
        };

        final String[] args = new String[] { "-T", "-a" };

        System.out.println("[before parsing]");

        final CLArgsParser parser = new CLArgsParser( args, options );

        System.out.println("[after parsing]");

        assertNull( parser.getErrorString() );

        final List clOptions = parser.getArguments();
        final int size = clOptions.size();

        assertEquals( size, 2 );
        final CLOption option0 = (CLOption)clOptions.get( 0 );
        assertEquals( option0.getId(), TAINT_OPT );
        assertEquals( option0.getArgument( 0 ), "" );

        final CLOption option1 = (CLOption)clOptions.get( 1 );
        assertEquals( option1.getId(), ALL_OPT );
        assertEquals( option1.getArgument( 0 ), "" );
    }

Both tests will hang after printing "[before parsing]".  Note that, if the
arguments were reversed ("-a" "-T"), the test would complete.

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Mime
View raw message