aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/common/options/OptionFiltersSynchronyTest.java
blob: 0e13eca0bc2b7a034b561ef6be53bc05879b1769 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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());
    }
  }
}