Skip to content

Commit

Permalink
Use //> using directive in compilation tests
Browse files Browse the repository at this point in the history
* Set options with `//> using`
* Put together tests that need deep subtypes
* -Ycheck tests/run/typeclass-derivation1.scala

[Cherry-picked daeee35][modified]
  • Loading branch information
Kordyjan committed Dec 1, 2023
1 parent 551a97e commit 754dab7
Show file tree
Hide file tree
Showing 146 changed files with 247 additions and 76 deletions.
4 changes: 4 additions & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ t5031_2.scala
i16997.scala
i7414.scala
i17588.scala
i9804.scala
i13433.scala
i16649-irrefutable.scala
strict-pattern-bindings-3.0-migration.scala

# Tree is huge and blows stack for printing Text
i7034.scala
Expand Down
54 changes: 15 additions & 39 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ class CompilationTests {
@Test def pos: Unit = {
implicit val testGroup: TestGroup = TestGroup("compilePos")
var tests = List(
compileFile("tests/pos/nullarify.scala", defaultOptions.and("-Ycheck:nullarify")),
compileFile("tests/pos-special/utf8encoded.scala", explicitUTF8),
compileFile("tests/pos-special/utf16encoded.scala", explicitUTF16),
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init")),
compileFilesInDir("tests/pos-deep-subtype", allowDeepSubtypes),
compileFilesInDir("tests/pos-special/sourcepath/outer", defaultOptions.and("-sourcepath", "tests/pos-special/sourcepath")),
compileFile("tests/pos-special/sourcepath/outer/nested/Test4.scala", defaultOptions.and("-sourcepath", "tests/pos-special/sourcepath")),
compileFilesInDir("tests/pos-special/fatal-warnings", defaultOptions.and("-Xfatal-warnings", "-deprecation", "-feature")),
compileFilesInDir("tests/pos-special/spec-t5545", defaultOptions),
compileFilesInDir("tests/pos-special/strawman-collections", allowDeepSubtypes),
compileFilesInDir("tests/pos-special/isInstanceOf", allowDeepSubtypes.and("-Xfatal-warnings")),
compileFilesInDir("tests/new", defaultOptions.and("-source", "3.2")), // just to see whether 3.2 works
compileFilesInDir("tests/pos-scala2", scala2CompatMode),
compileFilesInDir("tests/pos-scala2", defaultOptions.and("-source", "3.0-migration")),
compileFilesInDir("tests/pos-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking")),
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init")),
compileFile("tests/pos-special/utf8encoded.scala", defaultOptions.and("-encoding", "UTF8")),
compileFile("tests/pos-special/utf16encoded.scala", defaultOptions.and("-encoding", "UTF16")),
// Run tests for legacy lazy vals
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.posLazyValsAllowlist)),
compileFilesInDir("tests/pos-deep-subtype", allowDeepSubtypes),
compileDir("tests/pos-special/java-param-names", defaultOptions.withJavacOnlyOptions("-parameters")),
)

