Skip to content

Commit ce3a962

Browse files
committed
Moved the bursting tests from PosixParserTest to ParserTestCase
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@779606 13f79535-47bb-0310-9956-ffa450edef68
1 parent 94f50c0 commit ce3a962

4 files changed

Lines changed: 126 additions & 79 deletions

File tree

src/test/org/apache/commons/cli/BasicParserTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,29 @@ public void testPartialLongOptionSingleDash() throws Exception
9898
{
9999
// not supported by the BasicParser
100100
}
101+
102+
public void testBursting() throws Exception
103+
{
104+
// not supported by the BasicParser
105+
}
106+
107+
public void testUnrecognizedOptionWithBursting() throws Exception
108+
{
109+
// not supported by the BasicParser
110+
}
111+
112+
public void testMissingArgWithBursting() throws Exception
113+
{
114+
// not supported by the BasicParser
115+
}
116+
117+
public void testStopBursting() throws Exception
118+
{
119+
// not supported by the BasicParser
120+
}
121+
122+
public void testStopBursting2() throws Exception
123+
{
124+
// not supported by the BasicParser
125+
}
101126
}

src/test/org/apache/commons/cli/GnuParserTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,29 @@ public void testPartialLongOptionSingleDash() throws Exception
6969
{
7070
// not supported by the GnuParser
7171
}
72+
73+
public void testBursting() throws Exception
74+
{
75+
// not supported by the GnuParser
76+
}
77+
78+
public void testUnrecognizedOptionWithBursting() throws Exception
79+
{
80+
// not supported by the GnuParser
81+
}
82+
83+
public void testMissingArgWithBursting() throws Exception
84+
{
85+
// not supported by the GnuParser
86+
}
87+
88+
public void testStopBursting() throws Exception
89+
{
90+
// not supported by the GnuParser
91+
}
92+
93+
public void testStopBursting2() throws Exception
94+
{
95+
// not supported by the GnuParser
96+
}
7297
}

src/test/org/apache/commons/cli/ParserTestCase.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,80 @@ public void testReuseOptionsTwice() throws Exception
573573
// expected
574574
}
575575
}
576+
577+
public void testBursting() throws Exception
578+
{
579+
String[] args = new String[] { "-acbtoast", "foo", "bar" };
580+
581+
CommandLine cl = parser.parse(options, args);
582+
583+
assertTrue( "Confirm -a is set", cl.hasOption("a") );
584+
assertTrue( "Confirm -b is set", cl.hasOption("b") );
585+
assertTrue( "Confirm -c is set", cl.hasOption("c") );
586+
assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
587+
assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
588+
}
589+
590+
public void testUnrecognizedOptionWithBursting() throws Exception
591+
{
592+
String[] args = new String[] { "-adbtoast", "foo", "bar" };
593+
594+
try
595+
{
596+
parser.parse(options, args);
597+
fail("UnrecognizedOptionException wasn't thrown");
598+
}
599+
catch (UnrecognizedOptionException e)
600+
{
601+
assertEquals("-adbtoast", e.getOption());
602+
}
603+
}
604+
605+
public void testMissingArgWithBursting() throws Exception
606+
{
607+
String[] args = new String[] { "-acb" };
608+
609+
boolean caught = false;
610+
611+
try
612+
{
613+
parser.parse(options, args);
614+
}
615+
catch (MissingArgumentException e)
616+
{
617+
caught = true;
618+
assertEquals("option missing an argument", "b", e.getOption().getOpt());
619+
}
620+
621+
assertTrue( "Confirm MissingArgumentException caught", caught );
622+
}
623+
624+
public void testStopBursting() throws Exception
625+
{
626+
String[] args = new String[] { "-azc" };
627+
628+
CommandLine cl = parser.parse(options, args, true);
629+
assertTrue( "Confirm -a is set", cl.hasOption("a") );
630+
assertFalse( "Confirm -c is not set", cl.hasOption("c") );
631+
632+
assertTrue( "Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
633+
assertTrue(cl.getArgList().contains("zc"));
634+
}
635+
636+
public void testStopBursting2() throws Exception
637+
{
638+
String[] args = new String[] { "-c", "foobar", "-btoast" };
639+
640+
CommandLine cl = parser.parse(options, args, true);
641+
assertTrue("Confirm -c is set", cl.hasOption("c"));
642+
assertTrue("Confirm 2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
643+
644+
cl = parser.parse(options, cl.getArgs());
645+
646+
assertTrue("Confirm -c is not set", !cl.hasOption("c"));
647+
assertTrue("Confirm -b is set", cl.hasOption("b"));
648+
assertTrue("Confirm arg of -b", cl.getOptionValue("b").equals("toast"));
649+
assertTrue("Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
650+
assertTrue("Confirm value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar"));
651+
}
576652
}

src/test/org/apache/commons/cli/PosixParserTest.java

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -30,85 +30,6 @@ public void setUp()
3030
parser = new PosixParser();
3131
}
3232

