Skip to content

Commit d7ded43

Browse files
committed
Extract scalac options checks from SipScalaTests to the compile sub-command test suite
1 parent 31a7ee6 commit d7ded43

File tree

4 files changed

+91
-65
lines changed

4 files changed

+91
-65
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
}

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

+1
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

+1
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

-65
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)