aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar Han-Wen Nienhuys <hanwen@google.com>2015-02-26 14:51:57 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-02-26 14:51:57 +0000
commit6682a318a75c4d19e4202753265af64eba5f340b (patch)
tree828acf4fe742afdf7ddcaf840588f3bfb19068db /src/test/java
parent40405afc62d38156daacbbeac1132b19cdf14456 (diff)
Update syntax tests to JUnit4.
-- MOS_MIGRATED_REVID=87248208
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java28
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java19
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java30
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java32
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java14
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java17
6 files changed, 128 insertions, 12 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java b/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
index eff5c92e73..e32005065c 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
@@ -13,6 +13,11 @@
// limitations under the License.
package com.google.devtools.build.lib.syntax;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventCollector;
import com.google.devtools.build.lib.events.EventKind;
@@ -23,12 +28,15 @@ import com.google.devtools.build.lib.testutil.JunitTestUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.util.FsApparatus;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import java.io.IOException;
import java.util.Arrays;
-public class BuildFileASTTest extends TestCase {
+@RunWith(JUnit4.class)
+public class BuildFileASTTest {
private FsApparatus scratch = FsApparatus.newInMemory();
@@ -52,6 +60,7 @@ public class BuildFileASTTest extends TestCase {
return BuildFileAST.parseBuildFile(file, events.reporter(), locator, false);
}
+ @Test
public void testParseBuildFileOK() throws Exception {
Path buildFile = scratch.file("/BUILD",
"# a file in the build language",
@@ -72,6 +81,7 @@ public class BuildFileASTTest extends TestCase {
env.lookup("x"));
}
+ @Test
public void testEvalException() throws Exception {
Path buildFile = scratch.file("/input1.BUILD",
"x = 1",
@@ -91,6 +101,7 @@ public class BuildFileASTTest extends TestCase {
assertEquals(4, e.getLocation().getStartLineAndColumn().getLine());
}
+ @Test
public void testParsesFineWithNewlines() throws Exception {
BuildFileAST buildFileAST = parseBuildFile("foo()\n"
+ "bar()\n"
@@ -99,6 +110,7 @@ public class BuildFileASTTest extends TestCase {
assertEquals(4, buildFileAST.getStatements().size());
}
+ @Test
public void testFailsIfNewlinesAreMissing() throws Exception {
events.setFailFast(false);
@@ -113,6 +125,7 @@ public class BuildFileASTTest extends TestCase {
assertTrue(buildFileAST.containsErrors());
}
+ @Test
public void testImplicitStringConcatenationFails() throws Exception {
events.setFailFast(false);
BuildFileAST buildFileAST = parseBuildFile("a = 'foo' 'bar'");
@@ -126,6 +139,7 @@ public class BuildFileASTTest extends TestCase {
assertTrue(buildFileAST.containsErrors());
}
+ @Test
public void testImplicitStringConcatenationAcrossLinesIsIllegal() throws Exception {
events.setFailFast(false);
BuildFileAST buildFileAST = parseBuildFile("a = 'foo'\n 'bar'");
@@ -154,6 +168,7 @@ public class BuildFileASTTest extends TestCase {
return null;
}
+ @Test
public void testWithSyntaxErrorsDoesNotPrintDollarError() throws Exception {
events.setFailFast(false);
BuildFileAST buildFile = parseBuildFile(
@@ -176,6 +191,7 @@ public class BuildFileASTTest extends TestCase {
assertNull(event2);
}
+ @Test
public void testInclude() throws Exception {
scratch.file("/foo/bar/BUILD",
"c = 4\n"
@@ -192,6 +208,7 @@ public class BuildFileASTTest extends TestCase {
assertEquals(5, buildFileAST.getStatements().size());
}
+ @Test
public void testInclude2() throws Exception {
scratch.file("/foo/bar/defs",
"a = 1\n");
@@ -211,6 +228,7 @@ public class BuildFileASTTest extends TestCase {
assertEquals(2, env.lookup("b"));
}
+ @Test
public void testMultipleIncludes() throws Exception {
String fileA =
"include(\"//foo:fileB\")\n"
@@ -235,6 +253,7 @@ public class BuildFileASTTest extends TestCase {
assertEquals(7, env.lookup("c"));
}
+ @Test
public void testFailInclude() throws Exception {
events.setFailFast(false);
BuildFileAST buildFileAST = parseBuildFile("include(\"//nonexistent\")");
@@ -252,6 +271,7 @@ public class BuildFileASTTest extends TestCase {
private CachingPackageLocator emptyLocator = new EmptyPackageLocator();
+ @Test
public void testFailInclude2() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/foo/bar/BUILD",
@@ -262,6 +282,7 @@ public class BuildFileASTTest extends TestCase {
events.assertContainsEvent("Package 'nonexistent' not found");
}
+ @Test
public void testInvalidInclude() throws Exception {
events.setFailFast(false);
BuildFileAST buildFileAST = parseBuildFile("include(2)");
@@ -269,6 +290,7 @@ public class BuildFileASTTest extends TestCase {
events.assertContainsEvent("syntax error at '2'");
}
+ @Test
public void testRecursiveInclude() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/foo/bar/BUILD",
@@ -278,6 +300,7 @@ public class BuildFileASTTest extends TestCase {
events.assertContainsEvent("Recursive inclusion");
}
+ @Test
public void testParseErrorInclude() throws Exception {
events.setFailFast(false);
@@ -292,6 +315,7 @@ public class BuildFileASTTest extends TestCase {
assertEquals("syntax error at '%'", event.getMessage());
}
+ @Test
public void testNonExistentIncludeReported() throws Exception {
events.setFailFast(false);
BuildFileAST buildFileAST = parseBuildFile("include('//foo:bar')");
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
index 595055b042..7aad74fba9 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
@@ -14,9 +14,16 @@
package com.google.devtools.build.lib.syntax;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import com.google.common.collect.Lists;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import java.util.Arrays;
import java.util.IllegalFormatException;
@@ -28,7 +35,8 @@ import java.util.Map;
* Test properties of the evaluator's datatypes and utility functions
* without actually creating any parse trees.
*/
-public class EvalUtilsTest extends TestCase {
+@RunWith(JUnit4.class)
+public class EvalUtilsTest {
private static List<?> makeList(Object ...args) {
return EvalUtils.makeSequence(Arrays.<Object>asList(args), false);
@@ -49,6 +57,7 @@ public class EvalUtilsTest extends TestCase {
}
}
+ @Test
public void testDataTypeNames() throws Exception {
assertEquals("string", EvalUtils.getDataTypeName("foo"));
assertEquals("int", EvalUtils.getDataTypeName(3));
@@ -59,6 +68,7 @@ public class EvalUtilsTest extends TestCase {
assertEquals("None", EvalUtils.getDataTypeName(Environment.NONE));
}
+ @Test
public void testDatatypeMutability() throws Exception {
assertTrue(EvalUtils.isImmutable("foo"));
assertTrue(EvalUtils.isImmutable(3));
@@ -68,6 +78,7 @@ public class EvalUtilsTest extends TestCase {
assertFalse(EvalUtils.isImmutable(makeFilesetEntry()));
}
+ @Test
public void testPrintValue() throws Exception {
// Note that prettyPrintValue and printValue only differ on behaviour of
// labels and strings at toplevel.
@@ -120,6 +131,7 @@ public class EvalUtilsTest extends TestCase {
}
}
+ @Test
public void testFormatPositional() throws Exception {
assertEquals("foo 3", EvalUtils.formatString("%s %d", makeTuple("foo", 3)));
@@ -165,6 +177,7 @@ public class EvalUtilsTest extends TestCase {
".");
}
+ @Test
public void testFilesetEntrySymlinkAttr() throws Exception {
FilesetEntry entryDereference =
createTestFilesetEntry(FilesetEntry.SymlinkBehavior.DEREFERENCE);
@@ -184,6 +197,7 @@ public class EvalUtilsTest extends TestCase {
stripPrefix);
}
+ @Test
public void testFilesetEntryStripPrefixAttr() throws Exception {
FilesetEntry withoutStripPrefix = createStripPrefixFilesetEntry(".");
FilesetEntry withStripPrefix = createStripPrefixFilesetEntry("orange");
@@ -195,6 +209,7 @@ public class EvalUtilsTest extends TestCase {
assertTrue(prettyWith.contains("strip_prefix = \"orange\""));
}
+ @Test
public void testRegressionCrashInPrettyPrintValue() throws Exception {
// Would cause crash in code such as this:
// Fileset(name='x', entries=[], out=[FilesetEntry(files=['a'])])
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java b/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java
index 75fed7d4e2..58a27833fa 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java
@@ -13,18 +13,27 @@
// limitations under the License.
package com.google.devtools.build.lib.syntax;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.testutil.Suite;
import com.google.devtools.build.lib.testutil.TestSpec;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Links for {@link GlobCriteria}
*/
@TestSpec(size = Suite.SMALL_TESTS)
-public class GlobCriteriaTest extends TestCase {
+@RunWith(JUnit4.class)
+public class GlobCriteriaTest {
+ @Test
public void testParse_EmptyList() throws Exception {
GlobCriteria gc = GlobCriteria.parse("[]");
assertFalse(gc.isGlob());
@@ -32,6 +41,7 @@ public class GlobCriteriaTest extends TestCase {
assertTrue(gc.getExcludePatterns().isEmpty());
}
+ @Test
public void testParse_SingleList() throws Exception {
GlobCriteria gc = GlobCriteria.parse("['abc']");
assertFalse(gc.isGlob());
@@ -39,6 +49,7 @@ public class GlobCriteriaTest extends TestCase {
assertTrue(gc.getExcludePatterns().isEmpty());
}
+ @Test
public void testParse_MultipleList() throws Exception {
GlobCriteria gc = GlobCriteria.parse("['abc', 'def', 'ghi']");
assertFalse(gc.isGlob());
@@ -46,6 +57,7 @@ public class GlobCriteriaTest extends TestCase {
assertTrue(gc.getExcludePatterns().isEmpty());
}
+ @Test
public void testParse_EmptyGlob() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob([])");
assertTrue(gc.isGlob());
@@ -53,6 +65,7 @@ public class GlobCriteriaTest extends TestCase {
assertTrue(gc.getExcludePatterns().isEmpty());
}
+ @Test
public void testParse_SingleGlob() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['abc'])");
assertTrue(gc.isGlob());
@@ -60,6 +73,7 @@ public class GlobCriteriaTest extends TestCase {
assertTrue(gc.getExcludePatterns().isEmpty());
}
+ @Test
public void testParse_MultipleGlob() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['abc', 'def', 'ghi'])");
assertTrue(gc.isGlob());
@@ -67,6 +81,7 @@ public class GlobCriteriaTest extends TestCase {
assertTrue(gc.getExcludePatterns().isEmpty());
}
+ @Test
public void testParse_EmptyGlobWithExclude() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob([], exclude=['xyz'])");
assertTrue(gc.isGlob());
@@ -74,6 +89,7 @@ public class GlobCriteriaTest extends TestCase {
assertEquals(ImmutableList.of("xyz"), gc.getExcludePatterns());
}
+ @Test
public void testParse_SingleGlobWithExclude() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['abc'], exclude=['xyz'])");
assertTrue(gc.isGlob());
@@ -81,6 +97,7 @@ public class GlobCriteriaTest extends TestCase {
assertEquals(ImmutableList.of("xyz"), gc.getExcludePatterns());
}
+ @Test
public void testParse_MultipleGlobWithExclude() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['abc', 'def', 'ghi'], exclude=['xyz'])");
assertTrue(gc.isGlob());
@@ -88,6 +105,7 @@ public class GlobCriteriaTest extends TestCase {
assertEquals(ImmutableList.of("xyz"), gc.getExcludePatterns());
}
+ @Test
public void testParse_MultipleGlobWithMultipleExclude() throws Exception {
GlobCriteria gc = GlobCriteria.parse(
"glob(['abc', 'def', 'ghi'], exclude=['rst', 'uvw', 'xyz'])");
@@ -96,6 +114,7 @@ public class GlobCriteriaTest extends TestCase {
assertEquals(ImmutableList.of("rst", "uvw", "xyz"), gc.getExcludePatterns());
}
+ @Test
public void testParse_GlobWithSlashesAndWildcards() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['java/src/net/jsunit/*.java'])");
assertTrue(gc.isGlob());
@@ -103,6 +122,7 @@ public class GlobCriteriaTest extends TestCase {
assertTrue(gc.getExcludePatterns().isEmpty());
}
+ @Test
public void testParse_ExcludeWithInvalidLabel() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['abc', 'def', 'ghi'], exclude=['xyz~'])");
assertTrue(gc.isGlob());
@@ -110,6 +130,7 @@ public class GlobCriteriaTest extends TestCase {
assertEquals(ImmutableList.of("xyz~"), gc.getExcludePatterns());
}
+ @Test
public void testParse_InvalidFormat_TooManySpacesList() throws Exception {
try {
GlobCriteria.parse("glob(['abc, 'def', 'ghi'], exclude=['xyz~'])");
@@ -119,6 +140,7 @@ public class GlobCriteriaTest extends TestCase {
}
}
+ @Test
public void testParse_InvalidFormat_MissingQuote() throws Exception {
try {
GlobCriteria.parse("glob(['abc, 'def', 'ghi'], exclude=['xyz~'])");
@@ -128,6 +150,7 @@ public class GlobCriteriaTest extends TestCase {
}
}
+ @Test
public void testParse_InvalidFormat_TooManySpacesExclude() throws Exception {
try {
GlobCriteria.parse("glob(['abc', 'def', 'ghi'], exclude=['xyz~'])");
@@ -137,6 +160,7 @@ public class GlobCriteriaTest extends TestCase {
}
}
+ @Test
public void testParse_InvalidFormat_MissingQuoteExclude() throws Exception {
try {
GlobCriteria.parse("glob(['abc, 'def', 'ghi'], exclude=['xyz~])");
@@ -146,6 +170,7 @@ public class GlobCriteriaTest extends TestCase {
}
}
+ @Test
public void testParse_InvalidFormat_ExcludeWithList() throws Exception {
try {
GlobCriteria.parse("['abc, 'def', 'ghi'], exclude=['xyz~']");
@@ -155,6 +180,7 @@ public class GlobCriteriaTest extends TestCase {
}
}
+ @Test
public void testParse_veryLongString() throws Exception {
StringBuilder builder = new StringBuilder();
builder.append("['File0.java'");
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java b/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java
index 96725e5cd6..e7d6c3739d 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java
@@ -13,6 +13,10 @@
// limitations under the License.
package com.google.devtools.build.lib.syntax;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.EventKind;
@@ -21,12 +25,15 @@ import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.util.FsApparatus;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests of tokenization behavior of the {@link Lexer}.
*/
-public class LexerTest extends TestCase {
+@RunWith(JUnit4.class)
+public class LexerTest {
private String lastError;
private Location lastErrorLocation;
private FsApparatus scratch = FsApparatus.newInMemory();
@@ -126,6 +133,7 @@ public class LexerTest extends TestCase {
return buf.toString();
}
+ @Test
public void testBasics1() throws Exception {
assertEquals("IDENTIFIER RPAREN NEWLINE EOF", names(tokens("wiz) ")));
assertEquals("IDENTIFIER RPAREN NEWLINE EOF", names(tokens("wiz )")));
@@ -134,6 +142,7 @@ public class LexerTest extends TestCase {
assertEquals("IDENTIFIER RPAREN NEWLINE EOF", names(tokens("wiz\t)")));
}
+ @Test
public void testBasics2() throws Exception {
assertEquals("RPAREN NEWLINE EOF", names(tokens(")")));
assertEquals("RPAREN NEWLINE EOF", names(tokens(" )")));
@@ -141,6 +150,7 @@ public class LexerTest extends TestCase {
assertEquals("RPAREN NEWLINE EOF", names(tokens(") ")));
}
+ @Test
public void testBasics3() throws Exception {
assertEquals("INT COMMENT NEWLINE INT NEWLINE EOF", names(tokens("123#456\n789")));
assertEquals("INT COMMENT NEWLINE INT NEWLINE EOF", names(tokens("123 #456\n789")));
@@ -150,6 +160,7 @@ public class LexerTest extends TestCase {
assertEquals("INT COMMENT NEWLINE INT NEWLINE EOF", names(tokens("123#456\n789 ")));
}
+ @Test
public void testBasics4() throws Exception {
assertEquals("NEWLINE EOF", names(tokens("")));
assertEquals("COMMENT NEWLINE EOF", names(tokens("# foo")));
@@ -159,6 +170,7 @@ public class LexerTest extends TestCase {
+ "NEWLINE EOF", names(tokens("foo(bar, wiz)")));
}
+ @Test
public void testIntegers() throws Exception {
// Detection of MINUS immediately following integer constant proves we
// don't consume too many chars.
@@ -185,6 +197,7 @@ public class LexerTest extends TestCase {
values(tokens("0x12345g-")));
}
+ @Test
public void testIntegersAndDot() throws Exception {
assertEquals("INT(1) DOT INT(2345) NEWLINE EOF", values(tokens("1.2345")));
@@ -212,11 +225,13 @@ public class LexerTest extends TestCase {
values(tokens("foo.xyz")));
}
+ @Test
public void testStringDelimiters() throws Exception {
assertEquals("STRING(foo) NEWLINE EOF", values(tokens("\"foo\"")));
assertEquals("STRING(foo) NEWLINE EOF", values(tokens("'foo'")));
}
+ @Test
public void testQuotesInStrings() throws Exception {
assertEquals("STRING(foo'bar) NEWLINE EOF", values(tokens("'foo\\'bar'")));
assertEquals("STRING(foo'bar) NEWLINE EOF", values(tokens("\"foo'bar\"")));
@@ -225,6 +240,7 @@ public class LexerTest extends TestCase {
values(tokens("\"foo\\\"bar\"")));
}
+ @Test
public void testStringEscapes() throws Exception {
assertEquals("STRING(a\tb\nc\rd) NEWLINE EOF",
values(tokens("'a\\tb\\nc\\rd'"))); // \t \r \n
@@ -253,6 +269,7 @@ public class LexerTest extends TestCase {
lastError.toString());
}
+ @Test
public void testOctalEscapes() throws Exception {
// Regression test for a bug.
assertEquals("STRING(\0 \1 \t \u003f I I1 \u00ff \u00ff \u00fe) NEWLINE EOF",
@@ -261,6 +278,7 @@ public class LexerTest extends TestCase {
assertEquals("STRING(\1b \1) NEWLINE EOF", values(tokens("'\\1b \\1'")));
}
+ @Test
public void testTripleQuotedStrings() throws Exception {
assertEquals("STRING(a\"b'c \n d\"\"e) NEWLINE EOF",
values(tokens("\"\"\"a\"b'c \n d\"\"e\"\"\"")));
@@ -268,6 +286,7 @@ public class LexerTest extends TestCase {
values(tokens("'''a\"b'c \n d\"\"e'''")));
}
+ @Test
public void testBadChar() throws Exception {
assertEquals("IDENTIFIER(a) IDENTIFIER(b) NEWLINE EOF",
values(tokens("a$b")));
@@ -275,6 +294,7 @@ public class LexerTest extends TestCase {
lastError.toString());
}
+ @Test
public void testIndentation() throws Exception {
assertEquals("INT(1) NEWLINE INT(2) NEWLINE INT(3) NEWLINE EOF",
values(tokens("1\n2\n3")));
@@ -295,6 +315,7 @@ public class LexerTest extends TestCase {
assertEquals("/some/path.txt:4: indentation error", lastError.toString());
}
+ @Test
public void testIndentationInsideParens() throws Exception {
// Indentation is ignored inside parens:
assertEquals("INT(1) LPAREN INT(2) INT(3) INT(4) INT(5) NEWLINE EOF",
@@ -308,12 +329,14 @@ public class LexerTest extends TestCase {
values(tokens("1 [\n 2]\n 3\n 4\n5")));
}
+ @Test
public void testIndentationAtEOF() throws Exception {
// Matching OUTDENTS are created at EOF:
assertEquals("INDENT INT(1) NEWLINE OUTDENT NEWLINE EOF",
values(tokens("\n 1")));
}
+ @Test
public void testBlankLineIndentation() throws Exception {
// Blank lines and comment lines should not generate any newlines indents
// (but note that every input ends with NEWLINE EOF).
@@ -331,6 +354,7 @@ public class LexerTest extends TestCase {
+ " return x\n")));
}
+ @Test
public void testMultipleCommentLines() throws Exception {
assertEquals("COMMENT NEWLINE COMMENT COMMENT COMMENT "
+ "DEF IDENTIFIER LPAREN IDENTIFIER RPAREN COLON NEWLINE "
@@ -343,6 +367,7 @@ public class LexerTest extends TestCase {
+ " return x\n")));
}
+ @Test
public void testBackslash() throws Exception {
assertEquals("IDENTIFIER IDENTIFIER NEWLINE EOF",
names(tokens("a\\\nb")));
@@ -352,6 +377,7 @@ public class LexerTest extends TestCase {
names(tokens("a(\\\n2)")));
}
+ @Test
public void testTokenPositions() throws Exception {
// foo ( bar , { 1 :
assertEquals("[0,3) [3,4) [4,7) [7,8) [9,10) [10,11) [11,12)"
@@ -360,6 +386,7 @@ public class LexerTest extends TestCase {
positions(tokens("foo(bar, {1: 'quux'})")));
}
+ @Test
public void testLineNumbers() throws Exception {
assertEquals("1 1 1 1 2 2 2 2 4 4 4 4 4",
linenums("foo = 1\nbar = 2\n\nwiz = 3"));
@@ -379,6 +406,7 @@ public class LexerTest extends TestCase {
assertEquals("1 1 2 2 2", linenums(s));
}
+ @Test
public void testContainsErrors() throws Exception {
Lexer lexerSuccess = createLexer("foo");
assertFalse(lexerSuccess.containsErrors());
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java b/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java
index f1fdd77f90..83e68d4648 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java
@@ -13,16 +13,21 @@
// limitations under the License.
package com.google.devtools.build.lib.syntax;
+import static org.junit.Assert.assertEquals;
+
import com.google.devtools.build.lib.events.Location.LineAndColumn;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.util.FsApparatus;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests for {@link LineNumberTable}.
*/
-public class LineNumberTableTest extends TestCase {
+@RunWith(JUnit4.class)
+public class LineNumberTableTest {
private FsApparatus scratch = FsApparatus.newInMemory();
private LineNumberTable create(String buffer) {
@@ -30,17 +35,20 @@ public class LineNumberTableTest extends TestCase {
scratch.path("/fake/file"));
}
+ @Test
public void testEmpty() {
LineNumberTable table = create("");
assertEquals(new LineAndColumn(1, 1), table.getLineAndColumn(0));
}
+ @Test
public void testNewline() {
LineNumberTable table = create("\n");
assertEquals(new LineAndColumn(1, 1), table.getLineAndColumn(0));
assertEquals(new LineAndColumn(2, 1), table.getLineAndColumn(1));
}
+ @Test
public void testOneLiner() {
LineNumberTable table = create("foo");
assertEquals(new LineAndColumn(1, 1), table.getLineAndColumn(0));
@@ -49,6 +57,7 @@ public class LineNumberTableTest extends TestCase {
assertEquals(Pair.of(0, 3), table.getOffsetsForLine(1));
}
+ @Test
public void testMultiLiner() {
LineNumberTable table = create("\ntwo\nthree\n\nfive\n");
@@ -78,6 +87,7 @@ public class LineNumberTableTest extends TestCase {
assertEquals(Pair.of(12, 17), table.getOffsetsForLine(5));
}
+ @Test
public void testHashLine() {
String data = "#\n"
+ "#line 67 \"/foo\"\n"
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
index 1d0e50c8fc..930ba277d4 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
@@ -14,11 +14,15 @@
package com.google.devtools.build.lib.syntax;
import static com.google.devtools.build.lib.util.StringUtilities.joinLines;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.util.FsApparatus;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -27,10 +31,12 @@ import java.io.InputStream;
/**
* A test case for {@link ParserInputSource}.
*/
-public class ParserInputSourceTest extends TestCase {
+@RunWith(JUnit4.class)
+public class ParserInputSourceTest {
private FsApparatus scratch = FsApparatus.newInMemory();
+ @Test
public void testCreateFromFile() throws IOException {
String content = joinLines("Line 1", "Line 2", "Line 3", "");
Path file = scratch.file("/tmp/my/file.txt", content);
@@ -39,6 +45,7 @@ public class ParserInputSourceTest extends TestCase {
assertEquals("/tmp/my/file.txt", input.getPath().toString());
}
+ @Test
public void testCreateFromString() {
String content = "Content provided as a string.";
String pathName = "/the/name/of/the/content.txt";
@@ -48,6 +55,7 @@ public class ParserInputSourceTest extends TestCase {
assertEquals(pathName, input.getPath().toString());
}
+ @Test
public void testCreateFromCharArray() {
String content = "Content provided as a string.";
String pathName = "/the/name/of/the/content.txt";
@@ -58,6 +66,7 @@ public class ParserInputSourceTest extends TestCase {
assertEquals(pathName, input.getPath().toString());
}
+ @Test
public void testCreateFromInputStream() throws IOException {
String content = "Content provided as a string.";
byte[] bytes = content.getBytes("ISO-8859-1");
@@ -69,6 +78,7 @@ public class ParserInputSourceTest extends TestCase {
assertEquals(pathName, input.getPath().toString());
}
+ @Test
public void testIOExceptionIfInputFileDoesNotExistForSingleArgConstructor() {
try {
Path path = scratch.path("/does/not/exist");
@@ -80,17 +90,20 @@ public class ParserInputSourceTest extends TestCase {
}
}
+ @Test
public void testWillNotTryToReadInputFileIfContentProvidedAsString() {
Path path = scratch.path("/will/not/try/to/read");
ParserInputSource.create("Content provided as string.", path);
}
+ @Test
public void testWillNotTryToReadInputFileIfContentProvidedAsChars() {
Path path = scratch.path("/will/not/try/to/read");
char[] content = "Content provided as char array.".toCharArray();
ParserInputSource.create(content, path);
}
+ @Test
public void testWillCloseStreamWhenReadingFromInputStream() {
final StringBuilder log = new StringBuilder();
InputStream in = new InputStream() {