33-
public void testBursting() throws Exception
34-
{
35-
String[] args = new String[] { "-acbtoast",
36-
"foo", "bar" };
37-
38-
CommandLine cl = parser.parse(options, args);
39-
40-
assertTrue( "Confirm -a is set", cl.hasOption("a") );
41-
assertTrue( "Confirm -b is set", cl.hasOption("b") );
42-
assertTrue( "Confirm -c is set", cl.hasOption("c") );
43-
assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
44-
assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
45-
}
46-
47-
public void testUnrecognizedOptionWithBursting() throws Exception
48-
{
49-
String[] args = new String[] { "-adbtoast", "foo", "bar" };
50-
51-
try
52-
{
53-
parser.parse(options, args);
54-
fail("UnrecognizedOptionException wasn't thrown");
55-
}
56-
catch (UnrecognizedOptionException e)
57-
{
58-
assertEquals("-adbtoast", e.getOption());
59-
}
60-
}
61-
62-
public void testMissingArgWithBursting() throws Exception
63-
{
64-
String[] args = new String[] { "-acb" };
65-
66-
boolean caught = false;
67-
68-
try
69-
{
70-
parser.parse(options, args);
71-
}
72-
catch (MissingArgumentException e)
73-
{
74-
caught = true;
75-
assertEquals("option missing an argument", "b", e.getOption().getOpt());
76-
}
77-
78-
assertTrue( "Confirm MissingArgumentException caught", caught );
79-
}
80-
81-
public void testStopBursting() throws Exception
82-
{
83-
String[] args = new String[] { "-azc" };
84-
85-
CommandLine cl = parser.parse(options, args, true);
86-
assertTrue( "Confirm -a is set", cl.hasOption("a") );
87-
assertFalse( "Confirm -c is not set", cl.hasOption("c") );
88-
89-
assertTrue( "Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
90-
assertTrue(cl.getArgList().contains("zc"));
91-
}
92-
93-
public void testStopBursting2() throws Exception
94-
{
95-
String[] args = new String[] { "-c",
96-
"foobar",
97-
"-btoast" };
98-
99-
CommandLine cl = parser.parse(options, args, true);
100-
assertTrue("Confirm -c is set", cl.hasOption("c"));
101-
assertTrue("Confirm 2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
102-
103-
cl = parser.parse(options, cl.getArgs());
104-
105-
assertTrue("Confirm -c is not set", !cl.hasOption("c"));
106-
assertTrue("Confirm -b is set", cl.hasOption("b"));
107-
assertTrue("Confirm arg of -b", cl.getOptionValue("b").equals("toast"));
108-
assertTrue("Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
109-
assertTrue("Confirm value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar"));
110-
}
111-
11233
/**
11334
* Real world test with long and short options.
11435
*/

0 commit comments

Comments
 (0)