Skip to content

Commit

Permalink
Run all supported tests with Scala 2 library TASTy
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 30, 2023
1 parent c88c0fe commit 3900988
Show file tree
Hide file tree
Showing 4 changed files with 20 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import scala.jdk.CollectionConverters._
import javax.tools.ToolProvider

import org.junit.Assert._
import org.junit.Assume.assumeFalse
import org.junit.Test
import org.junit.experimental.categories.Category

import dotty.BootstrappedOnlyTests
import dotty.tools.dotc.Main
import dotty.tools.dotc.semanticdb.Scala3.given
import dotty.tools.dotc.util.SourceFile
import dotty.Properties

@main def updateExpect =
SemanticdbTests().runExpectTest(updateExpectFiles = true)
Expand Down Expand Up @@ -65,6 +67,7 @@ class SemanticdbTests:
@Test def expectTests: Unit = if (!scala.util.Properties.isWin) runExpectTest(updateExpectFiles = false)

def runExpectTest(updateExpectFiles: Boolean): Unit =
assumeFalse("dotty/tests/semanticdb/metac.expect differs when using Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
val target = generateSemanticdb()
val errors = mutable.ArrayBuffer.empty[Path]
val metacSb: StringBuilder = StringBuilder(5000)
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

0 comments on commit 3900988

Please sign in to comment.