Skip to content

Commit 4673667

Browse files
committed
Extract scalac options checks from SipScalaTests to the compile sub-command test suite
1 parent 333cef0 commit 4673667

File tree

4 files changed

+93
-65
lines changed

4 files changed

+93
-65
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 localBin = root / "local-bin"
54+
os.proc(
55+
TestUtil.cs,
56+
"install",
57+
"--install-dir",
58+
localBin,
59+
s"scalac:$sv"
60+
).call(cwd = root)
61+
val cliRes =
62+
os.proc(
63+
TestUtil.cli,
64+
"compile",
65+
sourceFileName,
66+
"--server=false",
67+
if (useDirective) Nil else warningConfOptions
68+
)
69+
.call(cwd = root, check = false, stderr = os.Pipe)
70+
val scalacRes = os.proc(localBin / "scalac", warningConfOptions, sourceFileName)
71+
.call(cwd = root, check = false, stderr = os.Pipe)
72+
expect(scalacRes.exitCode == cliRes.exitCode)
73+
val scalacResErr = scalacRes.err.trim()
74+
if (sv != Constants.scala3Lts) {
75+
// TODO run this check for LTS when -Wconf gets fixed there
76+
val cliResErr =
77+
cliRes.err.trim().linesIterator.toList
78+
// skip potentially irrelevant logs
79+
.dropWhile(_.contains("Check"))
80+
.mkString(System.lineSeparator())
81+
expect(cliResErr == scalacResErr)
82+
}
83+
else expect(
84+
TestUtil.removeAnsiColors(cliRes.err.trim())
85+
.contains(
86+
"method oldMethod in object WConfExample is deprecated since 1.0.0: This method will be removed"
87+
)
88+
)
89+
}
90+
}
91+
}

modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ abstract class CompileTestDefinitions
1010
extends ScalaCliSuite
1111
with TestScalaVersionArgs
1212
with CompilerPluginTestDefinitions
13+
with CompileScalacCompatTestDefinitions
1314
with SemanticDbTestDefinitions { _: TestScalaVersion =>
1415
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions
1516

modules/integration/src/test/scala/scala/cli/integration/RunScalacCompatTestDefinitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.io.File
77
import scala.jdk.CollectionConverters.*
88
import scala.util.Properties
99

10+
/** For the `compile` counterpart, refer to [[CompileScalacCompatTestDefinitions]] */
1011
trait RunScalacCompatTestDefinitions {
1112
_: RunTestDefinitions =>
1213

modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -496,71 +496,6 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
496496
}
497497
}
498498

499-
test("consecutive -language:* flags are not ignored") {
500-
val sourceFileName = "example.scala"
501-
TestInputs(os.rel / sourceFileName ->
502-
"""//> using scala 3.3.1
503-
|//> using options -Yexplicit-nulls -language:fewerBraces -language:strictEquality
504-
|def repro[A](as: List[A]): List[A] =
505-
| as match
506-
| case Nil => Nil
507-
| case _ => ???
508-
|""".stripMargin).fromRoot { root =>
509-
val res = os.proc(TestUtil.cli, "compile", sourceFileName)
510-
.call(cwd = root, check = false, stderr = os.Pipe)
511-
expect(res.exitCode == 1)
512-
val expectedError =
513-
"Values of types object scala.collection.immutable.Nil and List[A] cannot be compared with == or !="
514-
expect(res.err.trim().contains(expectedError))
515-
}
516-
}
517-
518-
for {
519-
useDirective <- Seq(true, false)
520-
if !Properties.isWin
521-
optionsSource = if (useDirective) "using directive" else "command line"
522-
} test(s"consecutive -Wconf:* flags are not ignored (passed via $optionsSource)") {
523-
val sv = "3.5.2"
524-
val sourceFileName = "example.scala"
525-
val warningConfOptions = Seq("-Wconf:cat=deprecation:e", "-Wconf:any:s")
526-
val maybeDirectiveString =
527-
if (useDirective) s"//> using options ${warningConfOptions.mkString(" ")}" else ""
528-
TestInputs(os.rel / sourceFileName ->
529-
s"""//> using scala $sv
530-
|$maybeDirectiveString
531-
|object WConfExample extends App {
532-
| @deprecated("This method will be removed", "1.0.0")
533-
| def oldMethod(): Unit = println("This is an old method.")
534-
| oldMethod()
535-
|}
536-
|""".stripMargin).fromRoot { root =>
537-
val localCache = root / "local-cache"
538-
val localBin = root / "local-bin"
539-
os.proc(
540-
TestUtil.cs,
541-
"install",
542-
"--cache",
543-
localCache,
544-
"--install-dir",
545-
localBin,
546-
s"scalac:$sv"
547-
).call(cwd = root)
548-
val cliRes =
549-
os.proc(
550-
TestUtil.cli,
551-
"compile",
552-
sourceFileName,
553-
"--server=false",
554-
if (useDirective) Nil else warningConfOptions
555-
)
556-
.call(cwd = root, check = false, stderr = os.Pipe)
557-
val scalacRes = os.proc(localBin / "scalac", warningConfOptions, sourceFileName)
558-
.call(cwd = root, check = false, stderr = os.Pipe)
559-
expect(scalacRes.exitCode == cliRes.exitCode)
560-
expect(cliRes.err.trim() == scalacRes.err.trim())
561-
}
562-
}
563-
564499
for {
565500
sv <- Seq(Constants.scala212, Constants.scala213, Constants.scala3NextRc)
566501
code =

0 commit comments

Comments
 (0)