Skip to content

Add a warning for the -run option of the legacy scala runner, instead of failing #1801

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 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ case class LegacyScalaOptions(
@Name("-nc")
@Name("-nocompdaemon")
noCompilationDaemon: Option[Indexed[Boolean]] = None,
@Group("Legacy Scala runner")
@HelpMessage("Ignored legacy option. Deprecated option allowing to force the `run` mode on an input.")
@Tag(tags.must)
@Hidden
@ValueDescription("file")
@Name("-run")
run: Option[Indexed[String]] = None,
) {
// format: on

Expand All @@ -64,8 +71,16 @@ case class LegacyScalaOptions(
val howToRunString = howToRun.findArg(args)
val iString = I.findArg(args)
val noCompilationDaemonString = noCompilationDaemon.findArg(args)
val runString = run.findArg(args)
val deprecatedArgs =
Seq(saveOptionString, noSaveOptionString, howToRunString, iString, noCompilationDaemonString)
Seq(
saveOptionString,
noSaveOptionString,
howToRunString,
iString,
noCompilationDaemonString,
runString
)
.flatten
val filteredArgs = args.filterNot(deprecatedArgs.contains)
val filteredArgsString = filteredArgs.mkString(" ")
Expand Down Expand Up @@ -126,6 +141,20 @@ case class LegacyScalaOptions(
logger.message(s"Deprecated option '$nc' is ignored.")
logger.message("The script runner can no longer be picked as before.")
}
for {
rString <- runString
rValue <- run.map(_.value)
} {
logger.message(s"Deprecated option '$rString' is ignored.")
logger.message(
s"""$fullRunnerName does not support explicitly forcing the old `run` mode.
|Just pass $rValue as input and make sure it has the correct format and extension.
|i.e. to run a JAR, pass it as an input, just make sure it has the `.jar` extension and a main class.
|For details on how inputs can be run with $fullRunnerName, check the `run` sub-command.
| ${Console.BOLD}$progName run --help${Console.RESET}
|""".stripMargin
)
}
filteredArgs
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ trait LegacyScalaRunnerTestDefinitions { _: DefaultTests =>

test("ensure -howtorun/--how-to-run works with the default command") {
legacyOptionBackwardsCompatTest("-howtorun", "--how-to-run") {
(legacyHtrOption, root) =>
(legacyHtrOption, inputFile, root) =>
Seq("object", "script", "jar", "repl", "guess", "invalid").foreach { htrValue =>
val res = os.proc(TestUtil.cli, legacyHtrOption, htrValue, "s.sc", TestUtil.extraOptions)
.call(cwd = root, stderr = os.Pipe)
val res =
os.proc(TestUtil.cli, legacyHtrOption, htrValue, inputFile, TestUtil.extraOptions)
.call(cwd = root, stderr = os.Pipe)
expect(res.err.trim().contains(deprecatedOptionWarning(legacyHtrOption)))
expect(res.err.trim().contains(htrValue))
}
Expand All @@ -52,40 +53,66 @@ trait LegacyScalaRunnerTestDefinitions { _: DefaultTests =>

test("ensure -I works with the default command") {
legacyOptionBackwardsCompatTest("-I") {
(legacyOption, root) =>
val res = os.proc(TestUtil.cli, legacyOption, "--repl-dry-run", TestUtil.extraOptions)
(legacyOption, inputFile, root) =>
val anotherInputFile = "smth.scala"
val res = os.proc(
TestUtil.cli,
legacyOption,
inputFile,
legacyOption,
anotherInputFile,
"--repl-dry-run",
TestUtil.extraOptions
)
.call(cwd = root, stderr = os.Pipe)
expect(res.err.trim().contains(deprecatedOptionWarning(legacyOption)))
expect(res.err.trim().contains(inputFile))
expect(res.err.trim().contains(anotherInputFile))
}
}

test("ensure -nc/-nocompdaemon/--no-compilation-daemon works with the default command") {
simpleLegacyOptionBackwardsCompatTest("-nc", "-nocompdaemon", "--no-compilation-daemon")
}

test("ensure -run works with the default command") {
legacyOptionBackwardsCompatTest("-run") {
(legacyOption, inputFile, root) =>
val res = os.proc(TestUtil.cli, legacyOption, inputFile, ".", TestUtil.extraOptions)
.call(cwd = root, stderr = os.Pipe)
expect(res.err.trim().contains(deprecatedOptionWarning(legacyOption)))
expect(res.err.trim().contains(inputFile))
}
}

private def simpleLegacyOptionBackwardsCompatTest(optionAliases: String*): Unit =
abstractLegacyOptionBackwardsCompatTest(optionAliases) {
(legacyOption, expectedMsg, root) =>
(legacyOption, expectedMsg, _, root) =>
val res = os.proc(TestUtil.cli, legacyOption, "s.sc", TestUtil.extraOptions)
.call(cwd = root, stderr = os.Pipe)
expect(res.out.trim() == expectedMsg)
expect(res.err.trim().contains(deprecatedOptionWarning(legacyOption)))
}

private def legacyOptionBackwardsCompatTest(optionAliases: String*)(f: (String, os.Path) => Unit)
: Unit =
abstractLegacyOptionBackwardsCompatTest(optionAliases) { (legacyOption, _, root) =>
f(legacyOption, root)
private def legacyOptionBackwardsCompatTest(optionAliases: String*)(f: (
String,
String,
os.Path
) => Unit): Unit =
abstractLegacyOptionBackwardsCompatTest(optionAliases) { (legacyOption, _, inputFile, root) =>
f(legacyOption, inputFile, root)
}

private def abstractLegacyOptionBackwardsCompatTest(optionAliases: Seq[String])(f: (
String,
String,
String,
os.Path
) => Unit): Unit = {
val msg = "Hello world"
TestInputs(os.rel / "s.sc" -> s"""println("$msg")""").fromRoot { root =>
optionAliases.foreach(f(_, msg, root))
val msg = "Hello world"
val inputFile = "s.sc"
TestInputs(os.rel / inputFile -> s"""println("$msg")""").fromRoot { root =>
optionAliases.foreach(f(_, msg, inputFile, root))
}
}

Expand Down