aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2016-04-05 20:20:51 +0000
committerGravatar Lukacs Berki <lberki@google.com>2016-04-07 11:40:50 +0000
commit4f0fbe1b09333806cce76b75214e98c7684766e0 (patch)
tree9a5475842d119646267465a9cb7b36357f97a5c8 /src/test/java/com
parent351475627b9e94e5afdf472cbf465f49c433a25e (diff)
Add tests documenting the way rc-options are combined
Note that this patch does not change any semantics, it just adds tests. In this way, we have a machine-checkable (hence up to date) documentation of the semantics of how rc options are handled. In particular, our semantics is that - options get collected from all rc files, - more specific options take precedence over less specific ones, and - for equally specific options, the most specific rc file takes precedence. -- Change-Id: I6abadd15eb02a2f952debc3b005668e04dccd62a Reviewed-on: https://bazel-review.googlesource.com/#/c/3241 MOS_MIGRATED_REVID=119083139
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcherRcoptionsTest.java104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcherRcoptionsTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcherRcoptionsTest.java
index 000f79d42b..854f25e918 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcherRcoptionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcherRcoptionsTest.java
@@ -49,6 +49,9 @@ public class BlazeCommandDispatcherRcoptionsTest {
public static class FooOptions extends OptionsBase {
@Option(name = "numoption", defaultValue = "0")
public int numOption;
+
+ @Option(name = "stringoption", defaultValue = "[unspecified]")
+ public String stringOption;
}
@Command(
@@ -71,9 +74,33 @@ public class BlazeCommandDispatcherRcoptionsTest {
public void editOptions(CommandEnvironment env, OptionsParser optionsParser) {}
}
+ @Command(
+ name = "reportall",
+ options = {FooOptions.class},
+ shortDescription = "",
+ help = ""
+ )
+ private static class ReportAllCommand implements BlazeCommand {
+
+ @Override
+ public ExitCode exec(CommandEnvironment env, OptionsProvider options)
+ throws ShutdownBlazeServerException {
+ FooOptions fooOptions = options.getOptions(FooOptions.class);
+ env.getReporter()
+ .getOutErr()
+ .printOut("" + fooOptions.numOption + " " + fooOptions.stringOption);
+ return ExitCode.SUCCESS;
+ }
+
+ @Override
+ public void editOptions(CommandEnvironment env, OptionsParser optionsParser) {}
+ }
+
+
private final Scratch scratch = new Scratch();
private final RecordingOutErr outErr = new RecordingOutErr();
private final ReportNumCommand reportNum = new ReportNumCommand();
+ private final ReportAllCommand reportAll = new ReportAllCommand();
private BlazeRuntime runtime;
@Before
@@ -139,4 +166,81 @@ public class BlazeCommandDispatcherRcoptionsTest {
String out = outErr.outAsLatin1();
assertEquals("Specific options should dominate common options", "42", out);
}
+
+ @Test
+ public void testOptionsComined() throws Exception {
+ List<String> blazercOpts =
+ ImmutableList.of(
+ "--rc_source=/etc/bazelrc",
+ "--default_override=0:common=--stringoption=foo",
+ "--rc_source=/home/jrluser/.blazerc",
+ "--default_override=1:common=--numoption=99");
+
+ BlazeCommandDispatcher dispatch = new BlazeCommandDispatcher(runtime, reportNum, reportAll);
+ List<String> cmdLine = Lists.newArrayList("reportall");
+ cmdLine.addAll(blazercOpts);
+
+ dispatch.exec(cmdLine, outErr);
+ String out = outErr.outAsLatin1();
+ assertEquals("Options should get accumulated over different rc files", "99 foo", out);
+ }
+
+ @Test
+ public void testOptionsCominedWithOverride() throws Exception {
+ List<String> blazercOpts =
+ ImmutableList.of(
+ "--rc_source=/etc/bazelrc",
+ "--default_override=0:common=--stringoption=foo",
+ "--default_override=0:common=--numoption=42",
+ "--rc_source=/home/jrluser/.blazerc",
+ "--default_override=1:common=--numoption=99");
+
+ BlazeCommandDispatcher dispatch = new BlazeCommandDispatcher(runtime, reportNum, reportAll);
+ List<String> cmdLine = Lists.newArrayList("reportall");
+ cmdLine.addAll(blazercOpts);
+
+ dispatch.exec(cmdLine, outErr);
+ String out = outErr.outAsLatin1();
+ assertEquals("The more specific rc-file should override", "99 foo", out);
+ }
+
+ @Test
+ public void testOptionsCominedWithOverrideOtherName() throws Exception {
+ List<String> blazercOpts =
+ ImmutableList.of(
+ "--rc_source=/home/jrluser/.blazerc",
+ "--default_override=0:common=--stringoption=foo",
+ "--default_override=0:common=--numoption=42",
+ "--rc_source=/etc/bazelrc",
+ "--default_override=1:common=--numoption=99");
+
+ BlazeCommandDispatcher dispatch = new BlazeCommandDispatcher(runtime, reportNum, reportAll);
+ List<String> cmdLine = Lists.newArrayList("reportall");
+ cmdLine.addAll(blazercOpts);
+
+ dispatch.exec(cmdLine, outErr);
+ String out = outErr.outAsLatin1();
+ assertEquals("The more specific rc-file should override irrespective of name", "99 foo", out);
+ }
+
+ @Test
+ public void testOptionsCominedWithSpecificOverride() throws Exception {
+ List<String> blazercOpts =
+ ImmutableList.of(
+ "--rc_source=/home/jrluser/.blazerc",
+ "--default_override=0:common=--stringoption=foo",
+ "--default_override=0:reportall=--numoption=42",
+ "--rc_source=/etc/bazelrc",
+ "--default_override=1:common=--stringoption=bar",
+ "--default_override=1:common=--numoption=99");
+
+ BlazeCommandDispatcher dispatch = new BlazeCommandDispatcher(runtime, reportNum, reportAll);
+ List<String> cmdLine = Lists.newArrayList("reportall");
+ cmdLine.addAll(blazercOpts);
+
+ dispatch.exec(cmdLine, outErr);
+ String out = outErr.outAsLatin1();
+ assertEquals(
+ "The more specific option should override, irrespecitve of source file", "42 bar", out);
+ }
}