diff options
author | 2017-07-14 19:09:53 +0200 | |
---|---|---|
committer | 2017-07-17 10:10:58 +0200 | |
commit | d1c4d22f548880f1c6b159735040dbba4c513eeb (patch) | |
tree | cb5a6f3334dddb361ef915f0d25ca218de31368c /src/test/java/com | |
parent | 2bd6aa7ce56a8f8f110ed72a4c726fdce7d4da93 (diff) |
Add the option filter enums in java, with equivalence check.
In order to break out the proto dependency of the OptionsParser, add a java-only enum that users of the options parser can depend on, instead of requiring the dependency on the protobuf. The protocol buffer definition is kept in order to be used for command line reporting in the BEP, so a test is added to make sure that the two are kept in sync.
Also add some clearer guidance for how to go about selecting, and adding, option categories and tags.
Migrating the current uses of the proto enum to this one will happen in a follow-up change.
PiperOrigin-RevId: 161971077
Diffstat (limited to 'src/test/java/com')
-rw-r--r-- | src/test/java/com/google/devtools/common/options/OptionFiltersSynchronyTest.java | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/common/options/OptionFiltersSynchronyTest.java b/src/test/java/com/google/devtools/common/options/OptionFiltersSynchronyTest.java new file mode 100644 index 0000000000..0e13eca0bc --- /dev/null +++ b/src/test/java/com/google/devtools/common/options/OptionFiltersSynchronyTest.java @@ -0,0 +1,88 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.common.options; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; + +import com.google.devtools.common.options.proto.OptionFilters; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * This test makes sure that the two java filtering enums, OptionMetadataTag and OptionEffectTag, + * are kept in sync with the matching proto. + */ +@RunWith(JUnit4.class) +public class OptionFiltersSynchronyTest { + + @Test + public void optionEffectTags() { + // Check that the number of tags are equal. The proto version automatically defines an + // UNRECOGNIZED value at -1, the sizes should actually be offset by one. + assertThat(OptionFilters.OptionEffectTag.values()) + .hasLength(OptionEffectTag.values().length + 1); + + // Now go through each and check that the names are equal. + for (OptionEffectTag javaTag : OptionEffectTag.values()) { + OptionFilters.OptionEffectTag protoTag = + OptionFilters.OptionEffectTag.forNumber(javaTag.getValue()); + + // First check that the tag exists with this value, then that the names are equal. + assertWithMessage( + "OptionEffectTag " + + javaTag + + " does not have a proto equivalent with the same value") + .that(protoTag) + .isNotNull(); + assertWithMessage( + "OptionEffectTag " + + javaTag + + " does not have the same name as the proto equivalent " + + protoTag) + .that(javaTag.name()) + .isEqualTo(protoTag.name()); + } + } + + @Test + public void optionMetadataTags() { + // Check that the number of tags are equal. The proto version automatically defines an + // UNRECOGNIZED value at -1, the sizes should actually be offset by one. + assertThat(OptionFilters.OptionMetadataTag.values()) + .hasLength(OptionMetadataTag.values().length + 1); + + // Now go through each and check that the names are equal. + for (OptionMetadataTag javaTag : OptionMetadataTag.values()) { + OptionFilters.OptionMetadataTag protoTag = + OptionFilters.OptionMetadataTag.forNumber(javaTag.getValue()); + + // First check that the tag exists with this value, then that the names are equal. + assertWithMessage( + "OptionMetadataTag " + + javaTag + + " does not have a proto equivalent with the same value") + .that(protoTag) + .isNotNull(); + assertWithMessage( + "OptionMetadataTag " + + javaTag + + " does not have the same name as the proto equivalent " + + protoTag) + .that(javaTag.name()) + .isEqualTo(protoTag.name()); + } + } +} |