Skip to content

Commit

Permalink
Support //> options directive in compilation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Aug 16, 2023
1 parent c34c741 commit 990faff
Show file tree
Hide file tree
Showing 403 changed files with 404 additions and 403 deletions.
4 changes: 3 additions & 1 deletion compiler/test/dotty/tools/utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ def toolArgsFor(tool: ToolName)(lines: List[String]): List[String] =
// scalac: arg1 arg2, with alternative opening, optional space, alt names, text that is not */ up to end.
// groups are (name, args)
private val toolArg = raw"(?://|/\*| \*) ?(?i:(${ToolName.values.mkString("|")})):((?:[^*]|\*(?!/))*)".r.unanchored
private val directiveOptionsArg = raw"//> using options (.*)".r.unanchored

// Inspect the lines for compiler options of the form
// `// scalac: args`, `/* scalac: args`, ` * scalac: args`.
// If args string ends in close comment, stop at the `*` `/`.
// Returns all the matches by the regex.
def toolArgsParse(lines: List[String]): List[(String,String)] =
lines.flatMap { case toolArg(name, args) => List((name, args)) case _ => Nil }
lines.flatMap { case toolArg(name, args) => List((name, args)) case _ => Nil } ++
lines.flatMap { case directiveOptionsArg(args) => List(("scalac", args)) case _ => Nil }

import org.junit.Test
import org.junit.Assert._
Expand Down
2 changes: 1 addition & 1 deletion tests/explicit-nulls/neg-patmat/match-pat.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
//> using options -Xfatal-warnings

