1
1
package scala .cli .integration
2
2
3
+ import os .{CommandResult , Path }
4
+
3
5
import java .io .File
4
6
import java .util .concurrent .atomic .AtomicInteger
5
7
import java .util .concurrent .{ExecutorService , Executors , ScheduledExecutorService , ThreadFactory }
@@ -10,11 +12,11 @@ import scala.util.Properties
10
12
11
13
object TestUtil {
12
14
13
- val cliKind = sys.props(" test.scala-cli.kind" )
14
- val isNativeCli = cliKind.startsWith(" native" )
15
- val isCI = System .getenv(" CI" ) != null
16
- val cliPath = sys.props(" test.scala-cli.path" )
17
- val cli = cliCommand(cliPath)
15
+ val cliKind : String = sys.props(" test.scala-cli.kind" )
16
+ val isNativeCli : Boolean = cliKind.startsWith(" native" )
17
+ val isCI : Boolean = System .getenv(" CI" ) != null
18
+ val cliPath : String = sys.props(" test.scala-cli.path" )
19
+ val cli : Seq [ String ] = cliCommand(cliPath)
18
20
19
21
def cliCommand (cliPath : String ): Seq [String ] =
20
22
if (isNativeCli)
@@ -23,7 +25,7 @@ object TestUtil {
23
25
Seq (" java" , " -Xmx512m" , " -Xms128m" , " -jar" , cliPath)
24
26
25
27
// format: off
26
- val extraOptions = List (
28
+ val extraOptions : List [ String ] = List (
27
29
" --bloop-startup-timeout" , " 2min" ,
28
30
" --bloop-bsp-timeout" , " 1min"
29
31
)
@@ -58,7 +60,7 @@ object TestUtil {
58
60
.map(_.getAbsolutePath)
59
61
}
60
62
61
- def cs = Constants .cs
63
+ def cs : String = Constants .cs
62
64
63
65
def threadPool (prefix : String , size : Int ): ExecutorService =
64
66
Executors .newFixedThreadPool(size, daemonThreadFactory(prefix))
@@ -68,9 +70,9 @@ object TestUtil {
68
70
69
71
private def daemonThreadFactory (prefix : String ): ThreadFactory =
70
72
new ThreadFactory {
71
- val counter = new AtomicInteger
72
- def threadNumber () = counter.incrementAndGet()
73
- def newThread (r : Runnable ) =
73
+ val counter = new AtomicInteger
74
+ def threadNumber (): Int = counter.incrementAndGet()
75
+ def newThread (r : Runnable ): Thread =
74
76
new Thread (r, s " $prefix-thread- ${threadNumber()}" ) {
75
77
setDaemon(true )
76
78
setPriority(Thread .NORM_PRIORITY )
@@ -105,21 +107,27 @@ object TestUtil {
105
107
106
108
def retryOnCi [T ](maxAttempts : Int = 3 , waitDuration : FiniteDuration = 5 .seconds)(
107
109
run : => T
108
- ) = retry(if (isCI) maxAttempts else 1 , waitDuration)(run)
110
+ ): T = retry(if (isCI) maxAttempts else 1 , waitDuration)(run)
109
111
110
112
// Same as os.RelPath.toString, but for the use of File.separator instead of "/"
111
113
def relPathStr (relPath : os.RelPath ): String =
112
114
(Seq .fill(relPath.ups)(" .." ) ++ relPath.segments).mkString(File .separator)
113
115
114
- def kill (pid : Int ) =
116
+ def kill (pid : Int ): CommandResult =
115
117
if (Properties .isWin)
116
118
os.proc(" taskkill" , " /F" , " /PID" , pid).call()
117
119
else
118
120
os.proc(" kill" , pid).call()
119
121
120
- def pwd =
122
+ def pwd : Path =
121
123
if (Properties .isWin)
122
124
os.Path (os.pwd.toIO.getCanonicalFile)
123
125
else
124
126
os.pwd
127
+
128
+ /** @return
129
+ * 2 quotation marks (") when run for Windows, or a single one otherwise. This is necessary to
130
+ * escape the quotation marks passed in args for the Windows command line.
131
+ */
132
+ def argQuotationMark : String = if (Properties .isWin) " \"\" " else " \" "
125
133
}
0 commit comments