blob: 634ec3647b83a58503579cb489eb5d0211a1616d [file] [log] [blame]
Carmi Grushko9f136002015-12-04 20:53:54 +00001// Copyright 2015 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.devtools.build.lib.analysis;
16
17import static com.google.common.truth.Truth.assertThat;
18import static com.google.devtools.build.lib.analysis.AnalysisUtils.checkProvider;
michajlo660d17f2020-03-27 09:01:57 -070019import static org.junit.Assert.assertThrows;
Carmi Grushko9f136002015-12-04 20:53:54 +000020
21import com.google.auto.value.AutoValue;
Carmi Grushko9f136002015-12-04 20:53:54 +000022import org.junit.Test;
23import org.junit.runner.RunWith;
24import org.junit.runners.JUnit4;
25
26@RunWith(JUnit4.class)
27public class AnalysisUtilsTest {
28
29 @Test
30 public void checkProviderSucceedsOnClassAnnotatedWithAutoValue() {
31 checkProvider(AutoValuedClass.class);
32 }
33
34 @Test
Googler89100872016-07-26 15:52:48 +000035 public void checkProviderFailsOnClassGeneratedByAutoValue() {
jcater42edea62019-05-01 08:46:18 -070036 IllegalArgumentException e =
37 assertThrows(
38 IllegalArgumentException.class,
39 () -> checkProvider(AutoValue_AnalysisUtilsTest_AutoValuedClass.class));
40 assertThat(e).hasMessageThat().contains("generated by @AutoValue");
Carmi Grushko9f136002015-12-04 20:53:54 +000041 }
42
Googler89100872016-07-26 15:52:48 +000043 // Note: this has to be defined outside of checkProviderFailsOnClassGeneratedByAutoValue() so it
Carmi Grushko9f136002015-12-04 20:53:54 +000044 // can be static, which is required by @AutoValue.
45 @AutoValue
46 abstract static class AutoValuedClass implements TransitiveInfoProvider {
47 abstract int foo();
48 }
Googlercecca152016-06-20 22:51:10 +000049}