use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testCoverageInstrumentedMatchesFilter.
@Test
public void testCoverageInstrumentedMatchesFilter() throws Exception {
setUpCoverageInstrumentedTest();
useConfiguration("--collect_code_coverage", "--instrumentation_filter=:foo");
SkylarkRuleContext ruleContext = createRuleContext("//test:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.coverage_instrumented()");
assertThat((Boolean) result).isTrue();
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testCoverageInstrumentedMatchesFilterNonDefaultLabel.
@Test
public void testCoverageInstrumentedMatchesFilterNonDefaultLabel() throws Exception {
setUpCoverageInstrumentedTest();
useConfiguration("--collect_code_coverage", "--instrumentation_filter=:bar");
SkylarkRuleContext ruleContext = createRuleContext("//test:foo");
// //test:bar does match :bar, though //test:foo would not.
Object result = evalRuleContextCode(ruleContext, "ruleContext.coverage_instrumented(ruleContext.attr.deps[0])");
assertThat((Boolean) result).isTrue();
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testLabelKeyedStringDictConvertsToTargetToStringMap.
@Test
public void testLabelKeyedStringDictConvertsToTargetToStringMap() throws Exception {
scratch.file("my_rule.bzl", "def _impl(ctx):", " return", "my_rule = rule(", " implementation = _impl,", " attrs = {", " 'label_dict': attr.label_keyed_string_dict(),", " }", ")");
scratch.file("BUILD", "filegroup(name='dep')", "load('//:my_rule.bzl', 'my_rule')", "my_rule(name='r',", " label_dict={':dep': 'value'})");
invalidatePackages();
SkylarkRuleContext context = createRuleContext("//:r");
Label keyLabel = (Label) evalRuleContextCode(context, "ruleContext.attr.label_dict.keys()[0].label");
assertThat(keyLabel).isEqualTo(Label.parseAbsolute("//:dep"));
String valueString = (String) evalRuleContextCode(context, "ruleContext.attr.label_dict.values()[0]");
assertThat(valueString).isEqualTo("value");
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testParamFileLegacy.
@Test
public void testParamFileLegacy() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.new_file(ruleContext.bin_dir," + "ruleContext.files.tools[0], '.params')");
PathFragment fragment = ((Artifact) result).getRootRelativePath();
assertEquals("foo/t.exe.params", fragment.getPathString());
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method shouldGetPrerequisites.
@Test
public void shouldGetPrerequisites() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.srcs");
// Check for a known provider
TransitiveInfoCollection tic1 = (TransitiveInfoCollection) ((SkylarkList) result).get(0);
assertNotNull(tic1.getProvider(JavaSourceJarsProvider.class));
// Check an unimplemented provider too
assertNull(tic1.getProvider(SkylarkProviders.class).getValue(PyCommon.PYTHON_SKYLARK_PROVIDER_NAME));
}
Aggregations