From d43b993f368fa8d343fbefff69f9183cc3371a01 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 16 Jan 2025 08:03:37 -0800 Subject: [PATCH 1/3] Tweak TestGroup --- .../dotc/BootstrappedOnlyCompilationTests.scala | 6 ++---- .../dotty/tools/vulpix/ParallelTesting.scala | 16 ++++------------ compiler/test/dotty/tools/vulpix/TestGroup.scala | 15 ++++++++------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala b/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala index 23980508f17d..3698bc7c0a91 100644 --- a/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala @@ -4,9 +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.{ Test, AfterClass } import org.junit.experimental.categories.Category import scala.concurrent.duration._ @@ -96,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() } diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index 12a53a19931d..a2912d52cfca 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -4,14 +4,11 @@ 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} @@ -19,21 +16,16 @@ 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 * @@ -1458,7 +1450,7 @@ trait ParallelTesting extends RunnerOrchestration { self => * 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) diff --git a/compiler/test/dotty/tools/vulpix/TestGroup.scala b/compiler/test/dotty/tools/vulpix/TestGroup.scala index 3b9a5134f62e..b087086e134e 100644 --- a/compiler/test/dotty/tools/vulpix/TestGroup.scala +++ b/compiler/test/dotty/tools/vulpix/TestGroup.scala @@ -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 From 9d69f39892ce228cab640c17e40cbc1f44943923 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 16 Jan 2025 09:07:24 -0800 Subject: [PATCH 2/3] Tweak neg-macro test --- tests/neg-macros/i19842-a.check | 4 ++-- tests/neg-macros/i19842-a/Macro.scala | 8 +++----- tests/neg-macros/i19842-a/Test.scala | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/neg-macros/i19842-a.check b/tests/neg-macros/i19842-a.check index af628c566c15..2bcba49873b5 100644 --- a/tests/neg-macros/i19842-a.check +++ b/tests/neg-macros/i19842-a.check @@ -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] } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --------------------------------------------------------------------------------------------------------------------- diff --git a/tests/neg-macros/i19842-a/Macro.scala b/tests/neg-macros/i19842-a/Macro.scala index 14b7c3f24a1a..abadda276d13 100644 --- a/tests/neg-macros/i19842-a/Macro.scala +++ b/tests/neg-macros/i19842-a/Macro.scala @@ -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] @@ -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, @@ -25,5 +25,3 @@ object Macros { ClassDef.module(modSym, List(TypeTree.of[Serializer[T]]), Nil) Block(List(modValDef, modClassDef), Ref(modSym)).asExprOf[Serializer[T]] - } -} \ No newline at end of file diff --git a/tests/neg-macros/i19842-a/Test.scala b/tests/neg-macros/i19842-a/Test.scala index ba1611d97696..9e7eb7919d1a 100644 --- a/tests/neg-macros/i19842-a/Test.scala +++ b/tests/neg-macros/i19842-a/Test.scala @@ -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 \ No newline at end of file +@main def Test = summon[Serializer[ValidationCls]] // error From e6fa472aae0d04034a4ac3474d5b6e070a09ceee Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 16 Jan 2025 10:41:09 -0800 Subject: [PATCH 3/3] Relax check file match with stack trace --- .../test/dotty/tools/vulpix/FileDiff.scala | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/compiler/test/dotty/tools/vulpix/FileDiff.scala b/compiler/test/dotty/tools/vulpix/FileDiff.scala index 80fb2bf43534..8a83302a31d4 100644 --- a/compiler/test/dotty/tools/vulpix/FileDiff.scala +++ b/compiler/test/dotty/tools/vulpix/FileDiff.scala @@ -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)