Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ package dotc

import scala.language.unsafeNulls

import org.junit.{ Test, BeforeClass, AfterClass }
import org.junit.Assert._
import org.junit.Assume._
import org.junit.Ignore
import org.junit.{AfterClass, Ignore, Test}
import org.junit.experimental.categories.Category

import scala.concurrent.duration._
Expand Down Expand Up @@ -97,7 +94,7 @@ class BootstrappedOnlyCompilationTests {
// Negative tests ------------------------------------------------------------

@Test def negMacros: Unit = {
implicit val testGroup: TestGroup = TestGroup("compileNegWithCompiler")
given TestGroup = TestGroup("negMacros")
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros"))
.checkExpectedErrors()
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/test/dotty/tools/utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ private val toolArg = raw"(?://|/\*| \*) ?(?i:(${ToolName.values.mkString("|")})
// ================================================================================================

/** Directive to specify to vulpix the options to pass to Dotty */
private val directiveOptionsArg = raw"//> using options (.*)".r.unanchored
private val directiveJavacOptions = raw"//> using javacOpt (.*)".r.unanchored
private val directiveTargetOptions = raw"//> using target.platform (jvm|scala-js)".r.unanchored
private val directiveUnsupported = raw"//> using (scala) (.*)".r.unanchored
private val directiveUnknown = raw"//> using (.*)".r.unanchored
private val directiveOptionsArg = raw"//> using options (.*)".r
private val directiveJavacOptions = raw"//> using javacOpt (.*)".r
private val directiveTargetOptions = raw"//> using target.platform (jvm|scala-js)".r
private val directiveUnsupported = raw"//> using (scala) (.*)".r
private val directiveUnknown = raw"//> using (.*)".r

// Inspect the lines for compiler options of the form
// `//> using options args`, `// scalajs: args`, `/* scalajs: args`, ` * scalajs: args` etc.
Expand Down
25 changes: 14 additions & 11 deletions compiler/test/dotty/tools/vulpix/FileDiff.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ object FileDiff {
else None
}

def matches(actual: String, expect: String): Boolean = {
val actual1 = actual.stripLineEnd
val expect1 = expect.stripLineEnd
def matches(actual: String, expect: String): Boolean =
val actual1 = actual.stripLineEnd
val expect1 = expect.stripLineEnd
// handle check file path mismatch on windows
def matchesWindowsPath = File.separatorChar == '\\' && actual1.replace('\\', '/') == expect1
// obscure line numbers in frames of stack trace output
def obscureFrameLine(s: String): Option[String] =
//at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:257)
val frame = """\s+at [^(]+\([^:]+:(\d+)\)""".r
frame.findFirstMatchIn(s).map(m => s"${m.before(1)}_${m.after(1)}")
def matchesStackFrame =
actual1.endsWith(")") && expect1.endsWith(")") && obscureFrameLine(actual1) == obscureFrameLine(expect1)
actual1 == expect1 || matchesStackFrame || matchesWindowsPath

// handle check file path mismatch on windows
actual1 == expect1 || File.separatorChar == '\\' && actual1.replace('\\', '/') == expect1
}

def matches(actual: Seq[String], expect: Seq[String]): Boolean = {
actual.length == expect.length
&& actual.lazyZip(expect).forall(matches)
}
def matches(actual: Seq[String], expect: Seq[String]): Boolean = actual.corresponds(expect)(matches)

def dump(path: String, content: Seq[String]): Unit = {
val outFile = dotty.tools.io.File(path)
Expand Down
16 changes: 4 additions & 12 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,28 @@ package vulpix

import scala.language.unsafeNulls

import java.io.{File => JFile, IOException, PrintStream, ByteArrayOutputStream}
import java.lang.System.{lineSeparator => EOL}
import java.io.File => JFile
import java.lang.management.ManagementFactory
import java.net.URL
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
import java.nio.file.{Files, NoSuchFileException, Path, Paths}
import java.nio.file.{Files, NoSuchFileException, Paths}
import java.nio.charset.{Charset, StandardCharsets}
import java.text.SimpleDateFormat
import java.util.{HashMap, Timer, TimerTask}
import java.util.concurrent.{TimeUnit, TimeoutException, Executors => JExecutors}

import scala.collection.mutable
import scala.io.{Codec, Source}
import scala.jdk.CollectionConverters.*
import scala.util.{Random, Try, Failure => TryFailure, Success => TrySuccess, Using}
import scala.util.control.NonFatal
import scala.util.matching.Regex
import scala.collection.mutable.ListBuffer

import dotc.{Compiler, Driver}
import dotc.core.Contexts.*
import dotc.decompiler
import dotc.report
import dotc.interfaces.Diagnostic.ERROR
import dotc.reporting.{Reporter, TestReporter}
import dotc.reporting.Diagnostic
import dotc.config.Config
import dotc.util.{DiffUtil, SourceFile, SourcePosition, Spans, NoSourcePosition}
import dotc.util.{SourceFile, SourcePosition, Spans, NoSourcePosition}
import io.AbstractFile
import dotty.tools.vulpix.TestConfiguration.defaultOptions

/** A parallel testing suite whose goal is to integrate nicely with JUnit
*
Expand Down Expand Up @@ -1458,7 +1450,7 @@ trait ParallelTesting extends RunnerOrchestration:
* By default, files are compiled in alphabetical order. An optional seed
* can be used for randomization.
*/
def compileDir(f: String, flags: TestFlags, randomOrder: Option[Int] = None, recursive: Boolean = true)(implicit testGroup: TestGroup): CompilationTest = {
def compileDir(f: String, flags: TestFlags, randomOrder: Option[Int] = None, recursive: Boolean = true)(using testGroup: TestGroup): CompilationTest = {
val outDir = defaultOutputDir + testGroup + JFile.separator
val sourceDir = new JFile(f)
checkRequirements(f, sourceDir, outDir)
Expand Down
15 changes: 8 additions & 7 deletions compiler/test/dotty/tools/vulpix/TestGroup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package dotty.tools.vulpix

/** Test groups are used to ensure that the output of tests do not overlap.
*
* It can be used to disambiguate ouputs of tests that test the same file but with different options as shown in the following example.
* A test group can be used to disambiguate outputs of tests that test the same file
* but with different options as shown in the following example.
*
* compileFilesInDir("tests/pos", defaultOptions)(TestGroup("compileStdLib")) // will output in ./out/compileStdLib/...
* compileFilesInDir("tests/pos", defaultOptimised)(TestGroup("optimised/testOptimised")) // will output in ./out/optimised/testOptimised/...
*/
class TestGroup(val name: String) extends AnyVal {
override def toString: String = name
}

object TestGroup {
def apply(name: String): TestGroup = new TestGroup(name)
}
opaque type TestGroup = String

object TestGroup:
inline def apply(inline name: String): TestGroup = name
extension (inline group: TestGroup) inline def name: String = group
4 changes: 2 additions & 2 deletions tests/neg-macros/i19842-a.check
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
|Inline stack trace
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|This location contains code that was inlined from Test.scala:5
5 | implicit inline def implicitMakeSerializer[T]: Serializer[T] = ${ Macros.makeSerializer[T] }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 | inline given [T] => Serializer[T] = ${ Macros.makeSerializer[T] }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
---------------------------------------------------------------------------------------------------------------------
8 changes: 3 additions & 5 deletions tests/neg-macros/i19842-a/Macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import scala.annotation.{experimental, targetName}
import scala.quoted.*
import scala.util.Try

object Macros {
def makeSerializer[T: Type](using Quotes): Expr[Serializer[T]] = {
object Macros:
def makeSerializer[T: Type](using Quotes): Expr[Serializer[T]] =
import quotes.reflect.*

val tpe: TypeRepr = TypeRepr.of[T]
Expand All @@ -14,7 +14,7 @@ object Macros {
val modSym: Symbol = Symbol.newModule(
Symbol.spliceOwner,
name,
Flags.Implicit,
Flags.Given,
Flags.EmptyFlags,
_ => List(TypeRepr.of[Object], TypeRepr.of[Serializer[T]]),
_ => Nil,
Expand All @@ -25,5 +25,3 @@ object Macros {
ClassDef.module(modSym, List(TypeTree.of[Serializer[T]]), Nil)

Block(List(modValDef, modClassDef), Ref(modSym)).asExprOf[Serializer[T]]
}
}
4 changes: 2 additions & 2 deletions tests/neg-macros/i19842-a/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
trait Serializer[@specialized T]

object Serializer:
implicit inline def implicitMakeSerializer[T]: Serializer[T] = ${ Macros.makeSerializer[T] }
inline given [T] => Serializer[T] = ${ Macros.makeSerializer[T] }

case class ValidationCls(string: String)

@main def Test = summon[Serializer[ValidationCls]] // error
@main def Test = summon[Serializer[ValidationCls]] // error
2 changes: 1 addition & 1 deletion tests/pos/deferred-givens-singletons.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// //> using options -language:experimental.modularity -source future
//> using options -language:experimental.modularity -source future
import compiletime.*

trait A:
Expand Down
Loading