Skip to content

Commit

Permalink
Run all supported tests with Scala 2 library TASTy (#18875)
Browse files Browse the repository at this point in the history
[test_scala2_library_tasty]
  • Loading branch information
bishabosha authored Dec 18, 2023
2 parents 6313db6 + 07fb38d commit a5586c3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ jobs:
run: cp -vf .github/workflows/repositories /root/.sbt/ ; true

- name: Test with Scala 2 library TASTy
run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryTasty := true ;scala3-bootstrapped/testCompilation"
run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryTasty := true ;scala3-bootstrapped/test"


test_windows_fast:
Expand Down
2 changes: 2 additions & 0 deletions compiler/test/dotty/tools/scripting/BashExitCodeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 @@ -19,6 +20,7 @@ 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
12 changes: 12 additions & 0 deletions compiler/test/dotty/tools/scripting/BashScriptsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import scala.language.unsafeNulls
import java.nio.file.Paths
import org.junit.{Test, AfterClass}
import org.junit.Assert.assertEquals
import org.junit.Assume.assumeFalse
import org.junit.experimental.categories.Category

import vulpix.TestConfiguration
Expand Down Expand Up @@ -84,30 +85,35 @@ 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 @@ -125,6 +131,7 @@ 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 @@ -140,6 +147,7 @@ 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 @@ -159,6 +167,7 @@ class BashScriptsTests:
*/
@Category(Array(classOf[BootstrappedOnlyTests]))
@Test def verifyScriptPathProperty =
assumeFalse("Scripts do not yet support 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 @@ -175,6 +184,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)
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 @@ -197,6 +207,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)
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 @@ -221,6 +232,7 @@ 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
5 changes: 4 additions & 1 deletion compiler/test/dotty/tools/scripting/ExpressionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import scala.language.unsafeNulls
import java.nio.file.Paths
import org.junit.{Test, AfterClass}
import org.junit.Assert.assertEquals
import org.junit.Assume.assumeFalse
import org.junit.experimental.categories.Category

import vulpix.TestConfiguration
Expand All @@ -22,13 +23,15 @@ class ExpressionTest:
* verify -e <expression> 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)"
val result = getResult(expression)
assert(result.contains(expected), s"expression [$expression] did not send [$expected] to stdout")
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)
val expressionLines = List(
"import java.nio.file.Paths",
"import scala.util.Properties.userDir",
Expand Down
7 changes: 7 additions & 0 deletions compiler/test/dotty/tools/scripting/ScriptingTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ 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 @@ -21,6 +23,7 @@ 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 @@ -43,6 +46,7 @@ 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 @@ -61,6 +65,7 @@ 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 @@ -85,6 +90,7 @@ 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 @@ -123,6 +129,7 @@ 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 a5586c3

Please sign in to comment.