Skip to content

Commit d0c01b8

Browse files
Factor helper in integration tests
1 parent ca02f6e commit d0c01b8

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package scala.cli.integration
22

33
import com.eed3si9n.expecty.Expecty.expect
44

5-
import java.io.File
6-
import java.util.Locale
7-
85
import scala.util.Properties
96

107
class ConfigTests extends ScalaCliSuite {
@@ -104,30 +101,9 @@ class ConfigTests extends ScalaCliSuite {
104101
if (!Properties.isWin)
105102
os.perms.set(confDir, "rwx------")
106103

107-
val extraEnv = {
108-
val (pathVarName, currentPath) = sys.env
109-
.find(_._1.toLowerCase(Locale.ROOT) == "path")
110-
.getOrElse(("PATH", ""))
111-
val binDir = root / "bin"
112-
if (Properties.isWin) {
113-
val script =
114-
s"""@echo off
115-
|"${TestUtil.cs}" %*
116-
|""".stripMargin
117-
os.write(binDir / "cs.bat", script, createFolders = true)
118-
}
119-
else {
120-
val script =
121-
s"""#!/usr/bin/env bash
122-
|exec "${TestUtil.cs}" "$$@"
123-
|""".stripMargin
124-
os.write(binDir / "cs", script, "rwxr-xr-x", createFolders = true)
125-
}
126-
Map(
127-
"SCALA_CLI_CONFIG" -> confFile.toString,
128-
pathVarName -> s"$binDir${File.pathSeparator}$currentPath"
129-
)
130-
}
104+
val extraEnv =
105+
Map("SCALA_CLI_CONFIG" -> confFile.toString) ++
106+
TestUtil.putCsInPathViaEnv(root / "bin")
131107

132108
val res = os.proc(TestUtil.cli, "config", "httpProxy.address")
133109
.call(cwd = root, env = extraEnv)

modules/integration/src/test/scala/scala/cli/integration/TestUtil.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import os.{CommandResult, Path}
44

55
import java.io.File
66
import java.net.ServerSocket
7+
import java.util.Locale
78
import java.util.concurrent.atomic.AtomicInteger
89
import java.util.concurrent.{ExecutorService, Executors, ScheduledExecutorService, ThreadFactory}
910

@@ -222,4 +223,26 @@ object TestUtil {
222223
}
223224
}
224225
}
226+
227+
def putCsInPathViaEnv(binDir: os.Path): Map[String, String] = {
228+
229+
val (pathVarName, currentPath) = sys.env
230+
.find(_._1.toLowerCase(Locale.ROOT) == "path")
231+
.getOrElse(("PATH", ""))
232+
if (Properties.isWin) {
233+
val script =
234+
s"""@echo off
235+
|"${TestUtil.cs}" %*
236+
|""".stripMargin
237+
os.write(binDir / "cs.bat", script, createFolders = true)
238+
}
239+
else {
240+
val script =
241+
s"""#!/usr/bin/env bash
242+
|exec "${TestUtil.cs}" "$$@"
243+
|""".stripMargin
244+
os.write(binDir / "cs", script, "rwxr-xr-x", createFolders = true)
245+
}
246+
Map(pathVarName -> s"$binDir${File.pathSeparator}$currentPath")
247+
}
225248
}

0 commit comments

Comments
 (0)