Skip to content

fix ExpressionTest#verifyImports test compile error introduced in #14263 #14358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions compiler/test/dotty/tools/scripting/ExpressionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions compiler/test/dotty/tools/scripting/ScriptTestEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down