Skip to content

Conversation

@triceo
Copy link
Contributor

@triceo triceo commented Nov 30, 2018

The test for #551 is failing on List-based arguments. Before I move on with writing extra coverage, we should probably agree on how to deal with this. WDYT @remkop?


@Test
public void testAtFileSimplified() {
System.setProperty("picocli.useSimplifiedAtFiles", "true");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do this here, because of the change above.

@triceo triceo changed the title Add first failing test Add first failing test for #551 Nov 30, 2018
@triceo
Copy link
Contributor Author

triceo commented Nov 30, 2018

Also added a test to see if the simplified files work with quote trimming.

File file = findFile("/argfile-simplified-quoted.txt");
final App app = new App();
final CommandLine cli = new CommandLine(app);
cli.setTrimQuotes(true);
Copy link
Contributor Author

@triceo triceo Nov 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@remkop Any chance this could also be set through a system property? This way, it prevents Picocli from being used in the simple way: CommandLine.call(...)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sure. Do you want to provide a separate pull request for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look in another PR.

@remkop
Copy link
Owner

remkop commented Nov 30, 2018

Thanks for the PR! It’s my bedtime tonight, I’ll take a look tomorrow.

@remkop
Copy link
Owner

remkop commented Dec 1, 2018

I took a look just now. The approach looks good, but the tests fail in the Travis CI build. Can you make the tests pass?

picocli.CommandLineTest > testAtFileSimplified FAILED
    picocli.CommandLine$UnmatchedArgumentException: Unmatched argument: yet something else
        at picocli.CommandLine$Interpreter.parse(CommandLine.java:6759)
        at picocli.CommandLine$Interpreter.parse(CommandLine.java:6615)
        at picocli.CommandLine.parse(CommandLine.java:722)
        at picocli.CommandLine.populateCommand(CommandLine.java:675)
        at picocli.CommandLineTest.testAtFileSimplified(CommandLineTest.java:3649)

picocli.CommandLineTest > testAtFileSimplifiedWithQuotesTrimmed FAILED
    java.lang.AssertionError: expected: java.lang.String<https://picocli.info/> but was: java.net.URL<https://picocli.info/>
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.failNotEquals(Assert.java:834)
        at org.junit.Assert.assertEquals(Assert.java:118)
        at org.junit.Assert.assertEquals(Assert.java:144)
        at picocli.CommandLineTest.testAtFileSimplifiedWithQuotesTrimmed(CommandLineTest.java:3677)

@remkop
Copy link
Owner

remkop commented Dec 1, 2018

Sorry, I just re-read and saw your first comment. So, you are asking, if I have an option like this:

@Option(names = "-x") List<String> values;

and I give it multiple values, like -x a b c, why does picocli not add all values "a", "b" and "c" to the list but gives an 'Unmatched argument: b" error?

The answer is that default arity for arrays and collection options is 1. If an option needs to consume multiple arguments, you can specify the exact desired arity:

// consume 1 or 2 args for each -y option
// for example: <cmd> -y A -y A B -y E -y F G
// gives y = [A, A, B, E, F, G]
@Option(names = "-y", arity = "1..2") List<String> y;

// consume as many args as possible until the next option
// for example: <cmd> -z A B C D E -y Y
// gives z = [A, B, C, D, E] and y= [Y]
@Option(names = "-z", arity = "1..*") List<String> z;

@triceo
Copy link
Contributor Author

triceo commented Dec 1, 2018

@remkop Thanks, I completely forgot about the arity. The test is fixed now.

Did you have any more tests in mind? If so, please share - otherwise I'll move on to creating the PR wrt. the quote-trimming property.

@remkop
Copy link
Owner

remkop commented Dec 1, 2018

I’m happy to merge this PR when the tests pass.

@codecov-io
Copy link

Codecov Report

Merging #558 into master will increase coverage by 0.09%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #558      +/-   ##
============================================
+ Coverage     89.04%   89.13%   +0.09%     
- Complexity      285      286       +1     
============================================
  Files             4        4              
  Lines          3961     3967       +6     
  Branches        974      976       +2     
============================================
+ Hits           3527     3536       +9     
+ Misses          216      212       -4     
- Partials        218      219       +1
Impacted Files Coverage Δ Complexity Δ
src/main/java/picocli/CommandLine.java 89.17% <0%> (+0.1%) 161% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95c9b99...2df98ba. Read the comment docs.

@remkop remkop merged commit 950816e into remkop:master Dec 1, 2018
@remkop
Copy link
Owner

remkop commented Dec 1, 2018

Merged. Thanks for the PR!
I’ll update the release notes later.

@triceo triceo deleted the tests-for-551 branch December 1, 2018 08:06
@remkop
Copy link
Owner

remkop commented Dec 1, 2018

FYI: I created #561 as a more strategic solution for improving the convenience methods.

@triceo
Copy link
Contributor Author

triceo commented Dec 1, 2018

@remkop Thanks for merging this PR, I also submitted #562 in the meantime. (Although #561 will definitely be useful and will supersede my solution.)

@remkop remkop added this to the 3.8.1 milestone Dec 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants