aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2016-02-03 19:47:06 +0000
committerGravatar David Chen <dzc@google.com>2016-02-03 22:07:02 +0000
commit51810618e1ef1e055c3a7c1b362725aed3acddf4 (patch)
tree27d687f849fdcf506672799382ab8ff105a4d1b1 /src
parentb5ff50b7596d7ab92c9bf8e656da20e10ddd861a (diff)
Add unit-er tests for genrule
-- MOS_MIGRATED_REVID=113765603
Diffstat (limited to 'src')
-rw-r--r--src/test/java/com/google/devtools/build/lib/BUILD3
-rw-r--r--src/test/java/com/google/devtools/build/lib/bazel/rules/genrule/GenruleConfiguredTargetTest.java68
2 files changed, 71 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD
index f1cc973817..62cc9e33eb 100644
--- a/src/test/java/com/google/devtools/build/lib/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/BUILD
@@ -992,13 +992,16 @@ java_test(
tags = ["rules"],
test_class = "com.google.devtools.build.lib.AllTests",
deps = [
+ ":analysis_testutil",
":foundations_testutil",
":test_runner",
"//src/main/java/com/google/devtools/build/lib:bazel-main",
"//src/main/java/com/google/devtools/build/lib:bazel-rules",
+ "//src/main/java/com/google/devtools/build/lib:build-base",
"//src/main/java/com/google/devtools/build/lib:events",
"//src/main/java/com/google/devtools/build/lib:util",
"//src/main/java/com/google/devtools/build/lib:vfs",
+ "//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/protobuf:crosstool_config_proto",
"//third_party:guava",
"//third_party:junit4",
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/genrule/GenruleConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/genrule/GenruleConfiguredTargetTest.java
new file mode 100644
index 0000000000..00c8115412
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/genrule/GenruleConfiguredTargetTest.java
@@ -0,0 +1,68 @@
+// Copyright 2015 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.bazel.rules.genrule;
+
+import static com.google.common.collect.Iterables.getOnlyElement;
+import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.vfs.PathFragment;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.List;
+
+/**
+ * Unit tests for {@link GenRule}.
+ */
+@RunWith(JUnit4.class)
+public class GenruleConfiguredTargetTest extends BuildViewTestCase {
+ @Before
+ public void createFiles() throws Exception {
+ scratch.file("hello/BUILD",
+ "genrule(",
+ " name = 'z',",
+ " outs = ['x/y'],",
+ " cmd = 'echo hi > $(@D)/y',",
+ ")",
+ "genrule(",
+ " name = 'w',",
+ " outs = ['a/b', 'c/d'],",
+ " cmd = 'echo hi | tee $(@D)/a/b $(@D)/c/d',",
+ ")");
+ }
+
+ @Test
+ public void testD() throws Exception {
+ ConfiguredTarget z = getConfiguredTarget("//hello:z");
+ Artifact y = getOnlyElement(getFilesToBuild(z));
+ assertEquals(new PathFragment("hello/x/y"), y.getRootRelativePath());
+ }
+
+ @Test
+ public void testDMultiOutput() throws Exception {
+ ConfiguredTarget z = getConfiguredTarget("//hello:w");
+ List<Artifact> files = getFilesToBuild(z).toList();
+ assertThat(files).hasSize(2);
+ assertEquals(new PathFragment("hello/a/b"), files.get(0).getRootRelativePath());
+ assertEquals(new PathFragment("hello/c/d"), files.get(1).getRootRelativePath());
+ }
+}