Skip to content

Commit 746b9c6

Browse files
Merge pull request #14358 from philwalk/expressionTest-bugfix
fix ExpressionTest#verifyImports test compile error introduced in #14263
2 parents f955f8b + ae3238c commit 746b9c6

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

compiler/test/dotty/tools/scripting/ExpressionTest.scala

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,30 @@ class ExpressionTest:
2727
@Test def verifyImports: Unit =
2828
val expressionLines = List(
2929
"import java.nio.file.Paths",
30-
"""val cwd = Paths.get(""."")""",
31-
"""println(cwd.toFile.listFiles.toList.filter(_.isDirectory).size)""",
30+
"import scala.util.Properties.userDir",
31+
"println(Paths.get(userDir).toFile.listFiles.toList.filter(_.isDirectory).size)",
3232
)
3333
val expression = expressionLines.mkString(";")
34-
testExpression(expression){ result =>
34+
val success = testExpression(expression){ result =>
3535
result.matches("[0-9]+") && result.toInt > 0
3636
}
37+
assert(success)
3738

3839
def getResult(expression: String): String =
39-
val cmd = s"bin/scala -e $expression"
40-
val (_, _, stdout, stderr) = bashCommand(s"""bin/scala -e '$expression'""")
40+
val (_, _, stdout, stderr) = bashCommand(s"$scalaPath -e '$expression'")
4141
printf("stdout: %s\n", stdout.mkString("|"))
42-
printf("stderr: %s\n", stderr.mkString("\n","\n",""))
42+
printf("stderr: %s\n", stderr.mkString("\n", "\n", ""))
4343
stdout.filter(_.nonEmpty).mkString("")
4444

45-
def testExpression(expression: String)(check: (result: String) => Boolean) = {
45+
def testExpression(expression: String)(check: (result: String) => Boolean): Boolean =
4646
val result = getResult(expression)
4747
check(result)
48-
}
4948

49+
object ExpressionTest:
50+
51+
def main(args: Array[String]): Unit =
52+
val tests = new ExpressionTest
53+
println("\n=== verifyCommandLineExpression ===")
54+
tests.verifyCommandLineExpression
55+
println("\n=== verifyImports ===")
56+
tests.verifyImports

compiler/test/dotty/tools/scripting/ScriptTestEnv.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ object ScriptTestEnv {
2121
def psep: String = sys.props("path.separator")
2222
def userDir: String = sys.props("user.dir").norm
2323
def testCwd = envOrElse("TEST_CWD", "").norm // optional working directory TEST_CWD
24+
def verbose = envOrElse("VERBOSE", "").nonEmpty
2425

2526
def whichJava: String = whichExe("java")
2627
def whichBash: String = whichExe("bash")
2728

2829
lazy val workingDirectory: String = {
2930
val dirstr = if testCwd.nonEmpty then
30-
printf("TEST_CWD set to [%s]\n", testCwd)
31+
if verbose then printf("TEST_CWD set to [%s]\n", testCwd)
3132
testCwd
3233
else
3334
userDir // userDir, if TEST_CWD not set
@@ -37,7 +38,7 @@ object ScriptTestEnv {
3738
if !test.isDirectory then
3839
printf("warning: not found below working directory: %s\n", test.norm)
3940

40-
printf("working directory is [%s]\n", dirstr)
41+
if verbose then printf("working directory is [%s]\n", dirstr)
4142
dirstr
4243
}
4344

@@ -106,7 +107,7 @@ object ScriptTestEnv {
106107
// a misconfigured environment (e.g., script is not executable) can prevent script execution
107108
val validTest = !stderr.exists(_.contains("Permission denied"))
108109
if ! validTest then
109-
printf("\nunable to execute script, return value is %d\n", exitVal)
110+
System.err.printf("\nunable to execute script, return value is %d\n", exitVal)
110111
stderr.foreach { System.err.printf("stderr [%s]\n", _) }
111112

112113
(validTest, exitVal, stdout.reverse, stderr.reverse)
@@ -275,8 +276,7 @@ object ScriptTestEnv {
275276
("MSYS", msyshome),
276277
("SHELLOPTS", shellopts),
277278
).filter { case (name, valu) => valu.nonEmpty }
278-
for (k, v) <- pairs do
279-
printf("%s : %s\n", k ,v)
279+
if verbose then for (k, v) <- pairs do printf("%s : %s\n", k ,v)
280280
pairs
281281
}
282282

0 commit comments

Comments
 (0)