aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2016-06-20 11:44:06 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-06-21 09:57:38 +0000
commitfc6100505ca52aa3bd488b19360f2bd2706aea98 (patch)
tree781bce14825cb31ce84001346d42ffca4ff63d96 /src/test
parent2ee0377d835af26a6488ad7b80291953860c4dce (diff)
Fixed more Bazel tests on Windows by using the right line separator
Newly passing: //src/test/java/com/google/devtools/build/... lib:syntax_test lib/skylark:SkylarkTests lib:analysis_actions_test lib:pkgcache_test -- Change-Id: Iefdcf9e90ad28e664126aa7269487db95da1000a Reviewed-on: https://bazel-review.googlesource.com/#/c/3840 MOS_MIGRATED_REVID=125324588
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java11
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java8
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java72
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java262
5 files changed, 180 insertions, 177 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java
index 216a333717..1b7f42ffa5 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java
@@ -211,8 +211,8 @@ public class TemplateExpansionActionTest extends FoundationTestCase {
// We have to overwrite the artifacts since we need our template in "inputs"
createArtifacts(SPECIAL_CHARS + "%key%");
- // scratch.overwriteFile appends a newline, so we need an additional %n here
- String expected = String.format("%s%s%n", SPECIAL_CHARS, SPECIAL_CHARS);
+ // scratch.overwriteFile appends a newline, so we need an additional \n here
+ String expected = String.format("%s%s\n", SPECIAL_CHARS, SPECIAL_CHARS);
executeTemplateExpansion(expected, ImmutableList.of(Substitution.of("%key%", SPECIAL_CHARS)));
}
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java
index 8b57ff53dc..9019156a56 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java
@@ -44,8 +44,8 @@ public final class MockToolsConfig {
this(rootDirectory, realFileSystem, null);
}
- public MockToolsConfig(Path rootDirectory, boolean realFileSystem,
- @Nullable Path runfilesDirectoryOpt) {
+ public MockToolsConfig(
+ Path rootDirectory, boolean realFileSystem, @Nullable Path runfilesDirectoryOpt) {
this.rootDirectory = rootDirectory;
this.realFileSystem = realFileSystem;
if (!realFileSystem) {
@@ -75,7 +75,7 @@ public final class MockToolsConfig {
StringBuilder newContent = new StringBuilder();
for (String line : lines) {
newContent.append(line);
- newContent.append("\n");
+ newContent.append(System.lineSeparator());
}
if (!newContent.toString().equals(existingContent)) {
@@ -127,8 +127,9 @@ public final class MockToolsConfig {
if (!target.exists()) {
// In some cases we run tests in a special client with a ../READONLY/ path where we may also
// find the runfiles. Try that, too.
- Path readOnlyClientPath = rootDirectory.getRelative(
- "../READONLY/" + TestConstants.WORKSPACE_NAME + "/" + relativePath);
+ Path readOnlyClientPath =
+ rootDirectory.getRelative(
+ "../READONLY/" + TestConstants.WORKSPACE_NAME + "/" + relativePath);
if (!readOnlyClientPath.exists()) {
throw new IOException("target does not exist " + target);
} else {
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
index 4e5d38582a..3604865843 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
@@ -55,6 +55,8 @@ public class SkylarkAspectsTest extends AnalysisTestCase {
return false;
}
+ private static final String LINE_SEPARATOR = System.lineSeparator();
+
@Test
public void testAspect() throws Exception {
scratch.file(
@@ -417,9 +419,11 @@ public class SkylarkAspectsTest extends AnalysisTestCase {
"ERROR /workspace/test/BUILD:1:1: in "
+ "//test:aspect.bzl%MyAspect aspect on java_library rule //test:xxx: \n"
+ "Traceback (most recent call last):\n"
- + "\tFile \"/workspace/test/BUILD\", line 1\n"
+ + "\tFile \"/workspace/test/BUILD\", line 1"
+ + LINE_SEPARATOR
+ "\t\t//test:aspect.bzl%MyAspect(...)\n"
- + "\tFile \"/workspace/test/aspect.bzl\", line 2, in _impl\n"
+ + "\tFile \"/workspace/test/aspect.bzl\", line 2, in _impl"
+ + LINE_SEPARATOR
+ "\t\t1 / 0\n"
+ "integer division by zero");
}
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
index e41b90c134..78067a70db 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
@@ -47,6 +47,7 @@ import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
import com.google.devtools.build.lib.testutil.MoreAsserts;
+import com.google.devtools.build.lib.util.OsUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -71,8 +72,14 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
@Param(name = "mandatory", doc = ""),
@Param(name = "optional", doc = "", defaultValue = "None"),
@Param(name = "mandatory_key", doc = "", positional = false, named = true),
- @Param(name = "optional_key", doc = "", defaultValue = "'x'",
- positional = false, named = true)},
+ @Param(
+ name = "optional_key",
+ doc = "",
+ defaultValue = "'x'",
+ positional = false,
+ named = true
+ )
+ },
useEnvironment = true
)
private BuiltinFunction mockFunc;
@@ -85,7 +92,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
BuiltinFunction throwFunction;
@Before
- public final void createBuildFile() throws Exception {
+ public final void createBuildFile() throws Exception {
scratch.file(
"foo/BUILD",
"genrule(name = 'foo',",
@@ -126,7 +133,10 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
new BuiltinFunction("mock") {
@SuppressWarnings("unused")
public Object invoke(
- Object mandatory, Object optional, Object mandatoryKey, Object optionalKey,
+ Object mandatory,
+ Object optional,
+ Object mandatoryKey,
+ Object optionalKey,
Environment env) {
return EvalUtils.optionMap(
env,
@@ -230,8 +240,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
assertArtifactFilenames(action.getInputs(), "a.txt", "b.img");
assertArtifactFilenames(action.getOutputs(), "a.txt", "b.img");
- MoreAsserts.assertContainsSublist(action.getArguments(),
- "-c", "dummy_command", "", "--a", "--b");
+ MoreAsserts.assertContainsSublist(
+ action.getArguments(), "-c", "dummy_command", "", "--a", "--b");
assertEquals("DummyMnemonic", action.getMnemonic());
assertEquals("dummy_message", action.getProgressMessage());
assertEquals(targetConfig.getLocalShellEnvironment(), action.getEnvironment());
@@ -409,7 +419,6 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
" inputs = ctx.files.srcs,",
" mnemonic = 'EA',",
" )",
-
"empty_action_rule = rule(",
" implementation = _impl,",
" attrs = {",
@@ -422,11 +431,9 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
"load('/test/empty', 'empty_action_rule')",
"empty_action_rule(name = 'my_empty_action',",
" srcs = ['foo.in', 'other_foo.in'])",
-
"action_listener(name = 'listener',",
" mnemonics = ['EA'],",
" extra_actions = [':extra'])",
-
"extra_action(name = 'extra',",
" cmd='')");
@@ -480,15 +487,16 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
assertMatches(
"Expanded string",
expectedPattern,
- (String) evalRuleContextCode(
- ruleContext, String.format("ruleContext.expand_location('$(%s)')", command)));
+ (String)
+ evalRuleContextCode(
+ ruleContext, String.format("ruleContext.expand_location('$(%s)')", command)));
}
private void assertMatches(String description, String expectedPattern, String computedValue)
throws Exception {
assertTrue(
- Printer.format("%s %r did not match pattern '%s'",
- description, computedValue, expectedPattern),
+ Printer.format(
+ "%s %r did not match pattern '%s'", description, computedValue, expectedPattern),
Pattern.matches(expectedPattern, computedValue));
}
@@ -502,7 +510,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
@SuppressWarnings("unchecked")
List<String> argv = (List<String>) (List<?>) (MutableList) lookup("argv");
assertThat(argv).hasSize(3);
- assertMatches("argv[0]", "^.*/bash$", argv.get(0));
+ assertMatches("argv[0]", "^.*/bash" + OsUtils.executableExtension() + "$", argv.get(0));
assertThat(argv.get(1)).isEqualTo("-c");
assertThat(argv.get(2)).isEqualTo("I got the World on a string");
}
@@ -537,11 +545,11 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
@SuppressWarnings("unchecked")
List<String> argv = (List<String>) (List<?>) (MutableList) lookup("argv");
assertThat(argv).hasSize(3);
- assertMatches("argv[0]", "^.*/bash$", argv.get(0));
+ assertMatches("argv[0]", "^.*/bash" + OsUtils.executableExtension() + "$", argv.get(0));
assertThat(argv.get(1)).isEqualTo("-c");
assertMatches("argv[2]", "A.*/mytool .*/mytool.sh B.*file3.dat", argv.get(2));
}
-
+
@Test
public void testResolveCommandExecutionRequirements() throws Exception {
// Tests that requires-darwin execution requirements result in the usage of /bin/bash.
@@ -567,7 +575,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
@SuppressWarnings("unchecked")
List<String> argv = (List<String>) (List<?>) (MutableList) lookup("argv");
assertThat(argv).hasSize(2);
- assertMatches("argv[0]", "^.*/bash$", argv.get(0));
+ assertMatches("argv[0]", "^.*/bash" + OsUtils.executableExtension() + "$", argv.get(0));
assertMatches("argv[1]", "^.*/resolve_me[.]script[.]sh$", argv.get(1));
}
@@ -857,7 +865,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
String java = (String) evalRuleContextCode(ctx, "ruleContext.var['JAVA']");
// Get the last path segment
java = java.substring(java.lastIndexOf('/'));
- assertEquals("/java", java);
+ assertEquals("/java" + OsUtils.executableExtension(), java);
}
@Test
@@ -908,9 +916,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
fail(
String.format(
"Found %d error(s), but none with the expected message '%s'. First error: '%s'",
- count,
- errorMsg,
- first));
+ count, errorMsg, first));
}
} finally {
eventCollector.clear();
@@ -953,7 +959,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
@Test
public void testGlobInImplicitOutputs() throws Exception {
- scratch.file("test/glob.bzl",
+ scratch.file(
+ "test/glob.bzl",
"def _impl(ctx):",
" ctx.empty_action(",
" inputs = [],",
@@ -964,7 +971,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
" implementation = _impl,",
" outputs = _foo,",
")");
- scratch.file("test/BUILD",
+ scratch.file(
+ "test/BUILD",
"load('/test/glob', 'glob_rule')",
"glob_rule(name = 'my_glob',",
" srcs = ['foo.bar', 'other_foo.bar'])");
@@ -975,15 +983,9 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
@Test
public void testRuleFromBzlFile() throws Exception {
- scratch.file("test/rule.bzl",
- "def _impl(ctx): return",
- "foo = rule(implementation = _impl)");
- scratch.file("test/ext.bzl",
- "load('//test:rule.bzl', 'foo')",
- "a = 1",
- "foo(name = 'x')");
- scratch.file("test/BUILD",
- "load('//test:ext.bzl', 'a')");
+ scratch.file("test/rule.bzl", "def _impl(ctx): return", "foo = rule(implementation = _impl)");
+ scratch.file("test/ext.bzl", "load('//test:rule.bzl', 'foo')", "a = 1", "foo(name = 'x')");
+ scratch.file("test/BUILD", "load('//test:ext.bzl', 'a')");
reporter.removeHandler(failFastHandler);
getConfiguredTarget("//test:x");
assertContainsEvent("Cannot instantiate a rule when loading a .bzl file");
@@ -991,7 +993,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
@Test
public void testImplicitOutputsFromGlob() throws Exception {
- scratch.file("test/glob.bzl",
+ scratch.file(
+ "test/glob.bzl",
"def _impl(ctx):",
" outs = ctx.outputs",
" for i in ctx.attr.srcs:",
@@ -1015,7 +1018,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
")");
scratch.file("test/a.bar", "a");
scratch.file("test/b.bar", "b");
- scratch.file("test/BUILD",
+ scratch.file(
+ "test/BUILD",
"load('/test/glob', 'glob_rule')",
"glob_rule(name = 'my_glob', srcs = glob(['*.bar']))");
ConfiguredTarget ct = getConfiguredTarget("//test:my_glob");
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
index 307164d82d..279db38b0e 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
@@ -34,6 +34,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class MethodLibraryTest extends EvaluationTestCase {
+ private static final String LINE_SEPARATOR = System.lineSeparator();
+
@Before
public final void setFailFast() throws Exception {
setFailFast(true);
@@ -348,35 +350,43 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testStackTraceLocation() throws Exception {
- new SkylarkTest().testIfErrorContains(
- "Traceback (most recent call last):\n\t"
- + "File \"<unknown>\", line 8\n\t\t"
- + "foo()\n\t"
- + "File \"<unknown>\", line 2, in foo\n\t\t"
- + "bar(1)\n\t"
- + "File \"<unknown>\", line 7, in bar\n\t\t"
- + "'test'.index(x)",
- "def foo():",
- " bar(1)",
- "def bar(x):",
- " if x == 1:",
- " a = x",
- " b = 2",
- " 'test'.index(x)",
- "foo()");
+ new SkylarkTest()
+ .testIfErrorContains(
+ "Traceback (most recent call last):\n\t"
+ + "File \"<unknown>\", line 8"
+ + LINE_SEPARATOR
+ + "\t\tfoo()\n\t"
+ + "File \"<unknown>\", line 2, in foo"
+ + LINE_SEPARATOR
+ + "\t\tbar(1)\n\t"
+ + "File \"<unknown>\", line 7, in bar"
+ + LINE_SEPARATOR
+ + "\t\t'test'.index(x)",
+ "def foo():",
+ " bar(1)",
+ "def bar(x):",
+ " if x == 1:",
+ " a = x",
+ " b = 2",
+ " 'test'.index(x)",
+ "foo()");
}
@Test
public void testStackTraceWithIf() throws Exception {
- new SkylarkTest().testIfErrorContains(
- "File \"<unknown>\", line 5\n\t\t"
- + "foo()\n\t"
- + "File \"<unknown>\", line 3, in foo\n\t\ts[0]",
- "def foo():",
- " s = set()",
- " if s[0] == 1:",
- " x = 1",
- "foo()");
+ new SkylarkTest()
+ .testIfErrorContains(
+ "File \"<unknown>\", line 5"
+ + LINE_SEPARATOR
+ + "\t\tfoo()\n\t"
+ + "File \"<unknown>\", line 3, in foo"
+ + LINE_SEPARATOR
+ + "\t\ts[0]",
+ "def foo():",
+ " s = set()",
+ " if s[0] == 1:",
+ " x = 1",
+ "foo()");
}
@Test
@@ -397,11 +407,14 @@ public class MethodLibraryTest extends EvaluationTestCase {
new SkylarkTest()
.testIfExactError(
"Traceback (most recent call last):\n"
- + "\tFile \"<unknown>\", line 6\n"
+ + "\tFile \"<unknown>\", line 6"
+ + LINE_SEPARATOR
+ "\t\tfoo()\n"
- + "\tFile \"<unknown>\", line 2, in foo\n"
+ + "\tFile \"<unknown>\", line 2, in foo"
+ + LINE_SEPARATOR
+ "\t\tbar(1)\n"
- + "\tFile \"<unknown>\", line 5, in bar\n"
+ + "\tFile \"<unknown>\", line 5, in bar"
+ + LINE_SEPARATOR
+ "\t\t'test'.index(x)\n"
+ "Method string.index(sub: string, start: int, end: int or NoneType) "
+ "is not applicable "
@@ -471,15 +484,13 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testBoolean() throws Exception {
- new BothModesTest()
- .testStatement("False", Boolean.FALSE)
- .testStatement("True", Boolean.TRUE);
+ new BothModesTest().testStatement("False", Boolean.FALSE).testStatement("True", Boolean.TRUE);
}
@Test
public void testBooleanUnsupportedOperationFails() throws Exception {
- new BothModesTest().testIfErrorContains(
- "unsupported operand type(s) for +: 'bool' and 'bool'", "True + True");
+ new BothModesTest()
+ .testIfErrorContains("unsupported operand type(s) for +: 'bool' and 'bool'", "True + True");
}
@Test
@@ -490,18 +501,20 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testPyStringGlobalJoin() throws Exception {
// TODO(bazel-team): BUILD and Skylark should use the same code path (and same error message).
- new BuildTest().testIfErrorContains(
- "name 'join' is not defined", "join(' ', [ 'a', 'b', 'c' ])");
+ new BuildTest()
+ .testIfErrorContains("name 'join' is not defined", "join(' ', [ 'a', 'b', 'c' ])");
- new SkylarkTest().testIfErrorContains("ERROR 1:1: function 'join' does not exist",
- "join(' ', [ 'a', 'b', 'c' ])");
+ new SkylarkTest()
+ .testIfErrorContains(
+ "ERROR 1:1: function 'join' does not exist", "join(' ', [ 'a', 'b', 'c' ])");
new BothModesTest().testStatement("' '.join([ 'a', 'b', 'c' ])", "a b c");
}
@Test
public void testPyStringJoinCompr() throws Exception {
- new BothModesTest().testStatement("''.join([(x + '*') for x in ['a', 'b', 'c']])", "a*b*c*")
+ new BothModesTest()
+ .testStatement("''.join([(x + '*') for x in ['a', 'b', 'c']])", "a*b*c*")
.testStatement(
"''.join([(y + '*' + z + '|') " + "for y in ['a', 'b', 'c'] for z in ['d', 'e']])",
"a*d|a*e|b*d|b*e|c*d|c*e|");
@@ -522,19 +535,17 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testPyStringReplace() throws Exception {
new BothModesTest()
- .testStatement("'banana'.replace('a', 'e')", "benene")
- .testStatement("'banana'.replace('a', '$()')", "b$()n$()n$()")
- .testStatement("'banana'.replace('a', '$')", "b$n$n$")
- .testStatement("'banana'.replace('a', '\\\\')", "b\\n\\n\\")
- .testStatement("'b$()n$()n$()'.replace('$()', '$($())')", "b$($())n$($())n$($())")
- .testStatement("'b\\\\n\\\\n\\\\'.replace('\\\\', '$()')", "b$()n$()n$()");
+ .testStatement("'banana'.replace('a', 'e')", "benene")
+ .testStatement("'banana'.replace('a', '$()')", "b$()n$()n$()")
+ .testStatement("'banana'.replace('a', '$')", "b$n$n$")
+ .testStatement("'banana'.replace('a', '\\\\')", "b\\n\\n\\")
+ .testStatement("'b$()n$()n$()'.replace('$()', '$($())')", "b$($())n$($())n$($())")
+ .testStatement("'b\\\\n\\\\n\\\\'.replace('\\\\', '$()')", "b$()n$()n$()");
}
@Test
public void testPyStringReplace2() throws Exception {
- new BothModesTest()
- .testStatement("'banana'.replace('a', 'e', 2)", "benena")
-;
+ new BothModesTest().testStatement("'banana'.replace('a', 'e', 2)", "benena");
}
@Test
@@ -554,8 +565,8 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testPyStringSplitNoSep() throws Exception {
- new BothModesTest().testEval(
- "' 1 2 3 '.split(' ')", "['', '', '1', '', '2', '', '3', '', '']");
+ new BothModesTest()
+ .testEval("' 1 2 3 '.split(' ')", "['', '', '1', '', '2', '', '3', '', '']");
}
@Test
@@ -585,13 +596,13 @@ public class MethodLibraryTest extends EvaluationTestCase {
.testEval("'xxxxxx'.rsplit('x', 5)", "['x', '', '', '', '', '']")
.testEval("'xxxxxx'.rsplit('x', 6)", "['', '', '', '', '', '', '']")
.testEval("'xxxxxx'.rsplit('x', 7)", "['', '', '', '', '', '', '']");
-
}
@Test
public void testPyStringRSplitLongerSep() throws Exception {
- new BothModesTest().testEval("'abcdabef'.rsplit('ab')", "['', 'cd', 'ef']").testEval(
- "'google_or_gogol'.rsplit('go')", "['', 'ogle_or_', '', 'l']");
+ new BothModesTest()
+ .testEval("'abcdabef'.rsplit('ab')", "['', 'cd', 'ef']")
+ .testEval("'google_or_gogol'.rsplit('go')", "['', 'ogle_or_', '', 'l']");
}
@Test
@@ -615,8 +626,9 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testPyStringPartitionEasy() throws Exception {
- new BothModesTest().testEval("'lawl'.partition('a')", "['l', 'a', 'wl']").testEval(
- "'lawl'.rpartition('a')", "['l', 'a', 'wl']");
+ new BothModesTest()
+ .testEval("'lawl'.partition('a')", "['l', 'a', 'wl']")
+ .testEval("'lawl'.rpartition('a')", "['l', 'a', 'wl']");
}
@Test
@@ -690,24 +702,25 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testPyStringTitle() throws Exception {
- new BothModesTest().testStatement(
- "'this is a very simple test'.title()", "This Is A Very Simple Test");
- new BothModesTest().testStatement(
- "'Do We Keep Capital Letters?'.title()", "Do We Keep Capital Letters?");
- new BothModesTest().testStatement(
- "'this isn\\'t just an ol\\' apostrophe test'.title()",
- "This Isn'T Just An Ol' Apostrophe Test");
- new BothModesTest().testStatement(
- "'Let us test crazy characters: _bla.exe//foo:bla(test$class)'.title()",
- "Let Us Test Crazy Characters: _Bla.Exe//Foo:Bla(Test$Class)");
- new BothModesTest().testStatement(
- "'any germans here? äöü'.title()",
- "Any Germans Here? Äöü");
- new BothModesTest().testStatement(
- "'WE HAve tO lOWERCASE soMEthING heRE, AI?'.title()",
- "We Have To Lowercase Something Here, Ai?");
- new BothModesTest().testStatement(
- "'wh4t ab0ut s0me numb3rs'.title()", "Wh4T Ab0Ut S0Me Numb3Rs");
+ new BothModesTest()
+ .testStatement("'this is a very simple test'.title()", "This Is A Very Simple Test");
+ new BothModesTest()
+ .testStatement("'Do We Keep Capital Letters?'.title()", "Do We Keep Capital Letters?");
+ new BothModesTest()
+ .testStatement(
+ "'this isn\\'t just an ol\\' apostrophe test'.title()",
+ "This Isn'T Just An Ol' Apostrophe Test");
+ new BothModesTest()
+ .testStatement(
+ "'Let us test crazy characters: _bla.exe//foo:bla(test$class)'.title()",
+ "Let Us Test Crazy Characters: _Bla.Exe//Foo:Bla(Test$Class)");
+ new BothModesTest().testStatement("'any germans here? äöü'.title()", "Any Germans Here? Äöü");
+ new BothModesTest()
+ .testStatement(
+ "'WE HAve tO lOWERCASE soMEthING heRE, AI?'.title()",
+ "We Have To Lowercase Something Here, Ai?");
+ new BothModesTest()
+ .testStatement("'wh4t ab0ut s0me numb3rs'.title()", "Wh4T Ab0Ut S0Me Numb3Rs");
}
@Test
@@ -823,30 +836,25 @@ public class MethodLibraryTest extends EvaluationTestCase {
.testStatement("'{{ }}'.format(42)", "{ }")
.testStatement("'{{{{}}}}'.format()", "{{}}")
.testStatement("'{{{{}}}}'.format(42)", "{{}}")
-
.testStatement("'{{0}}'.format(42)", "{0}")
-
.testStatement("'{{}}'.format(42)", "{}")
.testStatement("'{{{}}}'.format(42)", "{42}")
.testStatement("'{{ '.format(42)", "{ ")
.testStatement("' }}'.format(42)", " }")
.testStatement("'{{ {}'.format(42)", "{ 42")
.testStatement("'{} }}'.format(42)", "42 }")
-
.testStatement("'{{0}}'.format(42)", "{0}")
.testStatement("'{{{0}}}'.format(42)", "{42}")
.testStatement("'{{ 0'.format(42)", "{ 0")
.testStatement("'0 }}'.format(42)", "0 }")
.testStatement("'{{ {0}'.format(42)", "{ 42")
.testStatement("'{0} }}'.format(42)", "42 }")
-
.testStatement("'{{test}}'.format(test = 42)", "{test}")
.testStatement("'{{{test}}}'.format(test = 42)", "{42}")
.testStatement("'{{ test'.format(test = 42)", "{ test")
.testStatement("'test }}'.format(test = 42)", "test }")
.testStatement("'{{ {test}'.format(test = 42)", "{ 42")
.testStatement("'{test} }}'.format(test = 42)", "42 }")
-
.testIfErrorContains("Found '}' without matching '{'", "'{{}'.format(1)")
.testIfErrorContains("Found '}' without matching '{'", "'{}}'.format(1)");
}
@@ -901,12 +909,10 @@ public class MethodLibraryTest extends EvaluationTestCase {
new BothModesTest()
.testStatement("'{test} and {}'.format(2, test = 1)", "1 and 2")
.testStatement("'{test} and {0}'.format(2, test = 1)", "1 and 2")
-
.testIfErrorContains(
"non-keyword arg after keyword arg", "'{test} and {}'.format(test = 1, 2)")
.testIfErrorContains(
"non-keyword arg after keyword arg", "'{test} and {0}'.format(test = 1, 2)")
-
.testIfErrorContains(
"Cannot mix manual and automatic numbering of positional fields",
"'{} and {1}'.format(1, 2)")
@@ -918,13 +924,14 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testPyStringFormatInvalidFields() throws Exception {
for (char unsupported : new char[] {'.', '[', ']', ','}) {
- new BothModesTest().testIfErrorContains(
- String.format("Invalid character '%c' inside replacement field", unsupported),
- String.format("'{test%ctest}'.format(test = 1)", unsupported));
+ new BothModesTest()
+ .testIfErrorContains(
+ String.format("Invalid character '%c' inside replacement field", unsupported),
+ String.format("'{test%ctest}'.format(test = 1)", unsupported));
}
- new BothModesTest().testIfErrorContains(
- "Nested replacement fields are not supported", "'{ {} }'.format(42)");
+ new BothModesTest()
+ .testIfErrorContains("Nested replacement fields are not supported", "'{ {} }'.format(42)");
}
@Test
@@ -936,9 +943,7 @@ public class MethodLibraryTest extends EvaluationTestCase {
.testStatement("'{a}{b}{a}{b}'.format(a = 3, b = True)", "3True3True")
.testStatement("'{a}{b}{a}{b}'.format(a = 3, b = True)", "3True3True")
.testStatement("'{s1}{s2}'.format(s1 = ['a'], s2 = 'a')", "[\"a\"]a")
-
.testIfErrorContains("Missing argument 'b'", "'{a}{b}'.format(a = 5)")
-
.testStatement("'{a}'.format(a = '$')", "$")
.testStatement("'{a}'.format(a = '$a')", "$a")
.testStatement("'{a}$'.format(a = '$a')", "$a$");
@@ -1139,9 +1144,10 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testDictionaryAccess() throws Exception {
- new BothModesTest().testEval("{1: ['foo']}[1]", "['foo']")
- .testStatement("{'4': 8}['4']", 8)
- .testStatement("{'a': 'aa', 'b': 'bb', 'c': 'cc'}['b']", "bb");
+ new BothModesTest()
+ .testEval("{1: ['foo']}[1]", "['foo']")
+ .testStatement("{'4': 8}['4']", 8)
+ .testStatement("{'a': 'aa', 'b': 'bb', 'c': 'cc'}['b']", "bb");
}
@Test
@@ -1201,9 +1207,7 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testStringSliceStep_EmptyString() throws Exception {
- new BothModesTest()
- .testStatement("''[::1]", "")
- .testStatement("''[::-1]", "");
+ new BothModesTest().testStatement("''[::1]", "").testStatement("''[::-1]", "");
}
@Test
@@ -1226,9 +1230,7 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testStringSliceStep_WrongOrder() throws Exception {
- new BothModesTest()
- .testStatement("'123'[3:1:1]", "")
- .testStatement("'123'[1:3:-1]", "");
+ new BothModesTest().testStatement("'123'[3:1:1]", "").testStatement("'123'[1:3:-1]", "");
}
@Test
@@ -1258,9 +1260,7 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testDictionaryCreationEmpty() throws Exception {
- new BothModesTest()
- .testEval("dict()", "{}")
- .testEval("dict([])", "{}");
+ new BothModesTest().testEval("dict()", "{}").testEval("dict([])", "{}");
}
@Test
@@ -1279,8 +1279,7 @@ public class MethodLibraryTest extends EvaluationTestCase {
new BothModesTest()
.testEval("dict([('a', 42), ('b', 2), ('a', 1), ('c', 3)])", expected)
.testEval("dict([('a', 42)], a = 1, b = 2, c = 3)", expected);
- new SkylarkTest()
- .testEval("dict([('a', 42)], **{'a': 1, 'b': 2, 'c': 3})", expected);
+ new SkylarkTest().testEval("dict([('a', 42)], **{'a': 1, 'b': 2, 'c': 3})", expected);
}
@Test
@@ -1288,7 +1287,7 @@ public class MethodLibraryTest extends EvaluationTestCase {
new BothModesTest()
.testIfErrorContains(
"expected value of type 'list(object)' for parameter args in dict(), "
- + "but got \"a\" (string)",
+ + "but got \"a\" (string)",
"dict('a')")
.testIfErrorContains(
"Cannot convert dictionary update sequence element #0 to a sequence", "dict(['a'])")
@@ -1344,9 +1343,9 @@ public class MethodLibraryTest extends EvaluationTestCase {
new SkylarkTest()
.testEval(
"d = {1: 'foo', 2: 'bar', 3: 'baz'}\n"
- + "if len(d) != 3: fail('clear 1')\n"
- + "if d.clear() != None: fail('clear 2')\n"
- + "d",
+ + "if len(d) != 3: fail('clear 1')\n"
+ + "if d.clear() != None: fail('clear 2')\n"
+ + "d",
"{}");
}
@@ -1356,13 +1355,13 @@ public class MethodLibraryTest extends EvaluationTestCase {
.testIfErrorContains(
"KeyError: 1",
"d = {1: 'foo', 2: 'bar', 3: 'baz'}\n"
- + "if len(d) != 3: fail('pop 1')\n"
- + "if d.pop(2) != 'bar': fail('pop 2')\n"
- + "if d.pop(3, 'quux') != 'baz': fail('pop 3a')\n"
- + "if d.pop(3, 'quux') != 'quux': fail('pop 3b')\n"
- + "if d.pop(1) != 'foo': fail('pop 1')\n"
- + "if d != {}: fail('pop 0')\n"
- + "d.pop(1)");
+ + "if len(d) != 3: fail('pop 1')\n"
+ + "if d.pop(2) != 'bar': fail('pop 2')\n"
+ + "if d.pop(3, 'quux') != 'baz': fail('pop 3a')\n"
+ + "if d.pop(3, 'quux') != 'quux': fail('pop 3b')\n"
+ + "if d.pop(1) != 'foo': fail('pop 1')\n"
+ + "if d != {}: fail('pop 0')\n"
+ + "d.pop(1)");
}
@Test
@@ -1371,12 +1370,12 @@ public class MethodLibraryTest extends EvaluationTestCase {
.testIfErrorContains(
"popitem(): dictionary is empty",
"d = {2: 'bar', 3: 'baz', 1: 'foo'}\n"
- + "if len(d) != 3: fail('popitem 0')\n"
- + "if d.popitem() != (1, 'foo'): fail('popitem 1')\n"
- + "if d.popitem() != (2, 'bar'): fail('popitem 2')\n"
- + "if d.popitem() != (3, 'baz'): fail('popitem 3')\n"
- + "if d != {}: fail('popitem 4')\n"
- + "d.popitem()");
+ + "if len(d) != 3: fail('popitem 0')\n"
+ + "if d.popitem() != (1, 'foo'): fail('popitem 1')\n"
+ + "if d.popitem() != (2, 'bar'): fail('popitem 2')\n"
+ + "if d.popitem() != (3, 'baz'): fail('popitem 3')\n"
+ + "if d != {}: fail('popitem 4')\n"
+ + "d.popitem()");
}
@Test
@@ -1394,12 +1393,12 @@ public class MethodLibraryTest extends EvaluationTestCase {
new SkylarkTest()
.testEval(
"d = {2: 'bar', 1: 'foo'}\n"
- + "if len(d) != 2: fail('setdefault 0')\n"
- + "if d.setdefault(1, 'a') != 'foo': fail('setdefault 1')\n"
- + "if d.setdefault(2) != 'bar': fail('setdefault 2')\n"
- + "if d.setdefault(3) != None: fail('setdefault 3')\n"
- + "if d.setdefault(4, 'b') != 'b': fail('setdefault 4')\n"
- + "d",
+ + "if len(d) != 2: fail('setdefault 0')\n"
+ + "if d.setdefault(1, 'a') != 'foo': fail('setdefault 1')\n"
+ + "if d.setdefault(2) != 'bar': fail('setdefault 2')\n"
+ + "if d.setdefault(3) != None: fail('setdefault 3')\n"
+ + "if d.setdefault(4, 'b') != 'b': fail('setdefault 4')\n"
+ + "d",
"{1: 'foo', 2: 'bar', 3: None, 4: 'b'}");
}
@@ -1440,11 +1439,7 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testSetUnionSideEffects() throws Exception {
- eval("def func():",
- " n1 = set(['a'])",
- " n2 = n1.union(['b'])",
- " return n1",
- "n = func()");
+ eval("def func():", " n1 = set(['a'])", " n2 = n1.union(['b'])", " return n1", "n = func()");
assertEquals(ImmutableList.of("a"), ((SkylarkNestedSet) lookup("n")).toCollection());
}
@@ -1495,13 +1490,11 @@ public class MethodLibraryTest extends EvaluationTestCase {
.testStatement("str(range(0))", "[]")
.testStatement("str(range(1))", "[0]")
.testStatement("str(range(-2))", "[]")
-
.testStatement("str(range(-3, 2))", "[-3, -2, -1, 0, 1]")
.testStatement("str(range(3, 2))", "[]")
.testStatement("str(range(3, 3))", "[]")
.testStatement("str(range(3, 4))", "[3]")
.testStatement("str(range(3, 5))", "[3, 4]")
-
.testStatement("str(range(-3, 5, 2))", "[-3, -1, 1, 3]")
.testStatement("str(range(-3, 6, 2))", "[-3, -1, 1, 3, 5]")
.testStatement("str(range(5, 0, -1))", "[5, 4, 3, 2, 1]")
@@ -1522,10 +1515,11 @@ public class MethodLibraryTest extends EvaluationTestCase {
@Test
public void testEnumerateBadArg() throws Exception {
- new BothModesTest().testIfErrorContains(
- "Method enumerate(list: sequence) is not applicable for arguments (string): "
- + "'list' is string, but should be sequence",
- "enumerate('a')");
+ new BothModesTest()
+ .testIfErrorContains(
+ "Method enumerate(list: sequence) is not applicable for arguments (string): "
+ + "'list' is string, but should be sequence",
+ "enumerate('a')");
}
@Test