diff --git a/compiler/testData/repl/evaluationErrors.repl b/compiler/testData/repl/evaluationErrors.repl index e08c0c56289..790febac499 100644 --- a/compiler/testData/repl/evaluationErrors.repl +++ b/compiler/testData/repl/evaluationErrors.repl @@ -1,5 +1,5 @@ >>> throw Exception("hi there") -stack trace +substring: Exception: hi there >>> fun foo() = 2 null >>> foo() diff --git a/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTest.java b/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTest.java index 51c10b98eec..6609fcfc8a9 100644 --- a/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTest.java +++ b/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTest.java @@ -56,9 +56,10 @@ public class ReplInterpreterTest { ReplInterpreter repl = new ReplInterpreter(disposable, compilerDependencies, Collections.singletonList(new File("out/production/runtime"))); ReplSessionTestFile file = ReplSessionTestFile.load(new File("compiler/testData/repl/" + relativePath)); - for (Pair t : file.getLines()) { - String code = t.first; - String expected = t.second.replaceFirst("\r?\n$", ""); + for (ReplSessionTestFile.OneLine t : file.getLines()) { + String code = t.getCode(); + String expected = t.getExpected().replaceFirst("\r?\n$", ""); + ReplSessionTestFile.MatchType matchType = t.getMatchType(); ReplInterpreter.LineResult lineResult = repl.eval(code); Object actual; @@ -70,7 +71,13 @@ public class ReplInterpreterTest { } String actualString = (actual != null ? actual.toString() : "null").replaceFirst("\r?\n$", ""); - Assert.assertEquals("after evaluation of: " + code, expected, actualString); + if (matchType == ReplSessionTestFile.MatchType.EQUALS) { + Assert.assertEquals("after evaluation of: " + code, expected, actualString); + } + else if (matchType == ReplSessionTestFile.MatchType.SUBSTRING) { + Assert.assertTrue("must contain substring: " + expected + ", actual: " + actualString, actualString.contains(expected)); + } + } } @@ -133,8 +140,7 @@ public class ReplInterpreterTest { @Test public void evaluationErrors() { - // TODO - //testFile("evaluationErrors.repl"); + testFile("evaluationErrors.repl"); } diff --git a/compiler/tests/org/jetbrains/jet/repl/ReplSessionTestFile.java b/compiler/tests/org/jetbrains/jet/repl/ReplSessionTestFile.java index f8f77de2f6c..a4a7574c7b3 100644 --- a/compiler/tests/org/jetbrains/jet/repl/ReplSessionTestFile.java +++ b/compiler/tests/org/jetbrains/jet/repl/ReplSessionTestFile.java @@ -36,15 +36,50 @@ import java.util.regex.Pattern; */ public class ReplSessionTestFile { - @NotNull - private final List> lines; + public enum MatchType { + EQUALS, + SUBSTRING, + } - public ReplSessionTestFile(@NotNull List> lines) { + public static class OneLine { + @NotNull + private final String code; + @NotNull + private final String expected; + @NotNull + private final MatchType matchType; + + public OneLine(@NotNull String code, @NotNull String expected, @NotNull MatchType matchType) { + this.code = code; + this.expected = expected; + this.matchType = matchType; + } + + @NotNull + public String getCode() { + return code; + } + + @NotNull + public String getExpected() { + return expected; + } + + @NotNull + public MatchType getMatchType() { + return matchType; + } + } + + @NotNull + private final List lines; + + public ReplSessionTestFile(@NotNull List lines) { this.lines = lines; } @NotNull - public List> getLines() { + public List getLines() { return lines; } @@ -64,19 +99,29 @@ public class ReplSessionTestFile { } private static ReplSessionTestFile load(@NotNull SimpleLinesParser parser) throws IOException { - List> list = Lists.newArrayList(); + List list = Lists.newArrayList(); + + Pattern startPattern = Pattern.compile(">>>( |$)(.*)"); + Pattern substringPattern = Pattern.compile("substring: (.*)"); + while (!parser.lookingAtEof()) { - Pattern startPattern = Pattern.compile(">>>( |$)(.*)"); Matcher matcher = parser.next(startPattern); String code = matcher.group(2); StringBuilder value = new StringBuilder(); + Matcher substringMatcher = parser.lookingAt(substringPattern); + if (substringMatcher != null) { + list.add(new OneLine(code, substringMatcher.group(1), MatchType.SUBSTRING)); + parser.next(); + continue; + } + while (!parser.lookingAtEof() && parser.lookingAt(startPattern) == null) { value.append(parser.next()).append("\n"); } - list.add(Pair.create(code, value.toString())); + list.add(new OneLine(code, value.toString(), MatchType.EQUALS)); } return new ReplSessionTestFile(list); }