File tree Expand file tree Collapse file tree 3 files changed +33
-35
lines changed
cli/src/main/scala/scala/cli/commands
integration/src/test/scala/scala/cli/integration Expand file tree Collapse file tree 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 {
407407 extraProps : Map [String , String ] = Map .empty
408408 ): Unit = {
409409 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 =>
413415 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 ? "
415417 )
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+ )
424419 if dryRun then logger.message(" Dry run, not running REPL." )
425420 else {
426421 val depClassPathArgs : Seq [String ] =
Original file line number Diff line number Diff line change @@ -48,8 +48,10 @@ object ScalacOptions {
4848 val YScriptRunnerOption = " Yscriptrunner"
4949 private val scalacOptionsPurePrefixes = Set (" V" , " W" , " X" , " Y" )
5050 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)
5355 private val scalacAliasedOptions = // these options don't require being passed after -O and accept an arg
5456 Set (
5557 " coverage-exclude-classlikes" ,
@@ -77,7 +79,7 @@ object ScalacOptions {
7779 " new-syntax" ,
7880 " indent" ,
7981 " no-indent"
80- )
82+ ) ++ replNoArgAliasedOptions
8183
8284 /** This includes all the scalac options which disregard inputs and print a help and/or context
8385 * message instead.
Original file line number Diff line number Diff line change @@ -87,25 +87,26 @@ abstract class ReplTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
8787 }
8888 }
8989
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+ }
109111 }
110- }
111112}
You can’t perform that action at this time.
0 commit comments