Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run tests for utf8 characters on input path / current working directory
Browse files Browse the repository at this point in the history
Gedochao committed Jan 30, 2025
1 parent 3ba09c2 commit 4e086fb
Showing 3 changed files with 100 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -11,27 +11,19 @@ trait RunJdkTestDefinitions { _: RunTestDefinitions =>
s"zulu:$javaVersion"
else javaVersion.toString

def canUseScalaInstallationWrapper: Boolean =
actualScalaVersion.startsWith("3") && actualScalaVersion.split('.').drop(1).head.toInt >= 5

for {
javaVersion <- Constants.allJavaVersions
index = javaIndex(javaVersion)
useScalaInstallationWrapper <-
if (canUseScalaInstallationWrapper) Seq(false, true) else Seq(false)
launcherString = if (useScalaInstallationWrapper) "coursier scala installation" else "Scala CLI"
scalaRunnerWrapperVersion = actualScalaVersion match {
case v if v == Constants.scala3NextRc => Constants.scala3NextRcAnnounced
case v if v == Constants.scala3Next => Constants.scala3NextAnnounced
case v => v
}
withLauncher = (root: os.Path) =>
(f: Seq[os.Shellable] => Unit) =>
if (useScalaInstallationWrapper)
withScalaRunnerWrapper(
root = root,
localBin = root / "local-bin",
scalaVersion = scalaRunnerWrapperVersion,
scalaVersion = actualScalaRunnerWrapperVersion,
shouldCleanUp = false
)(launcher => f(Seq(launcher)))
else
Original file line number Diff line number Diff line change
@@ -32,6 +32,15 @@ abstract class RunTestDefinitions
protected val ciOpt: Seq[String] =
Option(System.getenv("CI")).map(v => Seq("-e", s"CI=$v")).getOrElse(Nil)

def canUseScalaInstallationWrapper: Boolean =
actualScalaVersion.startsWith("3") && actualScalaVersion.split('.').drop(1).head.toInt >= 5

lazy val actualScalaRunnerWrapperVersion: String = actualScalaVersion match {
case v if v == Constants.scala3NextRc => Constants.scala3NextRcAnnounced
case v if v == Constants.scala3Next => Constants.scala3NextAnnounced
case v => v
}

test("print command") {
val fileName = "simple.sc"
val message = "Hello"
@@ -1071,6 +1080,40 @@ abstract class RunTestDefinitions
}
}

for {
useScalaInstallationWrapper <-
if (canUseScalaInstallationWrapper) Seq(false, true) else Seq(false)
launcherString = if (useScalaInstallationWrapper) "coursier scala installation" else "Scala CLI"
withLauncher = (root: os.Path) =>
(f: Seq[os.Shellable] => Unit) =>
if (useScalaInstallationWrapper)
withScalaRunnerWrapper(
root = root,
localBin = root / "local-bin",
scalaVersion = actualScalaRunnerWrapperVersion,
shouldCleanUp = false
)(launcher => f(Seq(launcher)))
else
f(Seq(TestUtil.cli))
}
test(
s"UTF-8 characters on the input path & current working directory path with $launcherString"
) {
val expectedMessage = "Hello"
val utf8DirPath = os.rel / "äöü"
val inputName = "Hello.sc"
val inputPath = utf8DirPath / inputName
TestInputs(inputPath -> s"""println("$expectedMessage")""")
.fromRoot { root =>
withLauncher(root / utf8DirPath) { launcher =>
println(launcher.toString())
val res = os.proc(launcher, "run", inputName, extraOptions)
.call(cwd = root / utf8DirPath)
expect(res.out.trim() == expectedMessage)
}
}
}

test("return relevant error if multiple .scala main classes are present") {
TestUtil.retryOnCi() {
val (scalaFile1, scalaFile2, scriptName) =
Original file line number Diff line number Diff line change
@@ -884,4 +884,60 @@ class SipScalaTests extends ScalaCliSuite
expect(launcherVersionOverrideHelp == standardVersionOverrideHelp)
}
}

test("coursier scala installation works with utf8 paths") {
val utf8DirPath = os.rel / "äöü"
TestInputs(utf8DirPath / "version.sc" ->
"println(dotty.tools.dotc.config.Properties.versionNumberString)")
.fromRoot { root =>
val rootWithUtf8 = root / utf8DirPath
val localCache = rootWithUtf8 / "local-cache"
val localBin = rootWithUtf8 / "local-bin"
val scalaVersion = Constants.scala3NextRcAnnounced
withScalaRunnerWrapper(
root = rootWithUtf8,
localCache = Some(localCache),
localBin = localBin,
scalaVersion = scalaVersion
) { launchScalaPath =>
val r = os.proc(launchScalaPath, "--with-compiler", "version.sc")
.call(
cwd = rootWithUtf8,
env = Map("COURSIER_CACHE" -> localCache.toString),
check = false // need to clean up even on failure
)
expect(r.exitCode == 0)
expect(r.out.trim() == scalaVersion)
}
}
}

test("raw coursier works with utf8 paths") {
val utf8DirPath = os.rel / "äöü"
TestInputs(utf8DirPath / "version.sc" ->
"println(dotty.tools.dotc.config.Properties.versionNumberString)")
.fromRoot { root =>
val rootWithUtf8 = root / utf8DirPath
val localCache = rootWithUtf8 / "local-cache"
val localBin = rootWithUtf8 / "local-bin"
val scalaVersion = Constants.scala3NextRcAnnounced
// ensure cs works at all
os.proc(TestUtil.cs, "version")
.call(cwd = rootWithUtf8, stdout = os.Inherit)
// ensure scala is installable
os.proc(
TestUtil.cs,
"install",
"--cache",
localCache,
"--install-dir",
localBin,
s"scala:$scalaVersion"
).call(cwd = rootWithUtf8)
// ensure scala got installed
val launcherPath = if (Properties.isWin) localBin / "scala.bat" else localBin / "scala"
os.proc(launcherPath, "--version")
.call(cwd = rootWithUtf8, stdout = os.Inherit)
}
}
}

0 comments on commit 4e086fb

Please sign in to comment.