aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar Han-Wen Nienhuys <hanwen@google.com>2015-09-25 14:25:38 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-09-25 14:43:13 +0000
commit33ce2112a71e79a85b48afa518e7f0804cb383d1 (patch)
tree1446727be8f2a3e6fc7fc48bef19361db7281803 /src/test/java
parentf88f4d81acead9ef3e2f73d9a44afd76c2c239c1 (diff)
Use JUnit4 for skylark tests.
-- Change-Id: I3cf7a8127da60d93005594d73abbdb8f7bda7cf2 Reviewed-on: https://bazel-review.googlesource.com/#/c/2041 MOS_MIGRATED_REVID=103940423
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkCommandLineTest.java9
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkFileHelperTest.java12
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java56
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java56
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java15
7 files changed, 121 insertions, 35 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkCommandLineTest.java
index 7848af97a6..55aa37348e 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkCommandLineTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkCommandLineTest.java
@@ -19,12 +19,18 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.devtools.build.lib.skylark.util.SkylarkTestCase;
import com.google.devtools.build.lib.syntax.SkylarkList;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
/**
* Tests for {@link SkylarkCommandLine}.
*/
+@RunWith(JUnit4.class)
public class SkylarkCommandLineTest extends SkylarkTestCase {
- @Override
+ @Before
public void setUp() throws Exception {
super.setUp();
scratch.file(
@@ -36,6 +42,7 @@ public class SkylarkCommandLineTest extends SkylarkTestCase {
" outs = ['c.txt'])");
}
+ @Test
public void testCmdHelperAll() throws Exception {
Object result =
evalRuleContextCode(
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkFileHelperTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkFileHelperTest.java
index 8fc343e26b..9307868696 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkFileHelperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkFileHelperTest.java
@@ -21,12 +21,18 @@ import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.rules.SkylarkRuleContext;
import com.google.devtools.build.lib.skylark.util.SkylarkTestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
/**
* Tests for SkylarkFileset and SkylarkFileType.
*/
+@RunWith(JUnit4.class)
public class SkylarkFileHelperTest extends SkylarkTestCase {
- @Override
+ @Before
public void setUp() throws Exception {
super.setUp();
scratch.file(
@@ -39,6 +45,7 @@ public class SkylarkFileHelperTest extends SkylarkTestCase {
}
@SuppressWarnings("unchecked")
+ @Test
public void testFilterPasses() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result =
@@ -46,6 +53,7 @@ public class SkylarkFileHelperTest extends SkylarkTestCase {
assertEquals(ActionsTestUtil.baseNamesOf((Iterable<Artifact>) result), "b.img");
}
+ @Test
public void testFilterFiltersFilesOut() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result =
@@ -53,12 +61,14 @@ public class SkylarkFileHelperTest extends SkylarkTestCase {
assertThat(((Iterable<?>) result)).isEmpty();
}
+ @Test
public void testArtifactPath() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
String result = (String) evalRuleContextCode(ruleContext, "ruleContext.files.tools[0].path");
assertEquals("foo/t.exe", result);
}
+ @Test
public void testArtifactShortPath() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
String result =
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
index 730205ea45..1c57974cbb 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
@@ -35,14 +35,17 @@ import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.FileTypeSet;
import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests for SkylarkRuleClassFunctions.
*/
+@RunWith(JUnit4.class)
public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
@Before
- @Override
public void setUp() throws Exception {
super.setUp();
scratch.file(
@@ -66,6 +69,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
")");
}
+ @Test
public void testCannotOverrideBuiltInAttribute() throws Exception {
checkEvalError(
"There is already a built-in attribute 'tags' which cannot be overridden",
@@ -73,6 +77,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"r = rule(impl, attrs = {'tags': attr.string_list()})");
}
+ @Test
public void testImplicitArgsAttribute() throws Exception {
eval(
"def _impl(ctx):",
@@ -91,48 +96,56 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
eval("def impl():\n" + " return 0\n");
}
+ @Test
public void testAttrWithOnlyType() throws Exception {
Object result = evalRuleClassCode("attr.string_list()");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
assertEquals(Type.STRING_LIST, attr.getType());
}
+ @Test
public void testOutputListAttr() throws Exception {
Object result = evalRuleClassCode("attr.output_list()");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
assertEquals(BuildType.OUTPUT_LIST, attr.getType());
}
+ @Test
public void testIntListAttr() throws Exception {
Object result = evalRuleClassCode("attr.int_list()");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
assertEquals(Type.INTEGER_LIST, attr.getType());
}
+ @Test
public void testOutputAttr() throws Exception {
Object result = evalRuleClassCode("attr.output()");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
assertEquals(BuildType.OUTPUT, attr.getType());
}
+ @Test
public void testStringDictAttr() throws Exception {
Object result = evalRuleClassCode("attr.string_dict(default = {'a': 'b'})");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
assertEquals(Type.STRING_DICT, attr.getType());
}
+ @Test
public void testAttrAllowedFileTypesAnyFile() throws Exception {
Object result = evalRuleClassCode("attr.label_list(allow_files = True)");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
assertEquals(FileTypeSet.ANY_FILE, attr.getAllowedFileTypesPredicate());
}
+ @Test
public void testAttrAllowedFileTypesWrongType() throws Exception {
checkErrorContains(
"allow_files should be a boolean or a filetype object.",
"attr.label_list(allow_files = ['.xml'])");
}
+ @Test
public void testAttrWithSkylarkFileType() throws Exception {
Object result = evalRuleClassCode("attr.label_list(allow_files = FileType(['.xml']))");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
@@ -140,6 +153,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertFalse(attr.getAllowedFileTypesPredicate().apply("a.txt"));
}
+ @Test
public void testAttrWithProviders() throws Exception {
Object result =
evalRuleClassCode("attr.label_list(allow_files = True, providers = ['a', 'b'])");
@@ -147,6 +161,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertEquals(ImmutableSet.of("a", "b"), attr.getMandatoryProviders());
}
+ @Test
public void testNonLabelAttrWithProviders() throws Exception {
checkErrorContains(
"unexpected keyword 'providers' in call to string", "attr.string(providers = ['a'])");
@@ -167,7 +182,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
.add(Attribute.attr("tags", Type.STRING_LIST))
.build();
}
-
+ @Test
public void testAttrAllowedRuleClassesSpecificRuleClasses() throws Exception {
Object result =
evalRuleClassCode("attr.label_list(allow_rules = ['java_binary'], allow_files = True)");
@@ -175,13 +190,14 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertTrue(attr.getAllowedRuleClassesPredicate().apply(ruleClass("java_binary")));
assertFalse(attr.getAllowedRuleClassesPredicate().apply(ruleClass("genrule")));
}
-
+ @Test
public void testAttrDefaultValue() throws Exception {
Object result = evalRuleClassCode("attr.string(default = 'some value')");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
assertEquals("some value", attr.getDefaultValueForTesting());
}
+ @Test
public void testAttrDefaultValueBadType() throws Exception {
checkErrorContains(
"Method attr.string(*, default: string, mandatory: bool, values: sequence of strings) "
@@ -190,6 +206,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"attr.string(default = 1)");
}
+ @Test
public void testAttrMandatory() throws Exception {
Object result = evalRuleClassCode("attr.string(mandatory=True)");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
@@ -197,6 +214,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertFalse(attr.isNonEmpty());
}
+ @Test
public void testAttrNonEmpty() throws Exception {
Object result = evalRuleClassCode("attr.string_list(non_empty=True)");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
@@ -204,17 +222,20 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertFalse(attr.isMandatory());
}
+ @Test
public void testAttrBadKeywordArguments() throws Exception {
checkErrorContains(
"unexpected keyword 'bad_keyword' in call to string", "attr.string(bad_keyword = '')");
}
+ @Test
public void testAttrCfg() throws Exception {
Object result = evalRuleClassCode("attr.label(cfg = HOST_CFG, allow_files = True)");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
assertEquals(ConfigurationTransition.HOST, attr.getConfigurationTransition());
}
+ @Test
public void testAttrValues() throws Exception {
Object result = evalRuleClassCode("attr.string(values = ['ab', 'cd'])");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
@@ -223,6 +244,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertThat(predicate.apply("xy")).isFalse();
}
+ @Test
public void testAttrIntValues() throws Exception {
Object result = evalRuleClassCode("attr.int(values = [1, 2])");
Attribute attr = ((Attribute.Builder<?>) result).build("a1");
@@ -231,12 +253,14 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertThat(predicate.apply(3)).isFalse();
}
+ @Test
public void testRuleImplementation() throws Exception {
eval("def impl(ctx): return None", "rule1 = rule(impl)");
RuleClass c = ((RuleFunction) lookup("rule1")).getBuilder().build("rule1");
assertEquals("impl", c.getConfiguredTargetFunction().getName());
}
+ @Test
public void testLateBoundAttrWorksWithOnlyLabel() throws Exception {
checkEvalError(
"Method attr.string(*, default: string, mandatory: bool, values: sequence of strings) "
@@ -246,18 +270,21 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"attr.string(default=attr_value)");
}
+ @Test
public void testRuleAddAttribute() throws Exception {
eval("def impl(ctx): return None", "r1 = rule(impl, attrs={'a1': attr.string()})");
RuleClass c = ((RuleFunction) lookup("r1")).getBuilder().build("r1");
assertTrue(c.hasAttr("a1", Type.STRING));
}
+ @Test
public void testOutputToGenfiles() throws Exception {
eval("def impl(ctx): pass", "r1 = rule(impl, output_to_genfiles=True)");
RuleClass c = ((RuleFunction) lookup("r1")).getBuilder().build("r1");
assertFalse(c.hasBinaryOutput());
}
+ @Test
public void testRuleAddMultipleAttributes() throws Exception {
eval(
"def impl(ctx): return None",
@@ -270,7 +297,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertTrue(c.hasAttr("a1", BuildType.LABEL_LIST));
assertTrue(c.hasAttr("a2", Type.INTEGER));
}
-
+ @Test
public void testRuleAttributeFlag() throws Exception {
eval(
"def impl(ctx): return None",
@@ -279,6 +306,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertTrue(c.getAttributeByName("a1").isMandatory());
}
+ @Test
public void testRuleOutputs() throws Exception {
eval("def impl(ctx): return None", "r1 = rule(impl, outputs = {'a': 'a.txt'})");
RuleClass c = ((RuleFunction) lookup("r1")).getBuilder().build("r1");
@@ -286,6 +314,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertEquals("a.txt", Iterables.getOnlyElement(function.getImplicitOutputs(null)));
}
+ @Test
public void testRuleUnknownKeyword() throws Exception {
registerDummyUserDefinedFunction();
checkErrorContains(
@@ -293,6 +322,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"rule(impl, bad_keyword = 'some text')");
}
+ @Test
public void testRuleImplementationMissing() throws Exception {
checkErrorContains(
"missing mandatory positional argument 'implementation' while calling "
@@ -300,6 +330,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"rule(attrs = {})");
}
+ @Test
public void testRuleBadTypeForAdd() throws Exception {
registerDummyUserDefinedFunction();
checkErrorContains(
@@ -308,6 +339,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"rule(impl, attrs = 'some text')");
}
+ @Test
public void testRuleBadTypeInAdd() throws Exception {
registerDummyUserDefinedFunction();
checkErrorContains(
@@ -316,11 +348,13 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"rule(impl, attrs = {'a1': 'some text'})");
}
+ @Test
public void testLabel() throws Exception {
Object result = evalRuleClassCode("Label('//foo/foo:foo')");
assertEquals("//foo/foo:foo", ((Label) result).toString());
}
+ @Test
public void testLabelSameInstance() throws Exception {
Object l1 = evalRuleClassCode("Label('//foo/foo:foo')");
// Implicitly creates a new pkgContext and environment, yet labels should be the same.
@@ -328,6 +362,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertSame(l2, l1);
}
+ @Test
public void testLabelNameAndPackage() throws Exception {
Object result = evalRuleClassCode("Label('//foo/bar:baz').name");
assertEquals("baz", result);
@@ -336,6 +371,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertEquals("foo/bar", result);
}
+ @Test
public void testRuleLabelDefaultValue() throws Exception {
eval(
"def impl(ctx): return None\n"
@@ -346,6 +382,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertEquals("//foo:foo", ((Label) a.getDefaultValueForTesting()).toString());
}
+ @Test
public void testIntDefaultValue() throws Exception {
eval("def impl(ctx): return None", "r1 = rule(impl, attrs = {'a1': attr.int(default = 40+2)})");
RuleClass c = ((RuleFunction) lookup("r1")).getBuilder().build("r1");
@@ -353,12 +390,14 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertEquals(42, a.getDefaultValueForTesting());
}
+ @Test
public void testFileType() throws Exception {
Object result = evalRuleClassCode("FileType(['.css'])");
SkylarkFileType fts = (SkylarkFileType) result;
assertEquals(ImmutableList.of(".css"), fts.getExtensions());
}
+ @Test
public void testRuleInheritsBaseRuleAttributes() throws Exception {
eval("def impl(ctx): return None", "r1 = rule(impl)");
RuleClass c = ((RuleFunction) lookup("r1")).getBuilder().build("r1");
@@ -373,11 +412,13 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
assertEquals(Joiner.on("\n").join(lines) + "\n", result);
}
+ @Test
public void testSimpleTextMessagesBooleanFields() throws Exception {
checkTextMessage("struct(name=True).to_proto()", "name: true");
checkTextMessage("struct(name=False).to_proto()", "name: false");
}
+ @Test
public void testSimpleTextMessages() throws Exception {
checkTextMessage("struct(name='value').to_proto()", "name: \"value\"");
checkTextMessage("struct(name=['a', 'b']).to_proto()", "name: \"a\"", "name: \"b\"");
@@ -396,12 +437,14 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"struct(a=struct(b=struct(c='c'))).to_proto()", "a {", " b {", " c: \"c\"", " }", "}");
}
+ @Test
public void testTextMessageEscapes() throws Exception {
checkTextMessage("struct(name='a\"b').to_proto()", "name: \"a\\\"b\"");
checkTextMessage("struct(name='a\\'b').to_proto()", "name: \"a'b\"");
checkTextMessage("struct(name='a\\nb').to_proto()", "name: \"a\\nb\"");
}
+ @Test
public void testTextMessageInvalidElementInListStructure() throws Exception {
checkErrorContains(
"Invalid text format, expected a struct, a string, a bool, or "
@@ -409,6 +452,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"struct(a=[['b']]).to_proto()");
}
+ @Test
public void testTextMessageInvalidStructure() throws Exception {
checkErrorContains(
"Invalid text format, expected a struct, a string, a bool, or an int "
@@ -416,7 +460,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"struct(a=DATA_CFG).to_proto()");
}
- // Regression test for b/18352962
+ @Test
public void testLabelAttrWrongDefault() throws Exception {
checkErrorContains(
"expected Label or Label-returning function or NoneType for 'default' "
@@ -424,11 +468,13 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
"attr.label(default = '//foo:bar')");
}
+ @Test
public void testLabelGetRelative() throws Exception {
assertEquals("//foo:baz", eval("Label('//foo:bar').relative('baz')").toString());
assertEquals("//baz:qux", eval("Label('//foo:bar').relative('//baz:qux')").toString());
}
+ @Test
public void testLabelGetRelativeSyntaxError() throws Exception {
checkErrorContains(
"invalid target name 'bad syntax': target names may not contain ' '",
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
index e5f7f14791..efa4a6cdf4 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
@@ -28,20 +28,25 @@ import com.google.devtools.build.lib.rules.SkylarkRuleContext;
import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider;
import com.google.devtools.build.lib.rules.python.PythonSourcesProvider;
import com.google.devtools.build.lib.skylark.util.SkylarkTestCase;
-import com.google.devtools.build.lib.syntax.Runtime;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
import com.google.devtools.build.lib.testutil.TestConstants;
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;
/**
* Tests for SkylarkRuleContext.
*/
+@RunWith(JUnit4.class)
public class SkylarkRuleContextTest extends SkylarkTestCase {
- @Override
+ @Before
public void setUp() throws Exception {
super.setUp();
scratch.file(
@@ -101,6 +106,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
reporter.removeHandler(failFastHandler);
}
+ @Test
public void testNativeRuleAttributeErrorWithMacro() throws Exception {
setUpAttributeErrorTest();
try {
@@ -119,6 +125,8 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
+ "by the macro implementation in /workspace/test/macros.bzl:10:41");
}
}
+
+ @Test
public void testSkylarkRuleAttributeErrorWithMacro() throws Exception {
setUpAttributeErrorTest();
try {
@@ -134,6 +142,8 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
+ "been caused by the macro implementation in /workspace/test/macros.bzl:12:36");
}
}
+
+ @Test
public void testNativeRuleAttributeErrorWithoutMacro() throws Exception {
setUpAttributeErrorTest();
try {
@@ -151,6 +161,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
}
}
+ @Test
public void testSkylarkRuleAttributeErrorWithoutMacro() throws Exception {
setUpAttributeErrorTest();
try {
@@ -165,24 +176,13 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
}
}
+ @Test
public void testGetPrerequisiteArtifacts() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.files.srcs");
assertArtifactList(result, ImmutableList.of("a.txt", "b.img"));
}
- public void disabledTestGetPrerequisiteArtifact() throws Exception {
- SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
- Object result = evalRuleContextCode(ruleContext, "ruleContext.file.tools");
- assertEquals("t.exe", ((Artifact) result).getFilename());
- }
-
- public void disabledTestGetPrerequisiteArtifactNoFile() throws Exception {
- SkylarkRuleContext ruleContext = createRuleContext("//foo:foo2");
- Object result = evalRuleContextCode(ruleContext, "ruleContext.file.srcs");
- assertSame(Runtime.NONE, result);
- }
-
private void assertArtifactList(Object result, List<String> artifacts) {
assertThat(result).isInstanceOf(SkylarkList.class);
SkylarkList resultList = (SkylarkList) result;
@@ -193,6 +193,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
}
}
+ @Test
public void testGetPrerequisites() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.srcs");
@@ -203,6 +204,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
assertNull(tic1.getProvider(PythonSourcesProvider.class));
}
+ @Test
public void testGetPrerequisite() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:asr");
Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.srcjar");
@@ -211,6 +213,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
assertEquals("asr-src.jar", tic.getLabel().getName());
}
+ @Test
public void testMiddleMan() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:jl");
Object result = evalRuleContextCode(ruleContext, "ruleContext.middle_man(':host_jdk')");
@@ -220,51 +223,60 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
.contains("middlemen");
}
+ @Test
public void testGetRuleAttributeListType() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.outs");
assertThat(result).isInstanceOf(SkylarkList.class);
}
+ @Test
public void testGetRuleAttributeListValue() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.outs");
assertEquals(1, ((SkylarkList) result).size());
}
+ @Test
public void testGetRuleAttributeListValueNoGet() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.outs");
assertEquals(1, ((SkylarkList) result).size());
}
+ @Test
public void testGetRuleAttributeStringTypeValue() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.cmd");
assertEquals("dummy_cmd", (String) result);
}
+ @Test
public void testGetRuleAttributeStringTypeValueNoGet() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.cmd");
assertEquals("dummy_cmd", (String) result);
}
+ @Test
public void testGetRuleAttributeBadAttributeName() throws Exception {
checkErrorContains(
createRuleContext("//foo:foo"), "No attribute 'bad'", "ruleContext.attr.bad");
}
+ @Test
public void testGetLabel() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.label");
assertEquals("//foo:foo", ((Label) result).toString());
}
+ @Test
public void testRuleError() throws Exception {
checkErrorContains(createRuleContext("//foo:foo"), "message", "fail('message')");
}
+ @Test
public void testAttributeError() throws Exception {
checkErrorContains(
createRuleContext("//foo:foo"),
@@ -272,12 +284,14 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
"fail(attr='srcs', msg='message')");
}
+ @Test
public void testGetExecutablePrerequisite() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:jl");
Object result = evalRuleContextCode(ruleContext, "ruleContext.executable._ijar");
assertEquals("ijar", ((Artifact) result).getFilename());
}
+ @Test
public void testCreateSpawnActionArgumentsWithExecutableFilesToRunProvider() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:jl");
evalRuleContextCode(
@@ -294,24 +308,28 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
assertThat(action.getCommandFilename()).endsWith("/ijar");
}
+ @Test
public void testOutputs() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
Iterable<?> result = (Iterable<?>) evalRuleContextCode(ruleContext, "ruleContext.outputs.outs");
assertEquals("d.txt", ((Artifact) Iterables.getOnlyElement(result)).getFilename());
}
+ @Test
public void testSkylarkRuleContextStr() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "'%s' % ruleContext");
assertEquals("//foo:foo", result);
}
+ @Test
public void testSkylarkRuleContextGetDefaultShellEnv() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.configuration.default_shell_env");
assertThat(result).isInstanceOf(ImmutableMap.class);
}
+ @Test
public void testCheckPlaceholders() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result =
@@ -319,6 +337,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
assertEquals(true, result);
}
+ @Test
public void testCheckPlaceholdersBadPlaceholder() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result =
@@ -326,6 +345,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
assertEquals(false, result);
}
+ @Test
public void testExpandMakeVariables() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result =
@@ -334,6 +354,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
assertEquals("DEF", result);
}
+ @Test
public void testExpandMakeVariablesShell() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result =
@@ -341,24 +362,28 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
assertEquals("$ABC", result);
}
+ @Test
public void testConfiguration() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.configuration");
assertSame(result, ruleContext.getRuleContext().getConfiguration());
}
+ @Test
public void testHostConfiguration() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.host_configuration");
assertSame(result, ruleContext.getRuleContext().getHostConfiguration());
}
+ @Test
public void testWorkspaceName() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.workspace_name");
assertSame(result, TestConstants.WORKSPACE_NAME);
}
+ @Test
public void testDeriveArtifactLegacy() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result =
@@ -369,6 +394,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
assertEquals("foo/a/b.txt", fragment.getPathString());
}
+ @Test
public void testDeriveArtifact() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.new_file('a/b.txt')");
@@ -376,6 +402,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
assertEquals("foo/a/b.txt", fragment.getPathString());
}
+ @Test
public void testParamFileLegacy() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result =
@@ -387,6 +414,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
assertEquals("foo/t.exe.params", fragment.getPathString());
}
+ @Test
public void testParamFileSuffix() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
index cd046f604b..9e9b0c073b 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
import com.google.devtools.build.lib.testutil.TestMode;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -37,7 +38,8 @@ import java.util.Map;
*/
@RunWith(JUnit4.class)
public class EvaluationTest extends EvaluationTestCase {
- public EvaluationTest() throws Exception {
+ @Before
+ public void setBuildMode() throws Exception {
super.setMode(TestMode.BUILD);
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index d027adb237..f956f94150 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -30,6 +30,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.syntax.ClassObject.SkylarkClassObject;
import com.google.devtools.build.lib.testutil.TestMode;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -39,7 +40,8 @@ import org.junit.runners.JUnit4;
*/
@RunWith(JUnit4.class)
public class SkylarkEvaluationTest extends EvaluationTest {
- public SkylarkEvaluationTest() throws Exception {
+ @Before
+ public void setup() throws Exception {
setMode(TestMode.SKYLARK);
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java b/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
index be5317d1bf..fd0cd48ad0 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
@@ -44,20 +44,16 @@ import java.util.List;
* Base class for test cases that use parsing and evaluation services.
*/
public class EvaluationTestCase {
-
- private EventCollectionApparatus eventCollectionApparatus;
+ private EventCollectionApparatus eventCollectionApparatus =
+ new EventCollectionApparatus(EventKind.ALL_EVENTS);
private PackageFactory factory;
private TestMode testMode = TestMode.SKYLARK;
protected Environment env;
protected Mutability mutability = Mutability.create("test");
- public EvaluationTestCase() {
- createNewInfrastructure();
- }
-
@Before
public void setUp() throws Exception {
- createNewInfrastructure();
+ factory = new PackageFactory(TestRuleClassProvider.getRuleClassProvider());
env = newEnvironment();
}
@@ -101,11 +97,6 @@ public class EvaluationTestCase {
return testMode.createEnvironment(getEventHandler(), null);
}
- protected void createNewInfrastructure() {
- eventCollectionApparatus = new EventCollectionApparatus(EventKind.ALL_EVENTS);
- factory = new PackageFactory(TestRuleClassProvider.getRuleClassProvider());
- }
-
/**
* Sets the specified {@code TestMode} and tries to create the appropriate {@code Environment}
* @param testMode