Expand All @@ -59,7 +53,7 @@ class CompilationTests {
implicit val testGroup: TestGroup = TestGroup("rewrites")

aggregateTests(
compileFile("tests/rewrites/rewrites.scala", scala2CompatMode.and("-rewrite", "-indent")),
compileFile("tests/rewrites/rewrites.scala", defaultOptions.and("-source", "3.0-migration").and("-rewrite", "-indent")),
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration", "-Xfatal-warnings")),
compileFile("tests/rewrites/filtering-fors.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
Expand Down Expand Up @@ -120,27 +114,14 @@ class CompilationTests {
implicit val testGroup: TestGroup = TestGroup("compileNeg")
aggregateTests(
compileFilesInDir("tests/neg", defaultOptions),
compileFilesInDir("tests/neg-tailcall", defaultOptions),
compileFilesInDir("tests/neg-strict", defaultOptions.and("-source", "future", "-deprecation", "-Xfatal-warnings")),
compileFilesInDir("tests/neg-custom-args/allow-double-bindings", allowDoubleBindings),
compileFilesInDir("tests/neg-custom-args/allow-deep-subtypes", allowDeepSubtypes),
compileFilesInDir("tests/neg-deep-subtype", allowDeepSubtypes),
compileFilesInDir("tests/neg-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking")),
compileFile("tests/neg-custom-args/i1650.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/i3882.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/i4372.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/i1754.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/i12650.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/interop-polytypes.scala", allowDeepSubtypes.and("-Yexplicit-nulls")),
compileFile("tests/neg-custom-args/conditionalWarnings.scala", allowDeepSubtypes.and("-deprecation").and("-Xfatal-warnings")),
compileFilesInDir("tests/neg-custom-args/isInstanceOf", allowDeepSubtypes and "-Xfatal-warnings"),
compileFile("tests/neg-custom-args/i3627.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/sourcepath/outer/nested/Test1.scala", defaultOptions.and("-sourcepath", "tests/neg-custom-args/sourcepath")),
compileDir("tests/neg-custom-args/sourcepath2/hi", defaultOptions.and("-sourcepath", "tests/neg-custom-args/sourcepath2", "-Xfatal-warnings")),
compileList("duplicate source", List(
"tests/neg-custom-args/toplevel-samesource/S.scala",
"tests/neg-custom-args/toplevel-samesource/nested/S.scala"),
defaultOptions),
compileFile("tests/neg-custom-args/i6300.scala", allowDeepSubtypes),
compileFile("tests/neg/i7575.scala", defaultOptions.withoutLanguageFeatures.and("-language:_")),
).checkExpectedErrors()
}
Expand All @@ -155,12 +136,9 @@ class CompilationTests {
@Test def runAll: Unit = {
implicit val testGroup: TestGroup = TestGroup("runAll")
aggregateTests(
compileFile("tests/run-custom-args/typeclass-derivation1.scala", defaultOptions.without(yCheckOptions*)),
compileFile("tests/run-custom-args/tuple-cons.scala", allowDeepSubtypes),
compileFile("tests/run-custom-args/i5256.scala", allowDeepSubtypes),
compileFilesInDir("tests/run-custom-args/captures", allowDeepSubtypes.and("-language:experimental.captureChecking")),
compileFilesInDir("tests/run-deep-subtype", allowDeepSubtypes),
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init")),
compileFilesInDir("tests/run-deep-subtype", allowDeepSubtypes),
compileFilesInDir("tests/run-custom-args/captures", allowDeepSubtypes.and("-language:experimental.captureChecking")),
// Run tests for legacy lazy vals.
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.runLazyValsAllowlist)),
).checkRuns()
Expand All @@ -178,7 +156,6 @@ class CompilationTests {
@Test def pickling: Unit = {
implicit val testGroup: TestGroup = TestGroup("testPickling")
aggregateTests(
compileFilesInDir("tests/new", picklingOptions),
compileFilesInDir("tests/pos", picklingOptions, FileFilter.exclude(TestSources.posTestPicklingBlacklisted)),
compileFilesInDir("tests/run", picklingOptions, FileFilter.exclude(TestSources.runTestPicklingBlacklisted))
).checkCompile()
Expand All @@ -188,8 +165,7 @@ class CompilationTests {
def recheck: Unit =
given TestGroup = TestGroup("recheck")
aggregateTests(
compileFilesInDir("tests/new", recheckOptions),
compileFilesInDir("tests/run", recheckOptions, FileFilter.exclude(TestSources.runTestRecheckExcluded))
compileFilesInDir("tests/run", defaultOptions.and("-Yrecheck-test"), FileFilter.exclude(TestSources.runTestRecheckExcluded))
//Disabled to save some time.
//compileFilesInDir("tests/pos", recheckOptions, FileFilter.exclude(TestSources.posTestRecheckExcluded)),
).checkCompile()
Expand All @@ -198,22 +174,22 @@ class CompilationTests {
@Test def explicitNullsNeg: Unit = {
implicit val testGroup: TestGroup = TestGroup("explicitNullsNeg")
aggregateTests(
compileFilesInDir("tests/explicit-nulls/neg", explicitNullsOptions),
compileFilesInDir("tests/explicit-nulls/unsafe-common", explicitNullsOptions),
compileFilesInDir("tests/explicit-nulls/neg", defaultOptions and "-Yexplicit-nulls"),
compileFilesInDir("tests/explicit-nulls/unsafe-common", defaultOptions and "-Yexplicit-nulls"),
)
}.checkExpectedErrors()

@Test def explicitNullsPos: Unit = {
implicit val testGroup: TestGroup = TestGroup("explicitNullsPos")
aggregateTests(
compileFilesInDir("tests/explicit-nulls/pos", explicitNullsOptions),
compileFilesInDir("tests/explicit-nulls/unsafe-common", explicitNullsOptions and "-language:unsafeNulls"),
compileFilesInDir("tests/explicit-nulls/pos", defaultOptions and "-Yexplicit-nulls"),
compileFilesInDir("tests/explicit-nulls/unsafe-common", defaultOptions and "-Yexplicit-nulls" and "-language:unsafeNulls"),
)
}.checkCompile()

@Test def explicitNullsRun: Unit = {
implicit val testGroup: TestGroup = TestGroup("explicitNullsRun")
compileFilesInDir("tests/explicit-nulls/run", explicitNullsOptions)
compileFilesInDir("tests/explicit-nulls/run", defaultOptions and "-Yexplicit-nulls")
}.checkRuns()

// initialization tests
Expand Down
7 changes: 0 additions & 7 deletions compiler/test/dotty/tools/vulpix/TestConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ object TestConfiguration {
)
val picklingWithCompilerOptions =
picklingOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath)
val recheckOptions = defaultOptions.and("-Yrecheck-test")
val scala2CompatMode = defaultOptions.and("-source", "3.0-migration")
val explicitUTF8 = defaultOptions and ("-encoding", "UTF8")
val explicitUTF16 = defaultOptions and ("-encoding", "UTF16")

/** Enables explicit nulls */
val explicitNullsOptions = defaultOptions and "-Yexplicit-nulls"

/** Default target of the generated class files */
private def defaultTarget: String = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class Test {
def remove[S](a: S | Int, f: Int => S):S = a match {
case a: S => a // error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class C[T] {
val x: Any = ???
if (x.isInstanceOf[List[String]]) // error: unchecked
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

trait C[T]
class D[T]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class Test {
trait A[+T]
class B[T] extends A[T]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

object Test {
trait Foo
case class One[+T](fst: T)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

object Test1 {
trait Tree[-T]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//> using options -deprecation -Xfatal-warnings

// run with -deprecation -Xfatal-warnings
object Test {
@deprecated def foo = ???

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

sealed trait Exp[T]
case class Fun[A, B](f: Exp[A => B]) extends Exp[A => B]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class Test {
trait A[+T]
class B[T] extends A[T]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

object HTML:
type AttrArg = AppliedAttr | Seq[AppliedAttr]
opaque type AppliedAttr = String
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

trait Box[+T]
case class Foo[+S](s: S) extends Box[S]

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

import scala.collection.mutable

object Test:
Expand All @@ -14,10 +16,10 @@ object Test:
type JsonArray = mutable.Buffer[Json]

def encode(x: Json): Int = x match
case str: String => 1
case b: Boolean => 2
case i: Int => 3
case d: Double => 4
case str: String => 1 // error
case b: Boolean => 2 // error
case i: Int => 3 // error
case d: Double => 4 // error
case arr: JsonArray => 5 // error
case obj: JsonObject => 6 // error
case _ => 7
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class Foo {
def foo(x: Any): Boolean =
x.isInstanceOf[List[String]] // error
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class Test {
def test[X <: Option[Int]](x: X) = x.isInstanceOf[Some[Int]]
def test1[Y <: Int, X <: Option[Y]](x: X) = x.isInstanceOf[Some[Int]]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class A
class B

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class Foo {
def test[A]: (List[Int] | A) => Int = {
case ls: List[Int] => ls.head // error, A = List[String]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class Foo {
def test1[A]: List[Int] | A => Int = {
case ls: List[_] => ls.head // error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Main {
assert(implicitly[thatSelf.type <:< that.This] != null)
}
val that: HasThisType[_] = Foo() // null.asInstanceOf
testSelf(that) // error
testSelf(that) // error: recursion limit exceeded
}


Expand All @@ -36,7 +36,7 @@ object Main {
}
val that: HasThisType[_] = Foo() // null.asInstanceOf
// this line of code makes Dotty compiler infinite recursion (stopped only by overflow) - comment it to make it compilable again
testSelf(that) // error
testSelf(that) // error: recursion limit exceeded
}

// ---- ---- ---- ----
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

sealed trait Foo[+A]
case class Bar[A]() extends Foo[A]

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Yexplicit-nulls

class Foo {
import java.util.ArrayList
// Test that return values in PolyTypes are marked as nullable.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

object Test1 {
trait Tree
trait Context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class A[-T]
class B[T] extends A[T]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class A
class B extends A
type AA = A { type T = Int }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

// Test cases: the only place we can cut and paste without crying
// ourself to sleep.
object Test {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

trait A[T]
trait B[T] extends A[T]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -source future -deprecation -Xfatal-warnings

trait A:
def f: Int

Expand Down
2 changes: 2 additions & 0 deletions tests/neg-strict/i1050.scala → tests/neg/i1050.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -source future -deprecation -Xfatal-warnings

// i1050 checks failing at posttyper
trait A { type L <: Nothing }
trait B { type L >: Any}
Expand Down
2 changes: 2 additions & 0 deletions tests/neg-strict/i11225.scala → tests/neg/i11225b.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -source future -deprecation -Xfatal-warnings

import compiletime.uninitialized

class Memo[A](x: => A):
Expand Down
2 changes: 2 additions & 0 deletions tests/neg-strict/i15479.scala → tests/neg/i15479.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -source future -deprecation -Xfatal-warnings

package deptest {
@deprecated("Not used any more", since="7")
object DeprecatedThing {
Expand Down
2 changes: 2 additions & 0 deletions tests/neg-strict/i16092.scala → tests/neg/i16092.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -source future -deprecation -Xfatal-warnings

trait X {
type T
def process(t: T): Unit
Expand Down
2 changes: 2 additions & 0 deletions tests/neg-strict/i5854.scala → tests/neg/i5854.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -source future -deprecation -Xfatal-warnings

object bar {
trait Sub {
type M
Expand Down
2 changes: 2 additions & 0 deletions tests/neg-strict/nullless.scala → tests/neg/nullless.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -source future -deprecation -Xfatal-warnings

object nullless {
trait LowerBound[T] {
type M >: T;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions tests/new/test.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

sealed trait A[T]
class B[T] extends A[T]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class Test {
val x: Any = ???

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

class C[T] {
val x: T = ???
x.isInstanceOf[T]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -Xfatal-warnings

object Test {
trait Marker
def foo[T](x: T) = x match {
Expand Down
Loading

0 comments on commit 754dab7

Please sign in to comment.