Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for #964 #1080

Merged
merged 1 commit into from Feb 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/test/java/picocli/SynopsisOrderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package picocli;

import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.ProvideSystemProperty;
import org.junit.contrib.java.lang.system.SystemErrRule;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Help;

import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
import static picocli.TestUtil.usageString;

public class SynopsisOrderTest {
@Rule
public final ProvideSystemProperty ansiOFF = new ProvideSystemProperty("picocli.ansi", "false");
@Rule
public final SystemErrRule systemErrRule = new SystemErrRule().enableLog().muteForSuccessfulTests();

@Command()
class SynopsisOrder {
class Group {
@CommandLine.Option(names = "--option1", required = true)
String value1;
}

class AllGroups {
@CommandLine.ArgGroup(exclusive = false, multiplicity = "1", order = 1) Group group;
@CommandLine.Option(names = "--option2", required = true, order = 2) String value2;
}

@ArgGroup(exclusive = true, multiplicity = "1")
AllGroups allGroups;
}

@Test
public void testSynopsisOrderForArgGroup() {
String result = usageString(new SynopsisOrder(), Help.Ansi.OFF);
assertEquals(format("" +
"Usage: <main class> (--option1=<value1> | (--option2=<value2>))%n" +
" --option1=<value1>%n" +
" --option2=<value2>%n"), result);
}
}