warkahscott | 1d9c7da | 2020-09-17 13:23:20 -0700 | [diff] [blame^] | 1 | // Copyright 2020 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 | package com.google.devtools.build.lib.runtime; |
| 15 | |
| 16 | import static com.google.common.truth.Truth.assertThat; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.devtools.build.lib.events.Event; |
| 20 | import org.junit.Test; |
| 21 | import org.junit.runner.RunWith; |
| 22 | import org.junit.runners.JUnit4; |
| 23 | |
| 24 | /** Tests --flag_alias functionality in {@link BlazeOptionHandler}. */ |
| 25 | @RunWith(JUnit4.class) |
| 26 | public final class FlagAliasTest extends AbstractBlazeOptionHandlerTest { |
| 27 | |
| 28 | @Test |
| 29 | public void useAliasWithoutSettingFeature() { |
| 30 | ImmutableList<String> args = |
| 31 | ImmutableList.of("c0", "--rc_source=/somewhere/.blazerc", "--flag_alias=foo=bar"); |
| 32 | optionHandler.parseOptions(args, eventHandler); |
| 33 | assertThat(eventHandler.getEvents()) |
| 34 | .contains( |
| 35 | Event.error( |
| 36 | "--flag_alias is experimental. Set --experimental_enable_flag_alias to true to" |
| 37 | + " make use of it. Detected aliases: --flag_alias=foo=bar")); |
| 38 | } |
| 39 | |
| 40 | @Test |
| 41 | public void useAliasWithSetDisabledFeature() { |
| 42 | ImmutableList<String> args = |
| 43 | ImmutableList.of( |
| 44 | "c0", |
| 45 | "--rc_source=/somewhere/.blazerc", |
| 46 | "--noexperimental_enable_flag_alias", |
| 47 | "--flag_alias=foo=bar"); |
| 48 | optionHandler.parseOptions(args, eventHandler); |
| 49 | assertThat(eventHandler.getEvents()) |
| 50 | .contains( |
| 51 | Event.error( |
| 52 | "--flag_alias is experimental. Set --experimental_enable_flag_alias to true to" |
| 53 | + " make use of it. Detected aliases: --flag_alias=foo=bar")); |
| 54 | } |
| 55 | |
| 56 | @Test |
| 57 | public void useAliasWithSetEnabledFeature() { |
| 58 | ImmutableList<String> args = |
| 59 | ImmutableList.of( |
| 60 | "c0", |
| 61 | "--rc_source=/somewhere/.blazerc", |
| 62 | "--experimental_enable_flag_alias", |
| 63 | "--flag_alias=foo=bar"); |
| 64 | optionHandler.parseOptions(args, eventHandler); |
| 65 | assertThat(eventHandler.hasErrors()).isFalse(); |
| 66 | } |
| 67 | |
| 68 | @Test |
| 69 | public void multipleAliasesLoggedInError() { |
| 70 | ImmutableList<String> args = |
| 71 | ImmutableList.of( |
| 72 | "c0", |
| 73 | "--rc_source=/somewhere/.blazerc", |
| 74 | "--noexperimental_enable_flag_alias", |
| 75 | "--flag_alias=foo=bar", |
| 76 | "--flag_alias=baz=baz2"); |
| 77 | optionHandler.parseOptions(args, eventHandler); |
| 78 | assertThat(eventHandler.getEvents()) |
| 79 | .contains( |
| 80 | Event.error( |
| 81 | "--flag_alias is experimental. Set --experimental_enable_flag_alias to true to" |
| 82 | + " make use of it. Detected aliases: --flag_alias=foo=bar," |
| 83 | + " --flag_alias=baz=baz2")); |
| 84 | } |
| 85 | } |