@@ -560,4 +560,45 @@ class ConfigTests extends ScalaCliSuite {
560
560
}
561
561
}
562
562
563
+ for {
564
+ offlineSetting <- Seq (true , false )
565
+ prefillCache <- if (offlineSetting) Seq (true , false ) else Seq (false )
566
+ caption = s " offline mode: $offlineSetting, " +
567
+ (offlineSetting -> prefillCache match {
568
+ case (true , true ) => " build should succeed when cache was pre-filled"
569
+ case (true , false ) => " build should fail when cache is empty"
570
+ case _ => " dependencies should be downloaded as normal"
571
+ })
572
+ }
573
+ test(caption) {
574
+ TestInputs (
575
+ os.rel / " simple.sc" -> " println(dotty.tools.dotc.config.Properties.versionNumberString)"
576
+ )
577
+ .fromRoot { root =>
578
+ val configFile = os.rel / " config" / " config.json"
579
+ val localRepoPath = root / " local-repo"
580
+ val envs = Map (
581
+ " COURSIER_CACHE" -> localRepoPath.toString,
582
+ " SCALA_CLI_CONFIG" -> configFile.toString
583
+ )
584
+ os.proc(TestUtil .cli, " bloop" , " exit" , " --power" ).call(cwd = root)
585
+ os.proc(TestUtil .cli, " config" , " --power" , " offline" , offlineSetting.toString)
586
+ .call(cwd = root, env = envs)
587
+ if (prefillCache) for {
588
+ artifactName <- Seq (
589
+ " scala3-compiler_3" ,
590
+ " scala3-staging_3" ,
591
+ " scala3-tasty-inspector_3" ,
592
+ " scala3-sbt-bridge"
593
+ )
594
+ artifact = s " org.scala-lang: $artifactName: ${Constants .scala3Next}"
595
+ } os.proc(TestUtil .cs, " fetch" , " --cache" , localRepoPath, artifact).call(cwd = root)
596
+ val buildExpectedToSucceed = ! offlineSetting || prefillCache
597
+ val r = os.proc(TestUtil .cli, " run" , " simple.sc" , " --with-compiler" )
598
+ .call(cwd = root, env = envs, check = buildExpectedToSucceed)
599
+ if (buildExpectedToSucceed) expect(r.out.trim() == Constants .scala3Next)
600
+ else expect(r.exitCode == 1 )
601
+ }
602
+ }
603
+
563
604
}
0 commit comments