@@ -39,7 +39,9 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
39
39
extension [A ](state : State )
40
40
def andThen (op : State => A ): A = op(state)
41
41
42
- def testFile (f : JFile ): Unit = {
42
+ def testFile (f : JFile ): Unit = testScript(f.toString, readLines(f))
43
+
44
+ def testScript (name : => String , lines : List [String ]): Unit = {
43
45
val prompt = " scala>"
44
46
45
47
def evaluate (state : State , input : String ) =
@@ -50,7 +52,7 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
50
52
}
51
53
catch {
52
54
case ex : Throwable =>
53
- System .err.println(s " failed while running script: $f , on: \n $input" )
55
+ System .err.println(s " failed while running script: $name , on: \n $input" )
54
56
throw ex
55
57
}
56
58
@@ -60,13 +62,12 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
60
62
case nonEmptyLine => nonEmptyLine :: Nil
61
63
}
62
64
63
- val expectedOutput = readLines(f) .flatMap(filterEmpties)
65
+ val expectedOutput = lines .flatMap(filterEmpties)
64
66
val actualOutput = {
65
67
resetToInitial()
66
68
67
- val lines = readLines(f)
68
69
assert(lines.head.startsWith(prompt),
69
- s """ Each file has to start with the prompt: " $prompt" """ )
70
+ s """ Each script must start with the prompt: " $prompt" """ )
70
71
val inputRes = lines.filter(_.startsWith(prompt))
71
72
72
73
val buf = new ArrayBuffer [String ]
@@ -88,7 +89,7 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
88
89
println(" actual ===========>" )
89
90
println(actualOutput.mkString(EOL ))
90
91
91
- fail(s " Error in file $f , expected output did not match actual " )
92
+ fail(s " Error in script $name , expected output did not match actual " )
92
93
end if
93
94
}
94
95
}
0 commit comments