Skip to content

Commit

Permalink
Warning for multiple files with using directives
Browse files Browse the repository at this point in the history
  • Loading branch information
wleczny committed Nov 17, 2022
1 parent 1d80196 commit f6754da
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/build/src/main/scala/scala/build/CrossSources.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ object CrossSources {

val preprocessedInputFromArgs = value(preprocessSources(inputs.flattened()))

val preprocessedWithUsingDirs =
preprocessedInputFromArgs.filter(p => p.options != Some(BuildOptions()) && p.options != None)
if (preprocessedWithUsingDirs.length > 1) println(
"Warning: using directives detected in multiple files. It is recommended to keep them centralized in the project.scala file."
)

val sourcesFromDirectives =
preprocessedInputFromArgs
.flatMap(_.options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,27 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
}
}

test("multiple using directives warning message") {
val inputs = TestInputs(
os.rel / "Foo.scala" ->
s"""//> using scala "3.2.0"
|
|object Foo extends App {
| println("Foo")
|}
|""".stripMargin,
os.rel / "Bar.scala" -> "",
os.rel / "Hello.java" -> "//> using packaging.output \"out\"",
)
inputs.fromRoot{ root =>
val warningMessage = "Warning: using directives detected in multiple files."
val output1 = os.proc(TestUtil.cli, ".").call(cwd = root).out.trim()
val output2 = os.proc(TestUtil.cli, "Foo.scala", "Bar.scala").call(cwd = root).out.trim()
expect(output1.contains(warningMessage))
expect(!output2.contains(warningMessage))
}
}

def sudoTest(): Unit = {
val fileName = "simple.sc"
val message = "Hello"
Expand Down

0 comments on commit f6754da

Please sign in to comment.