@@ -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