Skip to content

Commit 8d0e4e3

Browse files
committed
[WIP] Migrate Ammonite REPL tests to Scala 3 REPL
1 parent 514ea74 commit 8d0e4e3

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

modules/integration/src/test/scala/scala/cli/integration/ReplAmmoniteTestDefinitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.eed3si9n.expecty.Expecty.expect
55
import scala.cli.integration.TestUtil.{normalizeArgsForWindows, removeAnsiColors}
66

77
trait ReplAmmoniteTestDefinitions { this: ReplTestDefinitions =>
8-
protected val ammonitePrefix: String = "Ammonite REPL:"
8+
protected val ammonitePrefix: String = "Running in Ammonite REPL:"
99
def expectedScalaVersionForAmmonite: String =
1010
actualScalaVersion match {
1111
case s

modules/integration/src/test/scala/scala/cli/integration/ReplTestDefinitions.scala

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@ abstract class ReplTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
1515
actualScalaVersion.coursierVersion >= "3.7.0-RC1".coursierVersion
1616

1717
protected val dryRunPrefix: String = "Dry run:"
18-
protected val runInReplPrefix: String = "Running in REPL:"
18+
protected val runInReplPrefix: String = "Running in Scala REPL:"
1919

2020
def runInRepl(
2121
codeToRunInRepl: String,
22-
testInputs: TestInputs = TestInputs.empty
22+
testInputs: TestInputs = TestInputs.empty,
23+
cliOptions: Seq[String] = Seq.empty
2324
)(f: os.CommandResult => Unit): Unit = {
2425
testInputs.fromRoot { root =>
2526
f(
2627
os.proc(
2728
TestUtil.cli,
2829
"repl",
30+
".",
2931
"--repl-quit-after-init",
3032
"--repl-init-script",
3133
codeToRunInRepl,
32-
extraOptions
34+
extraOptions,
35+
cliOptions
3336
)
3437
.call(cwd = root)
3538
)
@@ -114,11 +117,39 @@ abstract class ReplTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
114117
expect(output.contains("typer"))
115118
}
116119

117-
if canRunInRepl then
120+
if canRunInRepl then {
118121
test(s"$runInReplPrefix simple") {
119122
val expectedMessage = "1337"
120123
runInRepl(s"""println($expectedMessage)""")(r =>
121124
expect(r.out.trim() == expectedMessage)
122125
)
123126
}
127+
128+
test(s"$runInReplPrefix verify Scala version from the REPL") {
129+
val opts = if actualScalaVersion.startsWith("3") && !isScala38OrNewer then
130+
Seq("--with-compiler")
131+
else Seq.empty
132+
runInRepl(
133+
codeToRunInRepl = s"""println($retrieveScalaVersionCode)""",
134+
cliOptions = opts
135+
)(r => expect(r.out.trim() == actualScalaVersion))
136+
}
137+
138+
test(s"$runInReplPrefix test scope") {
139+
val message = "something something something REPL"
140+
runInRepl(
141+
codeToRunInRepl = "println(example.TestScopeExample.message)",
142+
testInputs = TestInputs(
143+
os.rel / "example" / "TestScopeExample.test.scala" ->
144+
s"""package example
145+
|
146+
|object TestScopeExample {
147+
| def message: String = "$message"
148+
|}
149+
|""".stripMargin
150+
),
151+
cliOptions = Seq("--test")
152+
)(r => expect(r.out.trim() == message))
153+
}
154+
}
124155
}

0 commit comments

Comments
 (0)