File tree 3 files changed +33
-35
lines changed
cli/src/main/scala/scala/cli/commands
integration/src/test/scala/scala/cli/integration 3 files changed +33
-35
lines changed Original file line number Diff line number Diff line change @@ -407,20 +407,15 @@ object Repl extends ScalaCommand[ReplOptions] with BuildCommandHelpers {
407
407
extraProps : Map [String , String ] = Map .empty
408
408
): Unit = {
409
409
val isAmmonite = replArtifacts.replMainClass.startsWith(" ammonite" )
410
- if replArgs.exists(_.noDashPrefixes == ScalacOptions .replInitScript) then
411
- scalaParams.scalaVersion match
412
- case _ if isAmmonite =>
410
+ if isAmmonite then
411
+ replArgs
412
+ .map(_.noDashPrefixes)
413
+ .filter(ScalacOptions .replExecuteScriptOptions.contains)
414
+ .foreach(arg =>
413
415
logger.message(
414
- " The '--repl-init-script ' option is not supported with Ammonite. Did you mean to use '--ammonite-arg' ?"
416
+ s " The '-- $arg ' option is not supported with Ammonite. Did you mean to use '--ammonite-arg -c' to execute a script ? "
415
417
)
416
- case s
417
- if s.coursierVersion < " 3.6.4-RC1" .coursierVersion &&
418
- s.coursierVersion < " 3.6.4" .coursierVersion &&
419
- s.coursierVersion < " 3.6.4-RC1-bin-20250109-a50a1e4-NIGHTLY" .coursierVersion =>
420
- logger.message(
421
- " The '--repl-init-script option' is only supported starting with Scala 3.6.4 and onwards."
422
- )
423
- case _ => ()
418
+ )
424
419
if dryRun then logger.message(" Dry run, not running REPL." )
425
420
else {
426
421
val depClassPathArgs : Seq [String ] =
Original file line number Diff line number Diff line change @@ -48,8 +48,10 @@ object ScalacOptions {
48
48
val YScriptRunnerOption = " Yscriptrunner"
49
49
private val scalacOptionsPurePrefixes = Set (" V" , " W" , " X" , " Y" )
50
50
private val scalacOptionsPrefixes = Set (" P" ) ++ scalacOptionsPurePrefixes
51
- val replInitScript = " repl-init-script"
52
- private val replAliasedOptions = Set (replInitScript)
51
+ val replExecuteScriptOptions @ Seq (replInitScript, replQuitAfterInit) =
52
+ Seq (" repl-init-script" , " repl-quit-after-init" )
53
+ private val replAliasedOptions = Set (replInitScript)
54
+ private val replNoArgAliasedOptions = Set (replQuitAfterInit)
53
55
private val scalacAliasedOptions = // these options don't require being passed after -O and accept an arg
54
56
Set (
55
57
" coverage-exclude-classlikes" ,
@@ -77,7 +79,7 @@ object ScalacOptions {
77
79
" new-syntax" ,
78
80
" indent" ,
79
81
" no-indent"
80
- )
82
+ ) ++ replNoArgAliasedOptions
81
83
82
84
/** This includes all the scalac options which disregard inputs and print a help and/or context
83
85
* message instead.
Original file line number Diff line number Diff line change @@ -87,25 +87,26 @@ abstract class ReplTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
87
87
}
88
88
}
89
89
90
- test(" --repl-init-script dry run" ) {
91
- TestInputs .empty.fromRoot { root =>
92
- val r = os.proc(
93
- TestUtil .cli,
94
- " repl" ,
95
- extraOptions,
96
- " --repl-init-script" ,
97
- " println(\" Hello\" )" ,
98
- " --repl-dry-run"
99
- )
100
- .call(cwd = root, stderr = os.Pipe , check = false )
101
- val warningText =
102
- " The '--repl-init-script option' is only supported starting with Scala 3.6.4 and onwards."
103
- val coursierScalaVersion = actualScalaVersion.coursierVersion
104
- val shouldPrintWarning = coursierScalaVersion < " 3.6.4" .coursierVersion &&
105
- coursierScalaVersion < " 3.6.4-RC1" .coursierVersion &&
106
- coursierScalaVersion < " 3.6.4-RC1-bin-20250109-a50a1e4-NIGHTLY" .coursierVersion
107
- if (shouldPrintWarning) expect(r.err.trim().contains(warningText))
108
- else expect(! r.err.trim().contains(warningText))
90
+ if (
91
+ (actualScalaVersion.startsWith(" 3.3" ) &&
92
+ actualScalaVersion.coursierVersion >= " 3.3.7" .coursierVersion) ||
93
+ actualScalaVersion.startsWith(" 3.7" ) ||
94
+ actualScalaVersion.coursierVersion >= " 3.7.0-RC1" .coursierVersion
95
+ )
96
+ test(" run hello world from the REPL" ) {
97
+ TestInputs .empty.fromRoot { root =>
98
+ val expectedMessage = " 1337"
99
+ val code = s """ println( $expectedMessage) """
100
+ val r = os.proc(
101
+ TestUtil .cli,
102
+ " repl" ,
103
+ " --repl-quit-after-init" ,
104
+ " --repl-init-script" ,
105
+ code,
106
+ extraOptions
107
+ )
108
+ .call(cwd = root)
109
+ expect(r.out.trim() == expectedMessage)
110
+ }
109
111
}
110
- }
111
112
}
You can’t perform that action at this time.
0 commit comments