|
| 1 | +package scala.cli.integration |
| 2 | + |
| 3 | +import com.eed3si9n.expecty.Expecty.expect |
| 4 | + |
| 5 | +import scala.util.Properties |
| 6 | + |
| 7 | +/** For the `run` counterpart, refer to [[RunScalacCompatTestDefinitions]] */ |
| 8 | +trait CompileScalacCompatTestDefinitions { _: CompileTestDefinitions => |
| 9 | + if (actualScalaVersion.startsWith("3")) |
| 10 | + test("consecutive -language:* flags are not ignored") { |
| 11 | + val sourceFileName = "example.scala" |
| 12 | + TestInputs(os.rel / sourceFileName -> |
| 13 | + s"""//> using scala $actualScalaVersion |
| 14 | + |//> using options -color:never -language:noAutoTupling -language:strictEquality |
| 15 | + |case class Cat(name: String) |
| 16 | + |case class Dog(name: String) |
| 17 | + |def strictEquality(c: Cat, d: Dog):Boolean = c == d |
| 18 | + |def takesTuple(tpl: Tuple) = ??? |
| 19 | + |def withTuple() = takesTuple(1, 2) |
| 20 | + |""".stripMargin).fromRoot { root => |
| 21 | + val res = os.proc(TestUtil.cli, "compile", sourceFileName) |
| 22 | + .call(cwd = root, check = false, stderr = os.Pipe) |
| 23 | + expect(res.exitCode == 1) |
| 24 | + val errOutput = res.err.trim() |
| 25 | + val expectedStrictEqualityError = |
| 26 | + " Values of types Cat and Dog cannot be compared with == or !=" |
| 27 | + expect(errOutput.contains(expectedStrictEqualityError)) |
| 28 | + val expectedNoAutoTuplingError = |
| 29 | + "too many arguments for method takesTuple: (tpl: Tuple): Nothing" |
| 30 | + expect(errOutput.trim().contains(expectedNoAutoTuplingError)) |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + for { |
| 35 | + useDirective <- Seq(true, false) |
| 36 | + if !Properties.isWin |
| 37 | + optionsSource = if (useDirective) "using directive" else "command line" |
| 38 | + } test(s"consecutive -Wconf:* flags are not ignored (passed via $optionsSource)") { |
| 39 | + val sv = actualScalaVersion |
| 40 | + val sourceFileName = "example.scala" |
| 41 | + val warningConfOptions = Seq("-Wconf:cat=deprecation:e", "-Wconf:any:s") |
| 42 | + val maybeDirectiveString = |
| 43 | + if (useDirective) s"//> using options ${warningConfOptions.mkString(" ")}" else "" |
| 44 | + TestInputs(os.rel / sourceFileName -> |
| 45 | + s"""//> using scala $sv |
| 46 | + |$maybeDirectiveString |
| 47 | + |object WConfExample extends App { |
| 48 | + | @deprecated("This method will be removed", "1.0.0") |
| 49 | + | def oldMethod(): Unit = println("This is an old method.") |
| 50 | + | oldMethod() |
| 51 | + |} |
| 52 | + |""".stripMargin).fromRoot { root => |
| 53 | + val localCache = root / "local-cache" |
| 54 | + val localBin = root / "local-bin" |
| 55 | + os.proc( |
| 56 | + TestUtil.cs, |
| 57 | + "install", |
| 58 | + "--cache", |
| 59 | + localCache, |
| 60 | + "--install-dir", |
| 61 | + localBin, |
| 62 | + s"scalac:$sv" |
| 63 | + ).call(cwd = root) |
| 64 | + val cliRes = |
| 65 | + os.proc( |
| 66 | + TestUtil.cli, |
| 67 | + "compile", |
| 68 | + sourceFileName, |
| 69 | + "--server=false", |
| 70 | + "-color", |
| 71 | + "never", |
| 72 | + if (useDirective) Nil else warningConfOptions |
| 73 | + ) |
| 74 | + .call(cwd = root, check = false, stderr = os.Pipe) |
| 75 | + val scalacRes = os.proc(localBin / "scalac", warningConfOptions, sourceFileName) |
| 76 | + .call(cwd = root, check = false, stderr = os.Pipe) |
| 77 | + expect(scalacRes.exitCode == cliRes.exitCode) |
| 78 | + if (sv != Constants.scala3Lts) |
| 79 | + // TODO run this check for LTS when -Wconf gets fixed there |
| 80 | + expect(cliRes.err.trim() == scalacRes.err.trim()) |
| 81 | + else |
| 82 | + expect( |
| 83 | + cliRes.err.trim().contains( |
| 84 | + "method oldMethod in object WConfExample is deprecated since 1.0.0: This method will be removed" |
| 85 | + ) |
| 86 | + ) |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments