Skip to content

Commit 4e086fb

Browse files
committed
Run tests for utf8 characters on input path / current working directory
1 parent 3ba09c2 commit 4e086fb

File tree

3 files changed

+100
-9
lines changed

3 files changed

+100
-9
lines changed

modules/integration/src/test/scala/scala/cli/integration/RunJdkTestDefinitions.scala

+1-9
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,19 @@ trait RunJdkTestDefinitions { _: RunTestDefinitions =>
1111
s"zulu:$javaVersion"
1212
else javaVersion.toString
1313

14-
def canUseScalaInstallationWrapper: Boolean =
15-
actualScalaVersion.startsWith("3") && actualScalaVersion.split('.').drop(1).head.toInt >= 5
16-
1714
for {
1815
javaVersion <- Constants.allJavaVersions
1916
index = javaIndex(javaVersion)
2017
useScalaInstallationWrapper <-
2118
if (canUseScalaInstallationWrapper) Seq(false, true) else Seq(false)
2219
launcherString = if (useScalaInstallationWrapper) "coursier scala installation" else "Scala CLI"
23-
scalaRunnerWrapperVersion = actualScalaVersion match {
24-
case v if v == Constants.scala3NextRc => Constants.scala3NextRcAnnounced
25-
case v if v == Constants.scala3Next => Constants.scala3NextAnnounced
26-
case v => v
27-
}
2820
withLauncher = (root: os.Path) =>
2921
(f: Seq[os.Shellable] => Unit) =>
3022
if (useScalaInstallationWrapper)
3123
withScalaRunnerWrapper(
3224
root = root,
3325
localBin = root / "local-bin",
34-
scalaVersion = scalaRunnerWrapperVersion,
26+
scalaVersion = actualScalaRunnerWrapperVersion,
3527
shouldCleanUp = false
3628
)(launcher => f(Seq(launcher)))
3729
else

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

+43
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ abstract class RunTestDefinitions
3232
protected val ciOpt: Seq[String] =
3333
Option(System.getenv("CI")).map(v => Seq("-e", s"CI=$v")).getOrElse(Nil)
3434

35+
def canUseScalaInstallationWrapper: Boolean =
36+
actualScalaVersion.startsWith("3") && actualScalaVersion.split('.').drop(1).head.toInt >= 5
37+
38+
lazy val actualScalaRunnerWrapperVersion: String = actualScalaVersion match {
39+
case v if v == Constants.scala3NextRc => Constants.scala3NextRcAnnounced
40+
case v if v == Constants.scala3Next => Constants.scala3NextAnnounced
41+
case v => v
42+
}
43+
3544
test("print command") {
3645
val fileName = "simple.sc"
3746
val message = "Hello"
@@ -1071,6 +1080,40 @@ abstract class RunTestDefinitions
10711080
}
10721081
}
10731082

1083+
for {
1084+
useScalaInstallationWrapper <-
1085+
if (canUseScalaInstallationWrapper) Seq(false, true) else Seq(false)
1086+
launcherString = if (useScalaInstallationWrapper) "coursier scala installation" else "Scala CLI"
1087+
withLauncher = (root: os.Path) =>
1088+
(f: Seq[os.Shellable] => Unit) =>
1089+
if (useScalaInstallationWrapper)
1090+
withScalaRunnerWrapper(
1091+
root = root,
1092+
localBin = root / "local-bin",
1093+
scalaVersion = actualScalaRunnerWrapperVersion,
1094+
shouldCleanUp = false
1095+
)(launcher => f(Seq(launcher)))
1096+
else
1097+
f(Seq(TestUtil.cli))
1098+
}
1099+
test(
1100+
s"UTF-8 characters on the input path & current working directory path with $launcherString"
1101+
) {
1102+
val expectedMessage = "Hello"
1103+
val utf8DirPath = os.rel / "äöü"
1104+
val inputName = "Hello.sc"
1105+
val inputPath = utf8DirPath / inputName
1106+
TestInputs(inputPath -> s"""println("$expectedMessage")""")
1107+
.fromRoot { root =>
1108+
withLauncher(root / utf8DirPath) { launcher =>
1109+
println(launcher.toString())
1110+
val res = os.proc(launcher, "run", inputName, extraOptions)
1111+
.call(cwd = root / utf8DirPath)
1112+
expect(res.out.trim() == expectedMessage)
1113+
}
1114+
}
1115+
}
1116+
10741117
test("return relevant error if multiple .scala main classes are present") {
10751118
TestUtil.retryOnCi() {
10761119
val (scalaFile1, scalaFile2, scriptName) =

modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala

+56
Original file line numberDiff line numberDiff line change
@@ -884,4 +884,60 @@ class SipScalaTests extends ScalaCliSuite
884884
expect(launcherVersionOverrideHelp == standardVersionOverrideHelp)
885885
}
886886
}
887+
888+
test("coursier scala installation works with utf8 paths") {
889+
val utf8DirPath = os.rel / "äöü"
890+
TestInputs(utf8DirPath / "version.sc" ->
891+
"println(dotty.tools.dotc.config.Properties.versionNumberString)")
892+
.fromRoot { root =>
893+
val rootWithUtf8 = root / utf8DirPath
894+
val localCache = rootWithUtf8 / "local-cache"
895+
val localBin = rootWithUtf8 / "local-bin"
896+
val scalaVersion = Constants.scala3NextRcAnnounced
897+
withScalaRunnerWrapper(
898+
root = rootWithUtf8,
899+
localCache = Some(localCache),
900+
localBin = localBin,
901+
scalaVersion = scalaVersion
902+
) { launchScalaPath =>
903+
val r = os.proc(launchScalaPath, "--with-compiler", "version.sc")
904+
.call(
905+
cwd = rootWithUtf8,
906+
env = Map("COURSIER_CACHE" -> localCache.toString),
907+
check = false // need to clean up even on failure
908+
)
909+
expect(r.exitCode == 0)
910+
expect(r.out.trim() == scalaVersion)
911+
}
912+
}
913+
}
914+
915+
test("raw coursier works with utf8 paths") {
916+
val utf8DirPath = os.rel / "äöü"
917+
TestInputs(utf8DirPath / "version.sc" ->
918+
"println(dotty.tools.dotc.config.Properties.versionNumberString)")
919+
.fromRoot { root =>
920+
val rootWithUtf8 = root / utf8DirPath
921+
val localCache = rootWithUtf8 / "local-cache"
922+
val localBin = rootWithUtf8 / "local-bin"
923+
val scalaVersion = Constants.scala3NextRcAnnounced
924+
// ensure cs works at all
925+
os.proc(TestUtil.cs, "version")
926+
.call(cwd = rootWithUtf8, stdout = os.Inherit)
927+
// ensure scala is installable
928+
os.proc(
929+
TestUtil.cs,
930+
"install",
931+
"--cache",
932+
localCache,
933+
"--install-dir",
934+
localBin,
935+
s"scala:$scalaVersion"
936+
).call(cwd = rootWithUtf8)
937+
// ensure scala got installed
938+
val launcherPath = if (Properties.isWin) localBin / "scala.bat" else localBin / "scala"
939+
os.proc(launcherPath, "--version")
940+
.call(cwd = rootWithUtf8, stdout = os.Inherit)
941+
}
942+
}
887943
}

0 commit comments

Comments
 (0)