aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar eaftan <eaftan@google.com>2017-05-05 22:02:30 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-05-05 23:20:14 +0200
commit8e006399c42830855da11898db6707ac9f759762 (patch)
tree508e4f6317fdd500bdcf593fc8aa56a7910b63a3 /src/test/java/com/google/devtools
parent9eed8d6a7112d43e2b48c5658be70e0e310e9df2 (diff)
Blaze now passes an extra flag to JavaBuilder, --testonly, to
mark compilations of test code. We plan to use this for Error Prone checks that need to distinguish between test and production code, such as enforcing @VisibleForTesting. PiperOrigin-RevId: 155231021
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java39
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidLibraryTest.java33
2 files changed, 72 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
index 3715c0c45c..4948c8bfa5 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
@@ -2777,4 +2777,43 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase {
.containsAllOf("--nocompress_suffixes", ".apk", ".so")
.inOrder();
}
+
+ @Test
+ public void testAndroidBinaryWithTestOnlySetsTestOnly() throws Exception {
+ scratch.file(
+ "java/com/google/android/foo/BUILD",
+ "android_binary(",
+ " name = 'foo',",
+ " srcs = ['Foo.java'],",
+ " testonly = 1,",
+ " manifest = 'AndroidManifest.xml',",
+ " resource_files = ['res/raw/foo.apk'],",
+ " nocompress_extensions = ['.apk', '.so'],",
+ ")");
+ JavaCompileAction javacAction =
+ (JavaCompileAction)
+ getGeneratingAction(
+ getBinArtifact("libfoo.jar", getConfiguredTarget("//java/com/google/android/foo")));
+
+ assertThat(javacAction.buildCommandLine()).contains("--testonly");
+ }
+
+ @Test
+ public void testAndroidBinaryWithoutTestOnlyDoesntSetTestOnly() throws Exception {
+ scratch.file(
+ "java/com/google/android/foo/BUILD",
+ "android_binary(",
+ " name = 'foo',",
+ " srcs = ['Foo.java'],",
+ " manifest = 'AndroidManifest.xml',",
+ " resource_files = ['res/raw/foo.apk'],",
+ " nocompress_extensions = ['.apk', '.so'],",
+ ")");
+ JavaCompileAction javacAction =
+ (JavaCompileAction)
+ getGeneratingAction(
+ getBinArtifact("libfoo.jar", getConfiguredTarget("//java/com/google/android/foo")));
+
+ assertThat(javacAction.buildCommandLine()).doesNotContain("--testonly");
+ }
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLibraryTest.java
index ea30deb73f..706c08c748 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLibraryTest.java
@@ -1467,4 +1467,37 @@ public class AndroidLibraryTest extends AndroidBuildViewTestCase {
assertThat(provider).isNotNull();
assertThat(provider.getTransitiveAars()).hasSize(1);
}
+
+ @Test
+ public void testAndroidLibraryWithTestOnlySetsTestOnly() throws Exception {
+ scratch.file(
+ "java/com/google/android/foo/BUILD",
+ "android_library(",
+ " name = 'foo',",
+ " srcs = ['Foo.java'],",
+ " testonly = 1,",
+ ")");
+ JavaCompileAction javacAction =
+ (JavaCompileAction)
+ getGeneratingAction(
+ getBinArtifact("libfoo.jar", getConfiguredTarget("//java/com/google/android/foo")));
+
+ assertThat(javacAction.buildCommandLine()).contains("--testonly");
+ }
+
+ @Test
+ public void testAndroidLibraryWithoutTestOnlyDoesntSetTestOnly() throws Exception {
+ scratch.file(
+ "java/com/google/android/foo/BUILD",
+ "android_library(",
+ " name = 'foo',",
+ " srcs = ['Foo.java'],",
+ ")");
+ JavaCompileAction javacAction =
+ (JavaCompileAction)
+ getGeneratingAction(
+ getBinArtifact("libfoo.jar", getConfiguredTarget("//java/com/google/android/foo")));
+
+ assertThat(javacAction.buildCommandLine()).doesNotContain("--testonly");
+ }
}