Skip to content

Commit

Permalink
fix a bug in open-source args parsing.
Browse files Browse the repository at this point in the history
Fixes issue 319.

R=johnlenz
DELTA=24  (23 added, 0 deleted, 1 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=299


git-svn-id: https://closure-compiler.googlecode.com/svn/trunk@700 b0f006be-c8cd-11de-a2e8-8d36a3108c74
  • Loading branch information
nicksantos@google.com committed Jan 18, 2011
1 parent 840ddca commit 43c245f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/com/google/javascript/jscomp/CommandLineRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ public BooleanOptionHandler(

@Override
public int parseArguments(Parameters params) throws CmdLineException {
String param = params.getParameter(0);
String param = null;
try {
param = params.getParameter(0);
} catch (CmdLineException e) {}

if (param == null) {
setter.addValue(true);
return 0;
Expand Down
19 changes: 19 additions & 0 deletions test/com/google/javascript/jscomp/CommandLineRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public class CommandLineRunnerTest extends TestCase {
private ByteArrayOutputStream outReader = null;
private ByteArrayOutputStream errReader = null;

// If set, this will be appended to the end of the args list.
// For testing args parsing.
private String lastArg = null;

// If set to true, uses comparison by string instead of by AST.
private boolean useStringComparison = false;

Expand Down Expand Up @@ -96,6 +100,7 @@ public void setUp() throws Exception {
super.setUp();
externs = DEFAULT_EXTERNS;
lastCompiler = null;
lastArg = null;
outReader = new ByteArrayOutputStream();
errReader = new ByteArrayOutputStream();
useStringComparison = false;
Expand Down Expand Up @@ -592,6 +597,16 @@ public void testVersionFlag() {
"Version: "));
}

public void testVersionFlag2() {
lastArg = "--version";
testSame("");
assertEquals(
0,
new String(errReader.toByteArray()).indexOf(
"Closure Compiler (http://code.google.com/closure/compiler)\n" +
"Version: "));
}

public void testPrintAstFlag() {
args.add("--print_ast=true");
testSame("");
Expand Down Expand Up @@ -723,6 +738,10 @@ private CommandLineRunner createCommandLineRunner(String[] original) {
}
}

if (lastArg != null) {
args.add(lastArg);
}

String[] argStrings = args.toArray(new String[] {});
return new CommandLineRunner(
argStrings,
Expand Down

0 comments on commit 43c245f

Please sign in to comment.