Skip to content

Commit

Permalink
Fix support of multiline shebang
Browse files Browse the repository at this point in the history
  • Loading branch information
sierikov committed May 14, 2024
1 parent 82cd8c0 commit cdf3cdb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scala.build.preprocessing
import scala.util.matching.Regex

object SheBang {
private val sheBangRegex: Regex = s"""(^(#!.*(\\r\\n?|\\n)?)+(\\s*!#.*)?)""".r
private val sheBangRegex: Regex = s"""(^(#!.*(\\X)?)+(\\X*!#.*)?)""".r

def isShebangScript(content: String): Boolean = sheBangRegex.unanchored.matches(content)

Expand Down
13 changes: 13 additions & 0 deletions modules/build/src/test/scala/scala/build/tests/SourcesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ class SourcesTests extends TestUtil.ScalaCliBuildSuite {
|println("Hello World")""".stripMargin,
os.rel / "something5.scala" ->
"""#!/usr/bin/scala-cli
|
|println("Hello World #!")""".stripMargin,
os.rel / "multiline.scala" ->
"""#!/usr/bin/scala-cli
|# comment
|VAL=1
|!#
|
|println("Hello World #!")""".stripMargin
)
Expand All @@ -335,6 +342,12 @@ class SourcesTests extends TestUtil.ScalaCliBuildSuite {
|
|println("Hello World")""".stripMargin,
"""
|
|println("Hello World #!")""".stripMargin,
"""
|
|
|
|
|println("Hello World #!")""".stripMargin
)
Expand Down

0 comments on commit cdf3cdb

Please sign in to comment.