@@ -31,6 +31,78 @@ trait CompileScalacCompatTestDefinitions { _: CompileTestDefinitions =>
31
31
}
32
32
}
33
33
34
+ // Given the vast number of ways compiler options can be passed from the CLI,
35
+ // we test them all (or most, at the very least), as a (perhaps overkill) sanity check.
36
+ // Pieces of the existing `-language:*` test are reused, but kept separate for clarity.
37
+ {
38
+ val modes @ Seq (viaDirective, viaCli, viaCliWithExplicitOpt, mixed, mixedWithExplicitOpt) =
39
+ Seq (" directive" , " cli" , " cli with -O" , " mixed" , " mixed with -O" )
40
+ for {
41
+ mode <- modes
42
+ if actualScalaVersion == Constants .scala3Next
43
+ syntaxVariant <- Seq (
44
+ Seq (Seq (" -color:never" ), Seq (" -language:noAutoTupling" ), Seq (" -language:strictEquality" )),
45
+ Seq (
46
+ Seq (" -color" , " never" ),
47
+ Seq (" -language" , " noAutoTupling" ),
48
+ Seq (" -language" , " strictEquality" )
49
+ ),
50
+ Seq (Seq (" -color:never" ), Seq (" \" -language:noAutoTupling,strictEquality\" " )),
51
+ Seq (Seq (" -color" , " never" ), Seq (" -language" , " \" noAutoTupling,strictEquality\" " ))
52
+ )
53
+ (cliOpts, directiveOpts) = {
54
+ val (initialCliOpts, initialDirectiveOpts) = mode match {
55
+ case m if m == mixed => syntaxVariant.splitAt(syntaxVariant.length - 1 )
56
+ case m if m == mixedWithExplicitOpt =>
57
+ val (initialCliOpts, initialDirectiveOpts) =
58
+ syntaxVariant.splitAt(syntaxVariant.length - 1 )
59
+ initialCliOpts.map(_.flatMap(o => Seq (" -O" , o))) -> initialDirectiveOpts
60
+ case c if c == viaCli => syntaxVariant -> Nil
61
+ case c if c == viaCliWithExplicitOpt =>
62
+ syntaxVariant.map(_.flatMap(o => Seq (" -O" , o))) -> Nil
63
+ case _ => Nil -> syntaxVariant
64
+ }
65
+ initialCliOpts.flatten.map(_.filter(_ != '"' )) -> initialDirectiveOpts.flatten
66
+ }
67
+ cliOptsString = cliOpts.mkString(" " )
68
+ directiveOptsString = directiveOpts.mkString(" " )
69
+ includeDirective =
70
+ (mode == viaDirective || mode == mixed || mode == mixedWithExplicitOpt) && directiveOpts.nonEmpty
71
+ directiveString = if (includeDirective) s " //> using options $directiveOptsString" else " "
72
+ allOptsString = mode match {
73
+ case m if m.startsWith(mixed) =>
74
+ s " opts passed via command line: $cliOptsString, opts passed via directive: $directiveString"
75
+ case c if c.startsWith(viaCli) =>
76
+ s " opts passed via command line: $cliOptsString"
77
+ case _ =>
78
+ s " opts passed via directive: $directiveString"
79
+ }
80
+ } test(s " compiler options passed in $mode mode: $allOptsString" ) {
81
+ val sourceFileName = " example.scala"
82
+ TestInputs (os.rel / sourceFileName ->
83
+ s """ //> using scala $actualScalaVersion
84
+ | $directiveString
85
+ |case class Cat(name: String)
86
+ |case class Dog(name: String)
87
+ |def strictEquality(c: Cat, d: Dog):Boolean = c == d
88
+ |def takesTuple(tpl: Tuple) = ???
89
+ |def withTuple() = takesTuple(1, 2)
90
+ | """ .stripMargin).fromRoot { root =>
91
+ val res = os.proc(TestUtil .cli, " compile" , sourceFileName, cliOpts)
92
+ .call(cwd = root, check = false , stderr = os.Pipe )
93
+ println(res.err.trim())
94
+ expect(res.exitCode == 1 )
95
+ val errOutput = res.err.trim()
96
+ val expectedStrictEqualityError =
97
+ " Values of types Cat and Dog cannot be compared with == or !="
98
+ expect(errOutput.contains(expectedStrictEqualityError))
99
+ val expectedNoAutoTuplingError =
100
+ " too many arguments for method takesTuple: (tpl: Tuple): Nothing"
101
+ expect(errOutput.trim().contains(expectedNoAutoTuplingError))
102
+ }
103
+ }
104
+ }
105
+
34
106
for {
35
107
useDirective <- Seq (true , false )
36
108
if ! Properties .isWin
0 commit comments