[#928] Improve debug tracing: show command user object identity hashcode and prefix "Processing argument..." with argument index.

This commit is contained in:
Remko Popma
2020-01-25 02:06:31 +09:00
parent ba5c7a1869
commit daee860fee

View File

@@ -19,7 +19,8 @@ class CommandLineTest {
final String PROPERTY = "picocli.trace"
String old = System.getProperty(PROPERTY)
System.setProperty(PROPERTY, "true") // Groovy puts value 'true' if -D specified without value on command line
CommandLine commandLine = new CommandLine(new Params())
Params params = new Params()
CommandLine commandLine = new CommandLine(params)
commandLine.parse("-o", "anOption", "A", "B")
System.setErr(originalErr)
if (old == null) {
@@ -30,10 +31,10 @@ class CommandLineTest {
String expected = String.format("" +
"[picocli INFO] Picocli version: %s%n" +
"[picocli INFO] Parsing 4 command line args [-o, anOption, A, B]%n" +
"[picocli INFO] Setting field Object picocli.groovy.CommandLineTest\$Params.option to 'anOption' (was 'null') for option -o%n" +
"[picocli INFO] Adding [A] to field String[] picocli.groovy.CommandLineTest\$Params.positional for args[0..*] at position 0%n" +
"[picocli INFO] Adding [B] to field String[] picocli.groovy.CommandLineTest\$Params.positional for args[0..*] at position 1%n",
CommandLine.versionString())
'[picocli INFO] Setting field Object picocli.groovy.CommandLineTest\$Params.option to \'anOption\' (was \'null\') for option -o on Params@%2$s%n' +
'[picocli INFO] Adding [A] to field String[] picocli.groovy.CommandLineTest\$Params.positional for args[0..*] at position 0 on Params@%2$s%n' +
'[picocli INFO] Adding [B] to field String[] picocli.groovy.CommandLineTest\$Params.positional for args[0..*] at position 1 on Params@%2$s%n',
CommandLine.versionString(), Integer.toHexString(System.identityHashCode(params)))
String actual = new String(baos.toByteArray(), "UTF8")
// println actual
assertEquals(expected, actual)