aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/skylark
diff options
context:
space:
mode:
authorGravatar vladmos <vladmos@google.com>2017-07-07 21:13:27 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-07-10 09:16:15 +0200
commit8ff3d2d61d1638553ef1315ca0f52a8357feca2f (patch)
tree34ddc11774706076a59e3c7b32e3f201771524ff /src/test/java/com/google/devtools/build/lib/skylark
parent739d80ccbd795bac7727a6d89bbb92f5436675cf (diff)
Clean up string representations for artifacts
If --incompatible_descriptive_string_representations is passed, artifacts are converted to strings using `str`, `repr` and `print` functions differently (more descriptive, without leaking information that shouldn't be accessible). PiperOrigin-RevId: 161230209
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skylark')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java
index f1146a1975..3dbb2defb1 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java
@@ -98,8 +98,8 @@ public class SkylarkStringRepresentationsTest extends SkylarkTestCase {
* strings are available in the configured target for //test/skylark:check
*/
private void generateFilesToTestStrings() throws Exception {
- // Generate string representations of Skylark rule contexts and targets. Objects are gathered
- // in the implementation of the `check` rule.
+ // Generate string representations of Skylark rule contexts, targets, and files.
+ // Objects are gathered in the implementation of the `check` rule.
// prepare_params(objects) converts a dict of objects to a dict of their string representations.
scratch.file(
@@ -138,7 +138,9 @@ public class SkylarkStringRepresentationsTest extends SkylarkTestCase {
" 'output_target': ctx.attr.srcs[1],",
" 'rule_ctx': ctx,",
" 'aspect_ctx': ctx.attr.asp_deps[0][aspect_ctx_provider].ctx,",
- " 'aspect_ctx.rule': ctx.attr.asp_deps[0][aspect_ctx_provider].rule",
+ " 'aspect_ctx.rule': ctx.attr.asp_deps[0][aspect_ctx_provider].rule,",
+ " 'source_file': ctx.attr.srcs[0].files.to_list()[0],",
+ " 'generated_file': ctx.attr.srcs[1].files.to_list()[0],",
" }",
" return struct(**prepare_params(objects))",
"check = rule(",
@@ -269,6 +271,21 @@ public class SkylarkStringRepresentationsTest extends SkylarkTestCase {
}
@Test
+ public void testStringRepresentations_Files() throws Exception {
+ setSkylarkSemanticsOptions("--incompatible_descriptive_string_representations=true");
+
+ generateFilesToTestStrings();
+ ConfiguredTarget target = getConfiguredTarget("//test/skylark:check");
+
+ for (String suffix : SUFFIXES) {
+ assertThat(target.get("source_file" + suffix))
+ .isEqualTo("<source file test/skylark/input.txt>");
+ assertThat(target.get("generated_file" + suffix))
+ .isEqualTo("<generated file test/skylark/output.txt>");
+ }
+ }
+
+ @Test
public void testStringRepresentations_Attr() throws Exception {
setSkylarkSemanticsOptions("--incompatible_descriptive_string_representations=true");
@@ -381,4 +398,19 @@ public class SkylarkStringRepresentationsTest extends SkylarkTestCase {
.isEqualTo("rule_collection://test/skylark:bar");
}
}
+
+ @Test
+ public void testLegacyStringRepresentations_Files() throws Exception {
+ setSkylarkSemanticsOptions("--incompatible_descriptive_string_representations=false");
+
+ generateFilesToTestStrings();
+ ConfiguredTarget target = getConfiguredTarget("//test/skylark:check");
+
+ for (String suffix : SUFFIXES) {
+ assertThat(target.get("source_file" + suffix))
+ .isEqualTo("File:[/workspace[source]]test/skylark/input.txt");
+ assertThat((String) target.get("generated_file" + suffix))
+ .endsWith("test/skylark/output.txt");
+ }
+ }
}