@@ -847,4 +847,61 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
847
847
expect(res.out.trim().contains(scalaVersion))
848
848
}
849
849
}
850
+
851
+ if (! Properties .isWin) // FIXME: run this test on Windows
852
+ test(" coursier scala installation works in --offline mode" ) {
853
+ TestInputs .empty.fromRoot { root =>
854
+ val localCache = root / " local-cache"
855
+ val localBin = root / " local-bin"
856
+ val sv = " 3.5.0-RC4"
857
+ os.proc(
858
+ TestUtil .cs,
859
+ " install" ,
860
+ " --cache" ,
861
+ localCache,
862
+ " --install-dir" ,
863
+ localBin,
864
+ s " scala: $sv"
865
+ ).call(cwd = root)
866
+ val scalaBinary : os.Path = localBin / " scala"
867
+ val fileBytes = os.read.bytes(scalaBinary)
868
+ val shebang = new String (fileBytes.takeWhile(_ != '\n ' ), " UTF-8" )
869
+ val binaryData = fileBytes.drop(shebang.length + 1 )
870
+ val execLine = new String (binaryData.takeWhile(_ != '\n ' ), " UTF-8" )
871
+ val scriptPathRegex = """ exec "([^"]+/bin/scala).*"""" .r
872
+ val scalaScript = execLine match { case scriptPathRegex(extractedPath) => extractedPath }
873
+ val scalaScriptPath = os.Path (scalaScript)
874
+ val lineToChange = " eval \" ${SCALA_CLI_CMD_BASH[@]}\" \\ "
875
+ // FIXME: the way the scala script calls the launcher currently ignores the --debug flag
876
+ val newContent = os.read(scalaScriptPath).replace(
877
+ lineToChange,
878
+ s """ SCALA_CLI_CMD_BASH=(\" \\ \" ${TestUtil .cliPath}\\ \"\")
879
+ | $lineToChange""" .stripMargin
880
+ )
881
+ os.write.over(scalaScriptPath, newContent)
882
+ val r =
883
+ os.proc(
884
+ scalaScript,
885
+ " --offline" ,
886
+ " --power" ,
887
+ " --with-compiler" ,
888
+ " -e" ,
889
+ " println(dotty.tools.dotc.config.Properties.versionNumberString)"
890
+ ).call(
891
+ cwd = root,
892
+ env = Map (" COURSIER_CACHE" -> localCache.toString),
893
+ check = false // need to clean up even on failure
894
+ )
895
+ // clean up cs local binaries
896
+ val csPrebuiltBinaryDir =
897
+ os.Path (scalaScript.substring(0 , scalaScript.indexOf(sv) + sv.length))
898
+ try os.remove.all(csPrebuiltBinaryDir)
899
+ catch {
900
+ case ex : java.nio.file.FileSystemException =>
901
+ println(s " Failed to remove $csPrebuiltBinaryDir: $ex" )
902
+ }
903
+ expect(r.exitCode == 0 )
904
+ expect(r.out.trim() == sv)
905
+ }
906
+ }
850
907
}
0 commit comments