test for repl evaluation exception
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
>>> throw Exception("hi there")
|
>>> throw Exception("hi there")
|
||||||
stack trace
|
substring: Exception: hi there
|
||||||
>>> fun foo() = 2
|
>>> fun foo() = 2
|
||||||
null
|
null
|
||||||
>>> foo()
|
>>> foo()
|
||||||
|
|||||||
@@ -56,9 +56,10 @@ public class ReplInterpreterTest {
|
|||||||
ReplInterpreter repl = new ReplInterpreter(disposable, compilerDependencies, Collections.singletonList(new File("out/production/runtime")));
|
ReplInterpreter repl = new ReplInterpreter(disposable, compilerDependencies, Collections.singletonList(new File("out/production/runtime")));
|
||||||
|
|
||||||
ReplSessionTestFile file = ReplSessionTestFile.load(new File("compiler/testData/repl/" + relativePath));
|
ReplSessionTestFile file = ReplSessionTestFile.load(new File("compiler/testData/repl/" + relativePath));
|
||||||
for (Pair<String, String> t : file.getLines()) {
|
for (ReplSessionTestFile.OneLine t : file.getLines()) {
|
||||||
String code = t.first;
|
String code = t.getCode();
|
||||||
String expected = t.second.replaceFirst("\r?\n$", "");
|
String expected = t.getExpected().replaceFirst("\r?\n$", "");
|
||||||
|
ReplSessionTestFile.MatchType matchType = t.getMatchType();
|
||||||
|
|
||||||
ReplInterpreter.LineResult lineResult = repl.eval(code);
|
ReplInterpreter.LineResult lineResult = repl.eval(code);
|
||||||
Object actual;
|
Object actual;
|
||||||
@@ -70,7 +71,13 @@ public class ReplInterpreterTest {
|
|||||||
}
|
}
|
||||||
String actualString = (actual != null ? actual.toString() : "null").replaceFirst("\r?\n$", "");
|
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
|
@Test
|
||||||
public void evaluationErrors() {
|
public void evaluationErrors() {
|
||||||
// TODO
|
testFile("evaluationErrors.repl");
|
||||||
//testFile("evaluationErrors.repl");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,15 +36,50 @@ import java.util.regex.Pattern;
|
|||||||
*/
|
*/
|
||||||
public class ReplSessionTestFile {
|
public class ReplSessionTestFile {
|
||||||
|
|
||||||
@NotNull
|
public enum MatchType {
|
||||||
private final List<Pair<String, String>> lines;
|
EQUALS,
|
||||||
|
SUBSTRING,
|
||||||
|
}
|
||||||
|
|
||||||
public ReplSessionTestFile(@NotNull List<Pair<String, String>> 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<OneLine> lines;
|
||||||
|
|
||||||
|
public ReplSessionTestFile(@NotNull List<OneLine> lines) {
|
||||||
this.lines = lines;
|
this.lines = lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<Pair<String, String>> getLines() {
|
public List<OneLine> getLines() {
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,19 +99,29 @@ public class ReplSessionTestFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ReplSessionTestFile load(@NotNull SimpleLinesParser parser) throws IOException {
|
private static ReplSessionTestFile load(@NotNull SimpleLinesParser parser) throws IOException {
|
||||||
List<Pair<String, String>> list = Lists.newArrayList();
|
List<OneLine> list = Lists.newArrayList();
|
||||||
|
|
||||||
|
Pattern startPattern = Pattern.compile(">>>( |$)(.*)");
|
||||||
|
Pattern substringPattern = Pattern.compile("substring: (.*)");
|
||||||
|
|
||||||
while (!parser.lookingAtEof()) {
|
while (!parser.lookingAtEof()) {
|
||||||
Pattern startPattern = Pattern.compile(">>>( |$)(.*)");
|
|
||||||
Matcher matcher = parser.next(startPattern);
|
Matcher matcher = parser.next(startPattern);
|
||||||
String code = matcher.group(2);
|
String code = matcher.group(2);
|
||||||
|
|
||||||
StringBuilder value = new StringBuilder();
|
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) {
|
while (!parser.lookingAtEof() && parser.lookingAt(startPattern) == null) {
|
||||||
value.append(parser.next()).append("\n");
|
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);
|
return new ReplSessionTestFile(list);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user