summaryrefslogtreecommitdiff
path: root/main/test
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-04-08 08:54:45 -0700
committerLi Haoyi <haoyi.sg@gmail.com>2018-04-08 09:13:24 -0700
commitdbcad35c05f1726f26b8033524e8fdd3d68b2de9 (patch)
treeb5664e6b751e9f0c855e03b9fba737d3d6b50932 /main/test
parent4f51bd1ccc7cb68822a59ec07946242c1394e8c4 (diff)
parent997760eeddb75f163f7748c945d81a2f248db974 (diff)
downloadmill-dbcad35c05f1726f26b8033524e8fdd3d68b2de9.tar.gz
mill-dbcad35c05f1726f26b8033524e8fdd3d68b2de9.tar.bz2
mill-dbcad35c05f1726f26b8033524e8fdd3d68b2de9.zip
merge
Diffstat (limited to 'main/test')
-rw-r--r--main/test/src/mill/main/ClientServerTests.scala154
-rw-r--r--main/test/src/mill/util/ScriptTestSuite.scala2
2 files changed, 123 insertions, 33 deletions
diff --git a/main/test/src/mill/main/ClientServerTests.scala b/main/test/src/mill/main/ClientServerTests.scala
index e0e74fc7..60c9c9e6 100644
--- a/main/test/src/mill/main/ClientServerTests.scala
+++ b/main/test/src/mill/main/ClientServerTests.scala
@@ -1,9 +1,10 @@
package mill.main
-
import java.io._
import java.nio.file.Path
import mill.client.{ClientServer, Locks}
+
+import scala.collection.JavaConverters._
import utest._
class EchoServer extends ServerMain[Int]{
def main0(args: Array[String],
@@ -11,13 +12,21 @@ class EchoServer extends ServerMain[Int]{
mainInteractive: Boolean,
stdin: InputStream,
stdout: PrintStream,
- stderr: PrintStream) = {
+ stderr: PrintStream,
+ env: Map[String, String]) = {
val reader = new BufferedReader(new InputStreamReader(stdin))
val str = reader.readLine()
- stdout.println(str + args(0))
+ if (args.nonEmpty){
+ stdout.println(str + args(0))
+ }
+ env.toSeq.sortBy(_._1).foreach{
+ case (key, value) => stdout.println(s"$key=$value")
+ }
stdout.flush()
- stderr.println(str.toUpperCase + args(0))
+ if (args.nonEmpty){
+ stderr.println(str.toUpperCase + args(0))
+ }
stderr.flush()
(true, None)
}
@@ -37,38 +46,40 @@ object ClientServerTests extends TestSuite{
(tmpDir, locks)
}
+ def spawnEchoServer(tmpDir : Path, locks: Locks): Unit = {
+ new Thread(() => new Server(
+ tmpDir.toString,
+ new EchoServer(),
+ () => (),
+ 1000,
+ locks
+ ).run()).start()
+ }
+
+ def runClientAux(tmpDir : Path, locks: Locks)
+ (env : Map[String, String], args: Array[String]) = {
+ val (in, out, err) = initStreams()
+ Server.lockBlock(locks.clientLock){
+ mill.client.Main.run(
+ tmpDir.toString,
+ () => spawnEchoServer(tmpDir, locks),
+ locks,
+ in,
+ out,
+ err,
+ args,
+ env.asJava
+ )
+ Thread.sleep(100)
+ (new String(out.toByteArray), new String(err.toByteArray))
+ }
+ }
+
def tests = Tests{
'hello - {
if (!ClientServer.isWindows){
val (tmpDir, locks) = init()
-
- def spawnEchoServer(): Unit = {
- new Thread(() => new Server(
- tmpDir.toString,
- new EchoServer(),
- () => (),
- 1000,
- locks
- ).run()).start()
- }
-
-
- def runClient(arg: String) = {
- val (in, out, err) = initStreams()
- Server.lockBlock(locks.clientLock){
- mill.client.Main.run(
- tmpDir.toString,
- () => spawnEchoServer(),
- locks,
- in,
- out,
- err,
- Array(arg)
- )
- Thread.sleep(100)
- (new String(out.toByteArray), new String(err.toByteArray))
- }
- }
+ def runClient(s: String) = runClientAux(tmpDir, locks)(Map.empty, Array(s))
// Make sure the simple "have the client start a server and
// exchange one message" workflow works from end to end.
@@ -119,6 +130,85 @@ object ClientServerTests extends TestSuite{
err3 == "HELLO World\n"
)
}
+
+ 'envVars - {
+ if (!ClientServer.isWindows){
+ val (tmpDir, locks) = init()
+
+ def runClient(env : Map[String, String]) = runClientAux(tmpDir, locks)(env, Array())
+
+ // Make sure the simple "have the client start a server and
+ // exchange one message" workflow works from end to end.
+
+ assert(
+ locks.clientLock.probe(),
+ locks.serverLock.probe(),
+ locks.processLock.probe()
+ )
+
+ def longString(s : String) = Array.fill(1000)(s).mkString
+ val b1000 = longString("b")
+ val c1000 = longString("c")
+ val a1000 = longString("a")
+
+ val env = Map(
+ "a" -> a1000,
+ "b" -> b1000,
+ "c" -> c1000
+ )
+
+
+ val (out1, err1) = runClient(env)
+ val expected = s"a=$a1000\nb=$b1000\nc=$c1000\n"
+
+ assert(
+ out1 == expected,
+ err1 == ""
+ )
+
+ // Give a bit of time for the server to release the lock and
+ // re-acquire it to signal to the client that it's done
+ Thread.sleep(100)
+
+ assert(
+ locks.clientLock.probe(),
+ !locks.serverLock.probe(),
+ !locks.processLock.probe()
+ )
+
+ val path = List(
+ "/Users/foo/Library/Haskell/bin",
+ "/usr/local/git/bin",
+ "/sw/bin/",
+ "/usr/local/bin",
+ "/usr/local/",
+ "/usr/local/sbin",
+ "/usr/local/mysql/bin",
+ "/usr/local/bin",
+ "/usr/bin",
+ "/bin",
+ "/usr/sbin",
+ "/sbin",
+ "/opt/X11/bin",
+ "/usr/local/MacGPG2/bin",
+ "/Library/TeX/texbin",
+ "/usr/local/bin/",
+ "/Users/foo/bin",
+ "/Users/foo/go/bin",
+ "~/.bloop"
+ )
+
+ val pathEnvVar = path.mkString(":")
+ val (out2, err2) = runClient(Map("PATH" -> pathEnvVar))
+
+ val expected2 = s"PATH=$pathEnvVar\n"
+
+ assert(
+ out2 == expected2,
+ err2 == ""
+ )
+ }
+ }
}
}
}
diff --git a/main/test/src/mill/util/ScriptTestSuite.scala b/main/test/src/mill/util/ScriptTestSuite.scala
index 2df1c0c0..bbca5d68 100644
--- a/main/test/src/mill/util/ScriptTestSuite.scala
+++ b/main/test/src/mill/util/ScriptTestSuite.scala
@@ -15,7 +15,7 @@ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite{
val stdIn = new ByteArrayInputStream(Array())
lazy val runner = new mill.main.MainRunner(
ammonite.main.Cli.Config(wd = workspacePath),
- stdOutErr, stdOutErr, stdIn
+ stdOutErr, stdOutErr, stdIn, None, Map.empty
)
def eval(s: String*) = {
if (!fork) runner.runScript(workspacePath / "build.sc", s.toList)