Search in sources :

Example 6 with OptionsParser.newOptionsParser

use of com.google.devtools.common.options.OptionsParser.newOptionsParser in project bazel by bazelbuild.

the class OptionsParserTest method implicitDependencyHasImplicitDependency.

@Test
public void implicitDependencyHasImplicitDependency() throws Exception {
    OptionsParser parser = OptionsParser.newOptionsParser(ImplicitDependencyOptions.class);
    parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--first=first"));
    assertEquals("first", parser.getOptions(ImplicitDependencyOptions.class).first);
    assertEquals("second", parser.getOptions(ImplicitDependencyOptions.class).second);
    assertEquals("third", parser.getOptions(ImplicitDependencyOptions.class).third);
}
Also used : OptionsParser.newOptionsParser(com.google.devtools.common.options.OptionsParser.newOptionsParser) Test(org.junit.Test)

Example 7 with OptionsParser.newOptionsParser

use of com.google.devtools.common.options.OptionsParser.newOptionsParser in project bazel by bazelbuild.

the class OptionsParserTest method overrideExpansionWithExplicit.

@Test
public void overrideExpansionWithExplicit() throws Exception {
    OptionsParser parser = OptionsParser.newOptionsParser(ExpansionOptions.class);
    parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--first", "--second=second"));
    ExpansionOptions options = parser.getOptions(ExpansionOptions.class);
    assertEquals("second", options.second);
    assertEquals(0, parser.getWarnings().size());
}
Also used : OptionsParser.newOptionsParser(com.google.devtools.common.options.OptionsParser.newOptionsParser) Test(org.junit.Test)

Example 8 with OptionsParser.newOptionsParser

use of com.google.devtools.common.options.OptionsParser.newOptionsParser in project bazel by bazelbuild.

the class OptionsParserTest method asListOfEffectiveOptions.

@Test
public void asListOfEffectiveOptions() throws Exception {
    OptionsParser parser = OptionsParser.newOptionsParser(IntrospectionExample.class);
    parser.parse(OptionPriority.COMMAND_LINE, "source", Arrays.asList("--alpha=one", "--gamma=two"));
    List<OptionValueDescription> result = parser.asListOfEffectiveOptions();
    assertNotNull(result);
    assertEquals(5, result.size());
    HashMap<String, OptionValueDescription> map = new HashMap<String, OptionValueDescription>();
    for (OptionValueDescription description : result) {
        map.put(description.getName(), description);
    }
    assertOptionValue("alpha", "one", OptionPriority.COMMAND_LINE, "source", map.get("alpha"));
    assertOptionValue("beta", "beta", OptionPriority.DEFAULT, null, map.get("beta"));
    assertOptionValue("gamma", "two", OptionPriority.COMMAND_LINE, "source", map.get("gamma"));
    assertOptionValue("delta", "delta", OptionPriority.DEFAULT, null, map.get("delta"));
    assertOptionValue("echo", "echo", OptionPriority.DEFAULT, null, map.get("echo"));
}
Also used : UnparsedOptionValueDescription(com.google.devtools.common.options.OptionsParser.UnparsedOptionValueDescription) OptionValueDescription(com.google.devtools.common.options.OptionsParser.OptionValueDescription) HashMap(java.util.HashMap) OptionsParser.newOptionsParser(com.google.devtools.common.options.OptionsParser.newOptionsParser) Test(org.junit.Test)

Example 9 with OptionsParser.newOptionsParser

use of com.google.devtools.common.options.OptionsParser.newOptionsParser in project bazel by bazelbuild.

the class OptionsParserTest method deprecationWarningForListOption.

@Test
public void deprecationWarningForListOption() throws Exception {
    OptionsParser parser = OptionsParser.newOptionsParser(WarningOptions.class);
    parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--second=a"));
    assertEquals(Arrays.asList("Option 'second' is deprecated"), parser.getWarnings());
}
Also used : OptionsParser.newOptionsParser(com.google.devtools.common.options.OptionsParser.newOptionsParser) Test(org.junit.Test)

Example 10 with OptionsParser.newOptionsParser

use of com.google.devtools.common.options.OptionsParser.newOptionsParser in project bazel by bazelbuild.

the class OptionsParserTest method getOptionValueDescriptionWithValue.

@Test
public void getOptionValueDescriptionWithValue() throws Exception {
    OptionsParser parser = OptionsParser.newOptionsParser(NullTestOptions.class);
    parser.parse(OptionPriority.COMMAND_LINE, "my description", Arrays.asList("--simple=abc"));
    OptionValueDescription result = parser.getOptionValueDescription("simple");
    assertNotNull(result);
    assertEquals("simple", result.getName());
    assertEquals("abc", result.getValue());
    assertEquals(OptionPriority.COMMAND_LINE, result.getPriority());
    assertEquals("my description", result.getSource());
    assertNull(result.getImplicitDependant());
    assertFalse(result.isImplicitDependency());
    assertNull(result.getExpansionParent());
    assertFalse(result.isExpansion());
}
Also used : UnparsedOptionValueDescription(com.google.devtools.common.options.OptionsParser.UnparsedOptionValueDescription) OptionValueDescription(com.google.devtools.common.options.OptionsParser.OptionValueDescription) OptionsParser.newOptionsParser(com.google.devtools.common.options.OptionsParser.newOptionsParser) Test(org.junit.Test)

Aggregations

OptionsParser.newOptionsParser (com.google.devtools.common.options.OptionsParser.newOptionsParser)28 Test (org.junit.Test)27 UnparsedOptionValueDescription (com.google.devtools.common.options.OptionsParser.UnparsedOptionValueDescription)4 OptionValueDescription (com.google.devtools.common.options.OptionsParser.OptionValueDescription)2 HashMap (java.util.HashMap)1