aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar hlopko <hlopko@google.com>2018-02-27 06:09:18 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-27 06:11:28 -0800
commitdb80298391bd953b1a1f8e9bb83c2d4c2f3747b4 (patch)
tree5cea30cdd010d8be2d71732034ab83077bbeb2e0 /src/test/java/com/google/devtools/build
parentc2499c406d0727853ea0ddc5372a50be95de5515 (diff)
Introduce cc_configure_lib.bzl#split_escaped
This function allows us to split strings coming from env variables into lists while respecting %-escaping. RELNOTES: None. PiperOrigin-RevId: 187166226
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD2
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/SkylarkCcToolchainConfigureTest.java61
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java3
3 files changed, 66 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD b/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD
index e913a1ed28..7e0b17115b 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD
@@ -13,6 +13,7 @@ filegroup(
java_test(
name = "cpp-rules-tests",
srcs = glob(["*.java"]) + ["proto/CcProtoLibraryTest.java"],
+ resources = ["//tools/cpp:lib_cc_configure"],
tags = ["rules"],
test_class = "com.google.devtools.build.lib.AllTests",
deps = [
@@ -43,6 +44,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib:actions_testutil",
"//src/test/java/com/google/devtools/build/lib:analysis_testutil",
"//src/test/java/com/google/devtools/build/lib:packages_testutil",
+ "//src/test/java/com/google/devtools/build/lib:syntax_testutil",
"//src/test/java/com/google/devtools/build/lib:testutil",
"//third_party:guava",
"//third_party:guava-testlib",
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/SkylarkCcToolchainConfigureTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/SkylarkCcToolchainConfigureTest.java
new file mode 100644
index 0000000000..dbaa612fb3
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/SkylarkCcToolchainConfigureTest.java
@@ -0,0 +1,61 @@
+// Copyright 2018 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.rules.cpp;
+
+import com.google.devtools.build.lib.packages.util.ResourceLoader;
+import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
+import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
+import com.google.devtools.build.lib.testutil.TestConstants;
+import java.io.IOException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for cc autoconfiguration. */
+@RunWith(JUnit4.class)
+public class SkylarkCcToolchainConfigureTest extends EvaluationTestCase {
+
+ @Test
+ public void testSplitEscaped() throws Exception {
+ newTest()
+ .testStatement("split_escaped('a:b:c', ':')", MutableList.of(env, "a", "b", "c"))
+ .testStatement("split_escaped('a%:b', ':')", MutableList.of(env, "a:b"))
+ .testStatement("split_escaped('a%%b', ':')", MutableList.of(env, "a%b"))
+ .testStatement("split_escaped('a:::b', ':')", MutableList.of(env, "a", "", "", "b"))
+ .testStatement("split_escaped('a:b%:c', ':')", MutableList.of(env, "a", "b:c"))
+ .testStatement("split_escaped('a%%:b:c', ':')", MutableList.of(env, "a%", "b", "c"))
+ .testStatement("split_escaped(':a', ':')", MutableList.of(env, "", "a"))
+ .testStatement("split_escaped('a:', ':')", MutableList.of(env, "a", ""))
+ .testStatement("split_escaped('::a::', ':')", MutableList.of(env, "", "", "a", "", ""))
+ .testStatement("split_escaped('%%%:a%%%%:b', ':')", MutableList.of(env, "%:a%%", "b"))
+ .testStatement("split_escaped('', ':')", MutableList.of(env, ""))
+ .testStatement("split_escaped('%', ':')", MutableList.of(env, "%"))
+ .testStatement("split_escaped('%%', ':')", MutableList.of(env, "%"))
+ .testStatement("split_escaped('%:', ':')", MutableList.of(env, ":"))
+ .testStatement("split_escaped(':', ':')", MutableList.of(env, "", ""))
+ .testStatement("split_escaped('a%%b', ':')", MutableList.of(env, "a%b"))
+ .testStatement("split_escaped('a%:', ':')", MutableList.of(env, "a:"));
+ }
+
+ private ModalTestCase newTest(String... skylarkOptions) throws IOException {
+ return new SkylarkTest(skylarkOptions)
+ // A mock implementation of Label to be able to parse lib_cc_configure under default
+ // Skylark environment (lib_cc_configure is meant to be used from the repository
+ // environment).
+ .setUp("def Label(arg):\n return 42")
+ .setUp(
+ ResourceLoader.readFromResources(
+ TestConstants.BAZEL_REPO_PATH + "tools/cpp/lib_cc_configure.bzl"));
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
index 92377572d5..d7abdf6e9c 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
@@ -59,6 +59,9 @@ public class TestConstants {
*/
public static final String JAVATESTS_ROOT = "io_bazel/src/test/java/";
+ /** Location of the bazel repo relative to the workspace root */
+ public static final String BAZEL_REPO_PATH = "";
+
/** Relative path to the {@code process-wrapper} tool. */
public static final String PROCESS_WRAPPER_PATH =
"io_bazel/src/main/tools/process-wrapper";