Skip to content
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

Ensure compiler options relevant to syntax rewriting don't require being passed after -O #1501

Merged
merged 1 commit into from
Oct 27, 2022
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 @@ -33,11 +33,20 @@ object ScalacOptions {
private val scalacOptionsPurePrefixes =
Set("-V", "-W", "-X", "-Y")
private val scalacOptionsPrefixes =
Set("-g", "-language", "-opt", "-P", "-target") ++ scalacOptionsPurePrefixes
Set("-g", "-language", "-opt", "-P", "-target", "-source") ++ scalacOptionsPurePrefixes
private val scalacAliasedOptions = // these options don't require being passed after -O and accept an arg
Set("-encoding", "-release", "-color")
private val scalacNoArgAliasedOptions = // these options don't require being passed after -O and don't accept an arg
Set("-nowarn", "-feature", "-deprecation")
Set(
"-nowarn",
"-feature",
"-deprecation",
"-rewrite",
"-old-syntax",
"-new-syntax",
"-indent",
"-no-indent"
)

/** This includes all the scalac options which disregard inputs and print a help and/or context
* message instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2573,4 +2573,53 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
expect(res.out.trim() == "€")
}
}

if (actualScalaVersion.startsWith("3") || actualScalaVersion.startsWith("2.13")) {
val fileName = "Main.scala"
val expectedOutput = "Hello"
val oldSyntaxCode =
s"""object Main extends App {
| if (true) println("$expectedOutput") else println("Error")
|}
|""".stripMargin
val newSyntaxCode =
s"""object Main extends App {
| if true then println("$expectedOutput") else println("Error")
|}
|""".stripMargin

test("rewrite code to new syntax and then run it correctly (no -O required)") {
TestInputs(os.rel / fileName -> oldSyntaxCode)
.fromRoot { root =>
val res = os.proc(
TestUtil.cli,
fileName,
"-new-syntax",
"-rewrite",
"-source:3.2-migration"
).call(cwd = root, stderr = os.Pipe)
val filePath = root / fileName
expect(res.err.trim().contains(s"[patched file $filePath]"))
expect(os.read(filePath) == newSyntaxCode)
expect(res.out.trim() == expectedOutput)
}
}

test("rewrite code to old syntax and then run it correctly (no -O required)") {
TestInputs(os.rel / fileName -> newSyntaxCode)
.fromRoot { root =>
val res = os.proc(
TestUtil.cli,
fileName,
"-old-syntax",
"-rewrite",
"-source:3.2-migration"
).call(cwd = root, stderr = os.Pipe)
val filePath = root / fileName
expect(res.err.trim().contains(s"[patched file $filePath]"))
expect(os.read(filePath) == oldSyntaxCode)
expect(res.out.trim() == expectedOutput)
}
}
}
}