@@ -2087,4 +2087,62 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
20872087 expect(res.err.trim().contains(" JVM (11)" ))
20882088 }
20892089 }
2090+
2091+ // TODO: Remove this part once fix is released in os-lib (Issue #2585)
2092+ def getCoursierCacheRelPath : os.RelPath =
2093+ if (Properties .isWin) os.rel / " Coursier" / " Cache"
2094+ else if (Properties .isMac) os.rel / " Library" / " Caches" / " Coursier"
2095+ else os.rel / " .cache" / " coursier"
2096+ if (TestUtil .isJvmCli) // can't reproduce on native image launchers
2097+ test(" user.home is overridden with user.dir" ) {
2098+ val customCall =
2099+ Seq (" java" , " -Xmx512m" , " -Xms128m" , " -Duser.home=?" , " -jar" , TestUtil .cliPath)
2100+ val msg = " Hello"
2101+ val input = " script.sc"
2102+ TestInputs (os.rel / input -> s " println( \" $msg\" ) " )
2103+ .fromRoot { root =>
2104+ expect(! os.isDir(root / getCoursierCacheRelPath))
2105+ val res = os.proc(customCall, " run" , extraOptions, " --server=false" , input)
2106+ .call(
2107+ cwd = root,
2108+ stderr = os.Pipe
2109+ )
2110+ expect(res.out.trim() == msg)
2111+ expect(
2112+ res.err.trim().contains(
2113+ " user.home property is not valid: ?, setting it to user.dir value"
2114+ )
2115+ )
2116+ if (! Properties .isWin) // coursier cache location on Windows does not depend on home dir
2117+ expect(os.isDir(root / getCoursierCacheRelPath))
2118+ }
2119+ }
2120+
2121+ // TODO: Remove this part once fix is released in os-lib (Issue #2585)
2122+ test(" user.home is overridden by SCALA_CLI_HOME_DIR_OVERRIDE" ) {
2123+ val msg = " Hello"
2124+ val input = " script.sc"
2125+ TestInputs (os.rel / input -> s " println( \" $msg\" ) " )
2126+ .fromRoot { root =>
2127+ val newHomePath = root / " home"
2128+ os.makeDir(newHomePath)
2129+ expect(! os.isDir(newHomePath / getCoursierCacheRelPath))
2130+ val extraEnv = Map (" SCALA_CLI_HOME_DIR_OVERRIDE" -> newHomePath.toString())
2131+
2132+ val res = os.proc(TestUtil .cli, " run" , extraOptions, " --server=false" , input)
2133+ .call(
2134+ cwd = root,
2135+ stderr = os.Pipe ,
2136+ env = extraEnv
2137+ )
2138+ expect(res.out.trim() == msg)
2139+ expect(
2140+ res.err.trim().contains(
2141+ " user.home property overridden with the SCALA_CLI_HOME_DIR_OVERRIDE"
2142+ )
2143+ )
2144+ if (! Properties .isWin) // coursier cache location on Windows does not depend on home dir
2145+ expect(os.isDir(newHomePath / getCoursierCacheRelPath))
2146+ }
2147+ }
20902148}
0 commit comments