diff --git a/compiler/test/dotty/tools/scripting/ExpressionTest.scala b/compiler/test/dotty/tools/scripting/ExpressionTest.scala index fd642a7744e0..136007af835d 100755 --- a/compiler/test/dotty/tools/scripting/ExpressionTest.scala +++ b/compiler/test/dotty/tools/scripting/ExpressionTest.scala @@ -27,23 +27,30 @@ class ExpressionTest: @Test def verifyImports: Unit = val expressionLines = List( "import java.nio.file.Paths", - """val cwd = Paths.get(""."")""", - """println(cwd.toFile.listFiles.toList.filter(_.isDirectory).size)""", + "import scala.util.Properties.userDir", + "println(Paths.get(userDir).toFile.listFiles.toList.filter(_.isDirectory).size)", ) val expression = expressionLines.mkString(";") - testExpression(expression){ result => + val success = testExpression(expression){ result => result.matches("[0-9]+") && result.toInt > 0 } + assert(success) def getResult(expression: String): String = - val cmd = s"bin/scala -e $expression" - val (_, _, stdout, stderr) = bashCommand(s"""bin/scala -e '$expression'""") + val (_, _, stdout, stderr) = bashCommand(s"$scalaPath -e '$expression'") printf("stdout: %s\n", stdout.mkString("|")) - printf("stderr: %s\n", stderr.mkString("\n","\n","")) + printf("stderr: %s\n", stderr.mkString("\n", "\n", "")) stdout.filter(_.nonEmpty).mkString("") - def testExpression(expression: String)(check: (result: String) => Boolean) = { + def testExpression(expression: String)(check: (result: String) => Boolean): Boolean = val result = getResult(expression) check(result) - } +object ExpressionTest: + + def main(args: Array[String]): Unit = + val tests = new ExpressionTest + println("\n=== verifyCommandLineExpression ===") + tests.verifyCommandLineExpression + println("\n=== verifyImports ===") + tests.verifyImports diff --git a/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala b/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala index a37918f93ed2..15bcf4034a5f 100644 --- a/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala +++ b/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala @@ -21,13 +21,14 @@ object ScriptTestEnv { def psep: String = sys.props("path.separator") def userDir: String = sys.props("user.dir").norm def testCwd = envOrElse("TEST_CWD", "").norm // optional working directory TEST_CWD + def verbose = envOrElse("VERBOSE", "").nonEmpty def whichJava: String = whichExe("java") def whichBash: String = whichExe("bash") lazy val workingDirectory: String = { val dirstr = if testCwd.nonEmpty then - printf("TEST_CWD set to [%s]\n", testCwd) + if verbose then printf("TEST_CWD set to [%s]\n", testCwd) testCwd else userDir // userDir, if TEST_CWD not set @@ -37,7 +38,7 @@ object ScriptTestEnv { if !test.isDirectory then printf("warning: not found below working directory: %s\n", test.norm) - printf("working directory is [%s]\n", dirstr) + if verbose then printf("working directory is [%s]\n", dirstr) dirstr } @@ -106,7 +107,7 @@ object ScriptTestEnv { // a misconfigured environment (e.g., script is not executable) can prevent script execution val validTest = !stderr.exists(_.contains("Permission denied")) if ! validTest then - printf("\nunable to execute script, return value is %d\n", exitVal) + System.err.printf("\nunable to execute script, return value is %d\n", exitVal) stderr.foreach { System.err.printf("stderr [%s]\n", _) } (validTest, exitVal, stdout.reverse, stderr.reverse) @@ -275,8 +276,7 @@ object ScriptTestEnv { ("MSYS", msyshome), ("SHELLOPTS", shellopts), ).filter { case (name, valu) => valu.nonEmpty } - for (k, v) <- pairs do - printf("%s : %s\n", k ,v) + if verbose then for (k, v) <- pairs do printf("%s : %s\n", k ,v) pairs }