Skip to content

Test side effects in repl :load #7541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions compiler/test/dotty/tools/repl/LoadTests.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dotty.tools.repl

import java.nio.file.{ Path, Files }
import java.util.Comparator

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

@Test def helloworld = loadTest(
file = """def helloWorld = "Hello, World!"""",
defs = """|def helloWorld: String
file = """|def helloWorld = "Hello, World!"
|println(helloWorld)
|""".stripMargin,
defs = """|Hello, World!
|def helloWorld: String
|
|
|""".stripMargin,
Expand All @@ -21,7 +25,8 @@ class LoadTests extends ReplTest {
)

@Test def maindef = loadTest(
file = """@main def helloWorld = println("Hello, World!")""",
file = """|@main def helloWorld = println("Hello, World!")
|""".stripMargin,
defs = """|def helloWorld: Unit
|
|
Expand All @@ -34,7 +39,8 @@ class LoadTests extends ReplTest {

@Test def maindefs = loadTest(
file = """|@main def helloWorld = println("Hello, World!")
|@main def helloTo(name: String) = println(s"Hello, $name!")""".stripMargin,
|@main def helloTo(name: String) = println(s"Hello, $name!")
|""".stripMargin,
defs = """|def helloTo(name: String): Unit
|def helloWorld: Unit
|
Expand Down Expand Up @@ -67,11 +73,10 @@ object LoadTests {
dir = Files.createTempDirectory("repl_load_src")

@AfterClass def removeDir: Unit =
Files.walk(dir).filter(!Files.isDirectory(_)).forEach(Files.delete)
Files.delete(dir)
Files.walk(dir).sorted(Comparator.reverseOrder).forEach(Files.delete)
dir = null

def writeFile(contents: String): Path = {
private def writeFile(contents: String): Path = {
val file = Files.createTempFile(dir, "repl_test", ".scala")
Files.write(file, contents.getBytes)
file
Expand Down