Skip to content

Commit

Permalink
Enable more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Dec 11, 2023
1 parent 07fb38d commit c2da473
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 22 deletions.
2 changes: 0 additions & 2 deletions compiler/test/dotty/tools/scripting/BashExitCodeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import scala.language.unsafeNulls
import java.nio.file.Files, java.nio.charset.StandardCharsets.UTF_8
import org.junit.{ After, Test }
import org.junit.Assert.assertEquals
import org.junit.Assume.assumeFalse
import org.junit.experimental.categories.Category

import ScriptTestEnv.*
Expand All @@ -20,7 +19,6 @@ class BashExitCodeTests:

/** Verify the exit code of running `cmd args*`. */
def verifyExit(cmd: String, args: String*)(expectedExitCode: Int): Unit =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val (validTest, exitCode, stdout, stderr) = bashCommand((cmd +: args).mkString(" "))
if verifyValid(validTest) then
assertEquals({
Expand Down
14 changes: 3 additions & 11 deletions compiler/test/dotty/tools/scripting/BashScriptsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,35 +85,30 @@ class BashScriptsTests:

/* verify that `dist/bin/scala` correctly passes args to the jvm via -J-D for script envtest.sc */
@Test def verifyScJProperty =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val tag = "World1"
val stdout = callScript(tag, envtestSc, s"-J-Dkey")
assertEquals( s"Hello $tag", stdout)

/* verify that `dist/bin/scala` correctly passes args to the jvm via -J-D for script envtest.scala */
@Test def verifyScalaJProperty =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val tag = "World2"
val stdout = callScript(tag, envtestScala, s"-J-Dkey")
assertEquals(s"Hello $tag", stdout)

/* verify that `dist/bin/scala` can set system properties via -D for envtest.sc */
@Test def verifyScDProperty =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val tag = "World3"
val stdout = callScript(tag, envtestSc, s"-Dkey")
assertEquals(s"Hello $tag", stdout)

/* verify that `dist/bin/scala` can set system properties via -D for envtest.scala */
@Test def verifyScalaDProperty =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val tag = "World4"
val stdout = callScript(tag, envtestScala, s"-Dkey")
assertEquals(s"Hello $tag", stdout)

/* verify that `dist/bin/scala` can set system properties via -D when executing compiled script via -jar envtest.jar */
@Test def saveAndRunWithDProperty =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val commandline = Seq("SCALA_OPTS= ", scalaPath.relpath, "-save", envtestScala.relpath).mkString(" ")
val (_, _, _, _) = bashCommand(commandline) // compile jar, discard output
val testJar = testFile("envtest.jar") // jar is created by the previous bashCommand()
Expand All @@ -131,7 +126,6 @@ class BashScriptsTests:

/* verify `dist/bin/scalac` non-interference with command line args following script name */
@Test def verifyScalacArgs =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val commandline = (Seq("SCALA_OPTS= ", scalacPath, "-script", showArgsScript) ++ testScriptArgs).mkString(" ")
val (validTest, exitCode, stdout, stderr) = bashCommand(commandline)
if verifyValid(validTest) then
Expand All @@ -147,7 +141,6 @@ class BashScriptsTests:

/* verify `dist/bin/scala` non-interference with command line args following script name */
@Test def verifyScalaArgs =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val commandline = (Seq("SCALA_OPTS= ", scalaPath, showArgsScript) ++ testScriptArgs).mkString(" ")
val (validTest, exitCode, stdout, stderr) = bashCommand(commandline)
if verifyValid(validTest) then
Expand All @@ -167,7 +160,7 @@ class BashScriptsTests:
*/
@Category(Array(classOf[BootstrappedOnlyTests]))
@Test def verifyScriptPathProperty =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
assumeFalse("Scripts do not yet support fully Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val scriptFile = testFiles.find(_.getName == "scriptPath.sc").get
val expected = s"${scriptFile.getName}"
printf("===> verify valid system property script.path is reported by script [%s]\n", scriptFile.getName)
Expand All @@ -184,7 +177,7 @@ class BashScriptsTests:
* verify SCALA_OPTS can specify an @argsfile when launching a scala script in `dist/bin/scala`.
*/
@Test def verifyScalaOpts =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
assumeFalse("Scripts do not yet support fully Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val scriptFile = testFiles.find(_.getName == "classpathReport.sc").get
printf("===> verify SCALA_OPTS='@argsfile' is properly handled by `dist/bin/scala`\n")
val envPairs = List(("SCALA_OPTS", s"@$argsfile"))
Expand All @@ -207,7 +200,7 @@ class BashScriptsTests:
* verify that individual scripts can override -save with -nosave (needed to address #13760).
*/
@Test def sqlDateTest =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
assumeFalse("Scripts do not yet support fully Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val scriptBase = "sqlDateError"
val scriptFile = testFiles.find(_.getName == s"$scriptBase.sc").get
val testJar = testFile(s"$scriptBase.jar") // jar should not be created when scriptFile runs
Expand All @@ -232,7 +225,6 @@ class BashScriptsTests:
* verify -e println("yo!") works.
*/
@Test def verifyCommandLineExpression =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
printf("===> verify -e <expression> is properly handled by `dist/bin/scala`\n")
val expected = "9"
val expression = s"println(3*3)"
Expand Down
2 changes: 2 additions & 0 deletions compiler/test/dotty/tools/scripting/ClasspathTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.io.File
import java.nio.file.Path

import org.junit.{Test, Ignore, AfterClass}
import org.junit.Assume.assumeFalse
import vulpix.TestConfiguration
import ScriptTestEnv.*

Expand Down Expand Up @@ -78,6 +79,7 @@ class ClasspathTests:
* verify classpath is unglobbed by MainGenericRunner.
*/
@Test def unglobClasspathVerifyTest = {
assumeFalse("Scripts do not yet support fully Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val testScriptName = "unglobClasspath.sc"
val testScript = scripts("/scripting").find { _.name.matches(testScriptName) } match
case None => sys.error(s"test script not found: ${testScriptName}")
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/dotty/tools/scripting/ExpressionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class ExpressionTest:
* verify -e <expression> works.
*/
@Test def verifyCommandLineExpression =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
assumeFalse("Scripts do not yet support fully Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
printf("===> verify -e <expression> is properly handled by `dist/bin/scala`\n")
val expected = "9"
val expression = s"println(3*3)"
val result = getResult(expression)
assert(result.contains(expected), s"expression [$expression] did not send [$expected] to stdout. It send [$result].")

@Test def verifyImports: Unit =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
assumeFalse("Scripts do not yet support fully Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val expressionLines = List(
"import java.nio.file.Paths",
"import scala.util.Properties.userDir",
Expand Down
7 changes: 0 additions & 7 deletions compiler/test/dotty/tools/scripting/ScriptingTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import org.junit.Test
import vulpix.TestConfiguration
import ScriptTestEnv.*

import org.junit.Assume.assumeFalse

/** Runs all tests contained in `compiler/test-resources/scripting/` */
class ScriptingTests:
// classpath tests managed by scripting.ClasspathTests.scala
Expand All @@ -23,7 +21,6 @@ class ScriptingTests:
* Call .scala scripts without -save option, verify no jar created
*/
@Test def scriptingDriverTests =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
for (scriptFile, scriptArgs) <- scalaFilesWithArgs(".scala") do
showScriptUnderTest(scriptFile)
val unexpectedJar = script2jar(scriptFile)
Expand All @@ -46,7 +43,6 @@ class ScriptingTests:
* Call .sc scripts without -save option, verify no jar created
*/
@Test def scriptingMainTests =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
for (scriptFile, scriptArgs) <- scalaFilesWithArgs(".sc") do
showScriptUnderTest(scriptFile)
val unexpectedJar = script2jar(scriptFile)
Expand All @@ -65,7 +61,6 @@ class ScriptingTests:
* Call .sc scripts with -save option, verify jar is created.
*/
@Test def scriptingJarTest =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
for (scriptFile, scriptArgs) <- scalaFilesWithArgs(".sc") do
showScriptUnderTest(scriptFile)
val expectedJar = script2jar(scriptFile)
Expand All @@ -90,7 +85,6 @@ class ScriptingTests:
* Verify that when ScriptingDriver callback returns false, main is not called.
*/
@Test def scriptCompileOnlyTests =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val scriptFile = touchFileScript
showScriptUnderTest(scriptFile)

Expand Down Expand Up @@ -129,7 +123,6 @@ class ScriptingTests:
* Compile touchFile.sc to create executable jar, verify jar execution succeeds.
*/
@Test def scriptingNoCompileJar: Unit =
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val scriptFile = touchFileScript
showScriptUnderTest(scriptFile)
val expectedJar = script2jar(scriptFile)
Expand Down

0 comments on commit c2da473

Please sign in to comment.