Skip to content

Commit 59d2bb8

Browse files
committed
Ensure consecutive -Wunused:* flags are not ignored
1 parent 037314c commit 59d2bb8

File tree

2 files changed

+84
-49
lines changed

2 files changed

+84
-49
lines changed

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

Lines changed: 82 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -118,57 +118,91 @@ trait CompileScalacCompatTestDefinitions { _: CompileTestDefinitions =>
118118
useDirective <- Seq(true, false)
119119
if !Properties.isWin
120120
optionsSource = if (useDirective) "using directive" else "command line"
121-
} test(s"consecutive -Wconf:* flags are not ignored (passed via $optionsSource)") {
122-
val sv = actualScalaVersion
123-
val sourceFileName = "example.scala"
124-
val warningConfOptions = Seq("-Wconf:cat=deprecation:e", "-Wconf:any:s")
125-
val maybeDirectiveString =
126-
if (useDirective) s"//> using options ${warningConfOptions.mkString(" ")}" else ""
127-
TestInputs(os.rel / sourceFileName ->
128-
s"""//> using scala $sv
129-
|$maybeDirectiveString
130-
|object WConfExample extends App {
131-
| @deprecated("This method will be removed", "1.0.0")
132-
| def oldMethod(): Unit = println("This is an old method.")
133-
| oldMethod()
134-
|}
135-
|""".stripMargin).fromRoot { root =>
136-
val localBin = root / "local-bin"
137-
os.proc(
138-
TestUtil.cs,
139-
"install",
140-
"--install-dir",
141-
localBin,
142-
s"scalac:$sv"
143-
).call(cwd = root)
144-
val cliRes =
121+
sv = actualScalaVersion
122+
} {
123+
test(s"consecutive -Wconf:* flags are not ignored (passed via $optionsSource)") {
124+
val sourceFileName = "example.scala"
125+
val warningConfOptions = Seq("-Wconf:cat=deprecation:e", "-Wconf:any:s")
126+
val maybeDirectiveString =
127+
if (useDirective) s"//> using options ${warningConfOptions.mkString(" ")}" else ""
128+
TestInputs(os.rel / sourceFileName ->
129+
s"""//> using scala $sv
130+
|$maybeDirectiveString
131+
|object WConfExample extends App {
132+
| @deprecated("This method will be removed", "1.0.0")
133+
| def oldMethod(): Unit = println("This is an old method.")
134+
| oldMethod()
135+
|}
136+
|""".stripMargin).fromRoot { root =>
137+
val localBin = root / "local-bin"
145138
os.proc(
146-
TestUtil.cli,
147-
"compile",
148-
sourceFileName,
149-
"--server=false",
150-
if (useDirective) Nil else warningConfOptions
151-
)
139+
TestUtil.cs,
140+
"install",
141+
"--install-dir",
142+
localBin,
143+
s"scalac:$sv"
144+
).call(cwd = root)
145+
val cliRes =
146+
os.proc(
147+
TestUtil.cli,
148+
"compile",
149+
sourceFileName,
150+
"--server=false",
151+
if (useDirective) Nil else warningConfOptions
152+
)
153+
.call(cwd = root, check = false, stderr = os.Pipe)
154+
val scalacRes = os.proc(localBin / "scalac", warningConfOptions, sourceFileName)
152155
.call(cwd = root, check = false, stderr = os.Pipe)
153-
val scalacRes = os.proc(localBin / "scalac", warningConfOptions, sourceFileName)
154-
.call(cwd = root, check = false, stderr = os.Pipe)
155-
expect(scalacRes.exitCode == cliRes.exitCode)
156-
val scalacResErr = scalacRes.err.trim()
157-
if (sv != Constants.scala3Lts) {
158-
// TODO run this check for LTS when -Wconf gets fixed there
159-
val cliResErr =
160-
cliRes.err.trim().linesIterator.toList
161-
// skip potentially irrelevant logs
162-
.dropWhile(_.contains("Check"))
163-
.mkString(System.lineSeparator())
164-
expect(cliResErr == scalacResErr)
156+
expect(scalacRes.exitCode == cliRes.exitCode)
157+
val scalacResErr = scalacRes.err.trim()
158+
if (sv != Constants.scala3Lts) {
159+
// TODO run this check for LTS when -Wconf gets fixed there
160+
val cliResErr =
161+
cliRes.err.trim().linesIterator.toList
162+
// skip potentially irrelevant logs
163+
.dropWhile(_.contains("Check"))
164+
.mkString(System.lineSeparator())
165+
expect(cliResErr == scalacResErr)
166+
}
167+
else expect(
168+
TestUtil.removeAnsiColors(cliRes.err.trim())
169+
.contains(
170+
"method oldMethod in object WConfExample is deprecated since 1.0.0: This method will be removed"
171+
)
172+
)
165173
}
166-
else expect(
167-
TestUtil.removeAnsiColors(cliRes.err.trim())
168-
.contains(
169-
"method oldMethod in object WConfExample is deprecated since 1.0.0: This method will be removed"
170-
)
171-
)
172174
}
175+
176+
if (!sv.startsWith("2.12"))
177+
test(s"consecutive -Wunused:* flags are not ignored (passed via $optionsSource)") {
178+
val sourceFileName = "example.scala"
179+
val unusedLintOptions = Seq("-Wunused:locals", "-Wunused:privates")
180+
val maybeDirectiveString =
181+
if (useDirective) s"//> using options ${unusedLintOptions.mkString(" ")}" else ""
182+
TestInputs(os.rel / sourceFileName ->
183+
s"""//> using scala $sv
184+
|$maybeDirectiveString
185+
|object WUnusedExample {
186+
| private def unusedPrivate(): String = "stuff"
187+
| def methodWithUnusedLocal() = {
188+
| val smth = "hello"
189+
| println("Hello")
190+
| }
191+
|}
192+
|""".stripMargin).fromRoot { root =>
193+
val r =
194+
os.proc(
195+
TestUtil.cli,
196+
"compile",
197+
sourceFileName,
198+
if (useDirective) Nil else unusedLintOptions
199+
)
200+
.call(cwd = root, stderr = os.Pipe)
201+
val err = r.err.trim()
202+
val unusedKeyword = if (sv.startsWith("2")) "never used" else "unused"
203+
expect(err.linesIterator.exists(l => l.contains(unusedKeyword) && l.contains("local")))
204+
expect(err.linesIterator.exists(l => l.contains(unusedKeyword) && l.contains("private")))
205+
}
206+
}
173207
}
174208
}

modules/options/src/main/scala/scala/build/options/ScalacOpt.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ object ScalacOpt {
2727
"Xplugin",
2828
"P", // plugin options
2929
"language",
30-
"Wconf"
30+
"Wconf",
31+
"Wunused"
3132
)
3233

3334
implicit val hashedType: HashedType[ScalacOpt] = {

0 commit comments

Comments
 (0)