Skip to content

Commit

Permalink
Run tests for utf8 characters on input path / current working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Dec 5, 2024
1 parent fbc7cb1 commit f303e9f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ trait CoursierScalaInstallationTestHelper {
0,
underlyingScriptPath.toString().indexOf(scalaVersion) + scalaVersion.length
))
System.err.println(s"Cleaning up, trying to remove $csPrebuiltBinaryDir")
try {
os.remove.all(csPrebuiltBinaryDir)
if (!Properties.isWin) {
System.err.println(s"Cleaning up, trying to remove $csPrebuiltBinaryDir")
try {
os.remove.all(csPrebuiltBinaryDir)

System.err.println(s"Cleanup complete. Removed $csPrebuiltBinaryDir")
}
catch {
case ex: java.nio.file.FileSystemException =>
System.err.println(s"Failed to remove $csPrebuiltBinaryDir: $ex")
System.err.println(s"Cleanup complete. Removed $csPrebuiltBinaryDir")
}
catch {
case ex: java.nio.file.FileSystemException =>
System.err.println(s"Failed to remove $csPrebuiltBinaryDir: $ex")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,19 @@ abstract class RunTestDefinitions
}
}

test("UTF-8 characters on the input path & current working directory path") {
val expectedMessage = "Hello"
val utf8DirPath = os.rel / "äöü"
val inputName = "Hello.sc"
val inputPath = utf8DirPath / inputName
TestInputs(inputPath -> s"""println("$expectedMessage")""")
.fromRoot { root =>
val res = os.proc(TestUtil.cli, "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) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,4 +883,59 @@ 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 = 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
os.proc(localBin / "scala.bat", "--version")
.call(cwd = rootWithUtf8, stdout = os.Inherit)
}
}
}

0 comments on commit f303e9f

Please sign in to comment.