Skip to content

Commit d605037

Browse files
Merge pull request #7541 from bishabosha/repl-load-side-effects
Test side effects in repl :load
2 parents cbd0e31 + 902f8ac commit d605037

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

compiler/test/dotty/tools/repl/LoadTests.scala

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools.repl
22

33
import java.nio.file.{ Path, Files }
4+
import java.util.Comparator
45

56
import org.junit.{ Test, BeforeClass, AfterClass }
67
import org.junit.Assert.assertEquals
@@ -9,8 +10,11 @@ class LoadTests extends ReplTest {
910
import LoadTests._
1011

1112
@Test def helloworld = loadTest(
12-
file = """def helloWorld = "Hello, World!"""",
13-
defs = """|def helloWorld: String
13+
file = """|def helloWorld = "Hello, World!"
14+
|println(helloWorld)
15+
|""".stripMargin,
16+
defs = """|Hello, World!
17+
|def helloWorld: String
1418
|
1519
|
1620
|""".stripMargin,
@@ -21,7 +25,8 @@ class LoadTests extends ReplTest {
2125
)
2226

2327
@Test def maindef = loadTest(
24-
file = """@main def helloWorld = println("Hello, World!")""",
28+
file = """|@main def helloWorld = println("Hello, World!")
29+
|""".stripMargin,
2530
defs = """|def helloWorld: Unit
2631
|
2732
|
@@ -34,7 +39,8 @@ class LoadTests extends ReplTest {
3439

3540
@Test def maindefs = loadTest(
3641
file = """|@main def helloWorld = println("Hello, World!")
37-
|@main def helloTo(name: String) = println(s"Hello, $name!")""".stripMargin,
42+
|@main def helloTo(name: String) = println(s"Hello, $name!")
43+
|""".stripMargin,
3844
defs = """|def helloTo(name: String): Unit
3945
|def helloWorld: Unit
4046
|
@@ -67,11 +73,10 @@ object LoadTests {
6773
dir = Files.createTempDirectory("repl_load_src")
6874

6975
@AfterClass def removeDir: Unit =
70-
Files.walk(dir).filter(!Files.isDirectory(_)).forEach(Files.delete)
71-
Files.delete(dir)
76+
Files.walk(dir).sorted(Comparator.reverseOrder).forEach(Files.delete)
7277
dir = null
7378

74-
def writeFile(contents: String): Path = {
79+
private def writeFile(contents: String): Path = {
7580
val file = Files.createTempFile(dir, "repl_test", ".scala")
7681
Files.write(file, contents.getBytes)
7782
file

0 commit comments

Comments
 (0)