aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/analysis/config
diff options
context:
space:
mode:
authorGravatar Sergio Campama <kaipi@google.com>2016-11-28 18:00:21 +0000
committerGravatar Irina Iancu <elenairina@google.com>2016-11-29 08:06:42 +0000
commitc9f1f4b70be824edea275e8d9a815e9f400ea5ed (patch)
tree4f23c5537a9d5058b5ce5ee8b110ff25f1e6046b /src/test/java/com/google/devtools/build/lib/analysis/config
parent978fb3f780e60fcdd2659419f8c920d4c9f8fbe8 (diff)
Makes the --test_env command line options available in skylark's rule context.
-- MOS_MIGRATED_REVID=140369679
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/analysis/config')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationSkylarkTest.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationSkylarkTest.java b/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationSkylarkTest.java
new file mode 100644
index 0000000000..3ea05dc474
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationSkylarkTest.java
@@ -0,0 +1,55 @@
+// Copyright 2016 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.build.lib.analysis.config;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
+import com.google.devtools.build.lib.analysis.SkylarkProviders;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.syntax.SkylarkDict;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link BuildConfiguration}'s integration with Skylark. */
+@RunWith(JUnit4.class)
+public final class BuildConfigurationSkylarkTest extends BuildViewTestCase {
+
+ @Test
+ public void testSkylarkWithTestEnvOptions() throws Exception {
+ useConfiguration("--test_env=TEST_ENV_VAR=my_value");
+ scratch.file("examples/rule/BUILD");
+ scratch.file(
+ "examples/rule/config_test.bzl",
+ "def _test_rule_impl(ctx):",
+ " return struct(test_env = ctx.configuration.test_env)",
+ "test_rule = rule(implementation = _test_rule_impl,",
+ " attrs = {},",
+ ")");
+
+ scratch.file(
+ "examples/config_skylark/BUILD",
+ "package(default_visibility = ['//visibility:public'])",
+ "load('/examples/rule/config_test', 'test_rule')",
+ "test_rule(",
+ " name = 'my_target',",
+ ")");
+
+ ConfiguredTarget skylarkTarget = getConfiguredTarget("//examples/config_skylark:my_target");
+ SkylarkProviders skylarkProviders = skylarkTarget.getProvider(SkylarkProviders.class);
+ assertThat(skylarkProviders.getValue("test_env", SkylarkDict.class).get("TEST_ENV_VAR"))
+ .isEqualTo("my_value");
+ }
+}