Skip to content

Commit

Permalink
[#1531] add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Dec 27, 2021
1 parent 80d021b commit 42ebe77
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/test/java/picocli/Issue1531ResetOptionMethods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package picocli;

import org.junit.Ignore;
import org.junit.Test;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

import java.util.Collections;
import java.util.List;

import static org.junit.Assert.*;

// https://github.com/remkop/picocli/issues/1531
public class Issue1531ResetOptionMethods {

@Command
static class MyCommand {
List<String> modules;

@Option(names = "-c", description = "comps", split = ",")
List<String> comps;

@Option(names = "-m", description = "modules", split = ",")
public void setModules(final List<String> modules) {
this.modules = modules;
}
}

@Ignore("https://github.com/remkop/picocli/issues/1531")
@Test
public void testResetOptionMethodsOnReuse() {
MyCommand myCommand = new MyCommand();
CommandLine cmd = new CommandLine(myCommand);

cmd.parseArgs(); // first, invoke with no args
assertNull(myCommand.comps);
assertNull(myCommand.modules);

// now invoke with some arguments
cmd.parseArgs("-c c1 -m m1".split(" "));
assertEquals(Collections.singletonList("c1"), myCommand.comps);
assertEquals(Collections.singletonList("m1"), myCommand.modules);

cmd.parseArgs(); // finally, invoke with no args again
assertNull(myCommand.comps);
assertNull(myCommand.modules);
}
}

0 comments on commit 42ebe77

Please sign in to comment.