Skip to content

Commit

Permalink
Throw exception if 'None' value given to List-type command line optio…
Browse files Browse the repository at this point in the history
…ns in Bazel transition definition
  • Loading branch information
tobiade committed Apr 28, 2021
1 parent 9e513f9 commit 8b473b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private static BuildOptions applyTransition(
optionValueAsList.stream().map(Object::toString).collect(joining(",")));
}
} else if (def.getType() == List.class && optionValue == null) {
convertedValue = def.getDefaultValue();
throw ValidationException.format("'None' value not allowed for List-type option '%s'. Please use '[]' instead if trying to set option to empty value.", optionName);
} else if (optionValue == null || def.getType().isInstance(optionValue)) {
convertedValue = optionValue;
} else if (def.getType().equals(boolean.class) && optionValue instanceof Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ public void successfulTypeConversionOfNativeListOptionEmptyList() throws Excepti
}

@Test
public void successfulTypeConversionOfNativeListOptionNone() throws Exception {
public void failedTypeConversionOfNativeListOptionNone() throws Exception {
writeAllowlistFile();
scratch.file(
"test/transitions.bzl",
Expand All @@ -1355,9 +1355,9 @@ public void successfulTypeConversionOfNativeListOptionNone() throws Exception {
"load('//test:rules.bzl', 'my_rule')",
"my_rule(name = 'test')");

ConfiguredTarget ct = getConfiguredTarget("//test");
assertNoEvents();
assertThat(getConfiguration(ct).getOptions().get(CppOptions.class).coptList).isEmpty();
reporter.removeHandler(failFastHandler);
getConfiguredTarget("//test");
assertContainsEvent("'None' value not allowed for List-type option 'copt'. Please use '[]' instead if trying to set option to empty value.");
}

@Test
Expand Down

0 comments on commit 8b473b5

Please sign in to comment.