@@ -4,17 +4,52 @@ import coursier.cache.{ArtifactError, FileCache}
4
4
import coursier .util .{Artifact , Task }
5
5
6
6
import java .io .File
7
+ import java .util .concurrent .TimeUnit
7
8
8
- import scala .concurrent .duration .DurationInt
9
+ import scala .concurrent .duration .{ DurationInt , FiniteDuration }
9
10
import scala .util .control .NonFatal
10
11
11
12
object TestUtil {
13
+ abstract class ScalaCliSuite extends munit.FunSuite {
14
+ extension (munitContext : BeforeEach | AfterEach ) {
15
+ def locationAbsolutePath : os.Path =
16
+ os.Path {
17
+ (munitContext match {
18
+ case beforeEach : BeforeEach => beforeEach.test
19
+ case afterEach : AfterEach => afterEach.test
20
+ }).location.path
21
+ }
22
+ }
23
+
24
+ override def munitTimeout = new FiniteDuration (120 , TimeUnit .SECONDS )
25
+
26
+ val testStartEndLogger = new Fixture [Unit ](" files" ) {
27
+ def apply (): Unit = ()
28
+
29
+ override def beforeEach (context : BeforeEach ): Unit = {
30
+ val fileName = context.locationAbsolutePath.baseName
31
+ System .err.println(
32
+ s " >==== ${Console .CYAN }Running ' ${context.test.name}' from $fileName${Console .RESET }"
33
+ )
34
+ }
35
+
36
+ override def afterEach (context : AfterEach ): Unit = {
37
+ val fileName = context.locationAbsolutePath.baseName
38
+ System .err.println(
39
+ s " X==== ${Console .CYAN }Finishing ' ${context.test.name}' from $fileName${Console .RESET }"
40
+ )
41
+ }
42
+ }
43
+
44
+ override def munitFixtures = List (testStartEndLogger)
45
+ }
46
+
12
47
def downloadFile (url : String ): Either [ArtifactError , Array [Byte ]] = {
13
48
val artifact = Artifact (url).withChanging(true )
14
49
val cache = FileCache ()
15
50
16
51
val file : Either [ArtifactError , File ] = cache.logger.use {
17
- try cache.withTtl(0 .seconds).file(artifact).run.unsafeRun()(cache.ec)
52
+ try cache.withTtl(0 .seconds).file(artifact).run.unsafeRun()(using cache.ec)
18
53
catch {
19
54
case NonFatal (e) => throw new Exception (e)
20
55
}
0 commit comments