Skip to content

Commit

Permalink
Simplify macro tests with custom args
Browse files Browse the repository at this point in the history
[Cherry-picked cc90bf3][modified]
  • Loading branch information
Kordyjan committed Dec 7, 2023
1 parent 451838f commit c921574
Show file tree
Hide file tree
Showing 51 changed files with 125 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ class BootstrappedOnlyCompilationTests {
aggregateTests(
compileFilesInDir("tests/bench", defaultOptions.without("-Yno-deep-subtypes")),
compileFilesInDir("tests/pos-macros", defaultOptions.and("-Xcheck-macros")),
compileFilesInDir("tests/pos-custom-args/semanticdb", defaultOptions.and("-Xsemanticdb")),
compileDir("tests/pos-special/i7592", defaultOptions.and("-Yretain-trees")),
compileDir("tests/pos-special/i11331.1", defaultOptions),
compileDir("tests/pos-custom-args/i13405", defaultOptions.and("-Xfatal-warnings")),
).checkCompile()
}

Expand Down Expand Up @@ -107,12 +103,8 @@ class BootstrappedOnlyCompilationTests {

@Test def negMacros: Unit = {
implicit val testGroup: TestGroup = TestGroup("compileNegWithCompiler")
aggregateTests(
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros")),
compileFile("tests/pos-macros/i9570.scala", defaultOptions.and("-Xfatal-warnings")),
compileFile("tests/pos-macros/macro-deprecation.scala", defaultOptions.and("-Xfatal-warnings", "-deprecation")),
compileFile("tests/pos-macros/macro-experimental.scala", defaultOptions.and("-Yno-experimental")),
).checkExpectedErrors()
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros"))
.checkExpectedErrors()
}

@Test def negWithCompiler: Unit = {
Expand All @@ -127,15 +119,9 @@ class BootstrappedOnlyCompilationTests {

@Test def runMacros: Unit = {
implicit val testGroup: TestGroup = TestGroup("runMacros")
aggregateTests(
compileFilesInDir("tests/run-macros", defaultOptions.and("-Xcheck-macros")),
compileFilesInDir("tests/run-custom-args/Yretain-trees", defaultOptions and "-Yretain-trees"),
compileFilesInDir("tests/run-custom-args/Yread-comments", defaultOptions and "-Yread-docs"),
compileFilesInDir("tests/run-custom-args/run-macros-erased", defaultOptions.and("-language:experimental.erasedDefinitions").and("-Xcheck-macros")),
compileDir("tests/run-custom-args/Xmacro-settings/simple", defaultOptions.and("-Xmacro-settings:one,two,three")),
compileDir("tests/run-custom-args/Xmacro-settings/compileTimeEnv", defaultOptions.and("-Xmacro-settings:a,b=1,c.b.a=x.y.z=1,myLogger.level=INFO")),
)
}.checkRuns()
compileFilesInDir("tests/run-macros", defaultOptions.and("-Xcheck-macros"))
.checkRuns()
}

@Test def runWithCompiler: Unit = {
implicit val testGroup: TestGroup = TestGroup("runWithCompiler")
Expand Down
2 changes: 2 additions & 0 deletions tests/pos-macros/i9570.scala → tests/neg-macros/i9570.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Xfatal-warnings

import scala.quoted.*

object Macros {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Xfatal-warnings -deprecation

import scala.quoted.*

inline def f = ${ impl } // error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Yno-experimental

import scala.quoted.*
import scala.annotation.experimental

Expand Down
9 changes: 9 additions & 0 deletions tests/neg/i9685bis.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- [E008] Not Found Error: tests/neg/i9685bis.scala:25:4 ---------------------------------------------------------------
25 | 1.asdf // error
| ^^^^^^
| value asdf is not a member of Int, but could be made available as an extension method.
|
| The following import might make progress towards fixing the problem:
|
| import foo.Baz.toBaz
|
25 changes: 25 additions & 0 deletions tests/neg/i9685bis.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// scalac: -source future

package foo

import scala.language.implicitConversions

class Foo

object Foo:

inline implicit def toFoo(x: Int): Foo = Foo()

class Bar

object Bar:
inline given Conversion[Int, Bar] with
def apply(x: Int): Bar = Bar()

class Baz

object Baz:
transparent inline implicit def toBaz(x: Int): Baz = Baz()

object Usage:
1.asdf // error
1 change: 0 additions & 1 deletion tests/pos-custom-args/i13405/Test.scala

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/pos-macros/i13405/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// scalac: -Xfatal-warnings

@main def main: Unit = hh()
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Yretain-trees

def return1 = 1

def testReturn1 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// scalac: -Xsemanticdb

object Test {
def main(args: Array[String]): Unit = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Xsemanticdb

import scala.quoted.*

object Succ:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Xsemanticdb

import quoted.*

object CodeImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Xsemanticdb

import quoted.*

object TestImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Xsemanticdb

object Test {

def test = TestImpl.fun("")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Xmacro-settings:a,b=1,c.b.a=x.y.z=1,myLogger.level=INFO

import scala.compiletime.*

object Test {
Expand All @@ -16,10 +18,10 @@ object Test {
}

def runBasic(): Unit = {
printEnv("a")
printEnv("b")
printEnv("c.b.a")
printEnv("wat")
printEnv("a")
printEnv("b")
printEnv("c.b.a")
printEnv("wat")
}

inline def printEnv(inline k: String): Unit =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Xmacro-settings:one,two,three

import x.*

object Test {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Yread-docs

@main def Test(): Unit = {
println(getDocString[Data])
assert(getDocString[Data].nonEmpty)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Yread-docs

@main def Test(): Unit = {
val res = getDocString[scala.quoted.Quotes]
println(res)
Expand Down
3 changes: 3 additions & 0 deletions tests/run-macros/i17105b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
case erased: [erased case]
case erased nested: c
case erased nested 2: d
27 changes: 27 additions & 0 deletions tests/run-macros/i17105b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import scala.language.experimental.erasedDefinitions

import scala.quoted.*

inline def testExpr(inline body: Any) = ${ testExprImpl('body) }
def testExprImpl(body: Expr[Any])(using Quotes): Expr[String] =
body match
// Erased Types
case '{ def erasedfn(y: String) = "placeholder"; $a(erasedfn): String } =>
Expr("This case should not match")
case '{ def erasedfn(erased y: String) = "placeholder"; $a(erasedfn): String } =>
'{ $a((erased z: String) => "[erased case]") }
case '{
def erasedfn(a: String, b: String)(c: String, d: String): String = a
$y(erasedfn): String
} => Expr("This should not match")
case '{
def erasedfn(a: String, erased b: String)(erased c: String, d: String): String = a
$y(erasedfn): String
} =>
'{ $y((a: String, erased b: String) => (erased c: String, d: String) => d) }
case '{
def erasedfn(a: String, erased b: String)(c: String, erased d: String): String = a
$y(erasedfn): String
} =>
'{ $y((a: String, erased b: String) => (c: String, erased d: String) => c) }
case _ => Expr("not matched")
12 changes: 12 additions & 0 deletions tests/run-macros/i17105b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import scala.language.experimental.erasedDefinitions

@main def Test: Unit =
println("case erased: " + testExpr { def erasedfn1(erased x: String) = "placeholder"; erasedfn1("arg1")})
println("case erased nested: " + testExpr {
def erasedfn2(p: String, erased q: String)(r: String, erased s: String) = p
erasedfn2("a", "b")("c", "d")
})
println("case erased nested 2: " + testExpr {
def erasedfn2(p: String, erased q: String)(erased r: String, s: String) = p
erasedfn2("a", "b")("c", "d")
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import scala.language.experimental.erasedDefinitions

import scala.quoted.*

object Macro {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import scala.language.experimental.erasedDefinitions

trait Box {
type T
}
Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/tasty-definitions-1/quoted_2.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// scalac: -Yretain-trees

object Test {
def main(args: Array[String]): Unit = {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Yretain-trees

object Test {
def main(args: Array[String]): Unit = {
println(Foo.inspectBody(Foo.foo))
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// scalac: -Yretain-trees

object Test {

def main(args: Array[String]): Unit = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// scalac: -Yretain-trees

import Macros.*

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// scalac: -Yretain-trees

object Test {
def main(args: Array[String]): Unit = {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// scalac: -Yretain-trees

object Test {
def main(args: Array[String]): Unit = {
Expand Down

0 comments on commit c921574

Please sign in to comment.