class Foo {

Expand Down
2 changes: 1 addition & 1 deletion tests/explicit-nulls/pos/i14682.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Ysafe-init
//> using options -Ysafe-init

class C1:
sealed abstract class Name {
Expand Down
2 changes: 1 addition & 1 deletion tests/explicit-nulls/pos/i14947.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Ytest-pickler -Xprint-types
//> using options -Ytest-pickler -Xprint-types

class B:
def g: String | Null = ???
Expand Down
2 changes: 1 addition & 1 deletion tests/explicit-nulls/pos/match-pat.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
//> using options -Xfatal-warnings

// Ensure we don't get "the type test for argType cannot be checked at runtime" warning

Expand Down
2 changes: 1 addition & 1 deletion tests/explicit-nulls/pos/unsafe-match-null-pat.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
//> using options -Xfatal-warnings

import scala.language.unsafeNulls

Expand Down
2 changes: 1 addition & 1 deletion tests/neg-custom-args/wildcards.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -source future -deprecation -Xfatal-warnings
//> using options -source future -deprecation -Xfatal-warnings

object Test {
val xs: List[_] = List(1, 2, 3) // error
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i16355a.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//> using scala "3.2.1"
import scala.quoted.Expr
import scala.quoted.Type
import scala.quoted.quotes
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i9570.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
//> using options -Xfatal-warnings

import scala.quoted.*

Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/macro-deprecation.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings -deprecation
//> using options -Xfatal-warnings -deprecation

import scala.quoted.*

Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/macro-experimental.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Yno-experimental
//> using options -Yno-experimental

import scala.quoted.*
import scala.annotation.experimental
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-scalajs/enumeration-warnings.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
//> using options -Xfatal-warnings

class UnableToTransformValue extends Enumeration {
val a = {
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/14034.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Yno-experimental
//> using options -Yno-experimental

import annotation.experimental

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/14034b.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings -deprecation
//> using options -Xfatal-warnings -deprecation

@deprecated trait Exp
@deprecated val exp = 1
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/15981.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Werror
//> using options -Werror
val _ = locally{
sealed abstract class PosInt(val value: Int) {
override def equals(any: Any): Boolean = any.isInstanceOf[PosInt] // error
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/17284.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Werror -explain
//> using options -Werror -explain

def test =
451.synchronized {} // error
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/18031.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -source:future
//> using options -source:future

object A:
val x, y, z = 0
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/IsInstanceOfClassTag.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
//> using options -Xfatal-warnings

import scala.reflect.ClassTag

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/IsInstanceOfClassTag2.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
//> using options -Xfatal-warnings

import scala.reflect.TypeTest

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/adhoc-extension/B.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -source future -feature -Xfatal-warnings
//> using options -source future -feature -Xfatal-warnings

package adhoc
class B extends A // error: adhoc-extension (under -strict -feature -Xfatal-warnings)
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/autoTuplingTestb.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:noAutoTupling
//> using options -language:noAutoTupling

object autoTupling {

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/avoid-warn-deprecation.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings -feature
//> using options -Xfatal-warnings -feature

object A {
@deprecated("use bar instead of this one", "0.2.3")
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/by-name.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

def f(x: => Int, erased y: => Int) = x // error
def g(erased x: => Int, y: => Int) = y // error
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/capt-wf.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.captureChecking -Xfatal-warnings
//> using options -language:experimental.captureChecking -Xfatal-warnings

class C
type Cap = C^
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/classtag-typetest/3_1-migration.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
//> using options -Xfatal-warnings

import scala.language.`future-migration`
import scala.reflect.ClassTag
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/classtag-typetest/3_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
//> using options -Xfatal-warnings

import scala.language.future
import scala.reflect.ClassTag
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/constructor-proxy-shadowing.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -explain
//> using options -explain

object Test extends App {
def A22(s: String): String = s
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/convertible.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings -feature
//> using options -Xfatal-warnings -feature

import language.experimental.into

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/deptypes.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.dependent
//> using options -language:experimental.dependent

type Vec[T] = (n: Int) =>> Array[T] // error: not yet implemented

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/enum-variance.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
//> using options -Xfatal-warnings

enum View[-T]:
case Refl(f: T => T) // error: enum case Refl requires explicit declaration of type T
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
def foo0(a: Int): Int = a
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-2.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
def foo0(a: Int): Int = a
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-24.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

// Could become a run test if we had totality checking for erased arguments

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-3.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
def foo0(a: Int): Int = a
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-4.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-5.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-6.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
erased def foo: Foo = new Foo
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-args-lifted.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
def foo(a: Int)(b: Int, c: Int) = 42
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-assign.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
var i: Int = 1
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-case-class.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

case class Foo1(erased x: Int) // error // error
2 changes: 1 addition & 1 deletion tests/neg/erased-def-rhs.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using optionsage:experimental.erasedDefinitions

object Test {
def f(erased i: Int) = {
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-if-else.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
var b = true
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-implicit.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-in-tuples.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

@main def Test() =
val x = 5
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-lazy-val.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
erased lazy val i: Int = 1 // error
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-machine-state-encoding-with-inline.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

import scala.compiletime.*

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-match.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
var b = true
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-object.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

erased object Test // error
2 changes: 1 addition & 1 deletion tests/neg/erased-path.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

trait Sys { type X }

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-pathdep-1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

// Could become a neg test if we had totality checking for erased arguments

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-pathdep-2.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

// Could become a neg test if we had totality checking for erased arguments

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-return.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
var b = true
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-singleton.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

trait Sys

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-try.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
def foo(erased a: Int): Int = {
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-type.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

class Test {
erased type T // error
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-val-rhs.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
def f(erased i: Int) = {
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-value-class.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

class Foo(erased x: Int) extends AnyVal // error

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erased-var.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

object Test {
erased var i: Int = 1 // error
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/erasedValueb.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -language:experimental.erasedDefinitions
//> using options -language:experimental.erasedDefinitions

import scala.compiletime.erasedValue
object Test {
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/experimental-2.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Yno-experimental
//> using options -Yno-experimental

class Test7 {
import scala.language.experimental
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/experimental-erased.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Yno-experimental
//> using options -Yno-experimental

import language.experimental.erasedDefinitions
import annotation.experimental
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/experimental-imports.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Yno-experimental
//> using options -Yno-experimental

import annotation.experimental

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/experimental-nested-imports-2.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Yno-experimental
//> using options -Yno-experimental

import annotation.experimental

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/experimental-nested-imports-3.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Yno-experimental
//> using options -Yno-experimental

import annotation.experimental

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/experimental-nested-imports.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -Yno-experimental
//> using options -Yno-experimental

import annotation.experimental

Expand Down
Loading

0 comments on commit 990faff

Please sign in to comment.