-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix using directives not working with the shebang line in
.scala
files
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
modules/build/src/test/scala/scala/build/tests/ScalaPreprocessorTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package scala.build.tests | ||
|
||
import com.eed3si9n.expecty.Expecty.expect | ||
|
||
import scala.build.input.SourceScalaFile | ||
import scala.build.preprocessing.{PreprocessedSource, ScalaPreprocessor} | ||
|
||
class ScalaPreprocessorTests extends munit.FunSuite { | ||
|
||
test("should respect using directives in a .scala file with the shebang line") { | ||
TestInputs(os.rel / "Main.scala" -> | ||
"""#!/usr/bin/env -S scala-cli shebang | ||
|//> using lib "com.lihaoyi::os-lib::0.8.1" | ||
| | ||
|object Main { | ||
| def main(args: Array[String]): Unit = { | ||
| println(os.pwd) | ||
| } | ||
|}""".stripMargin).fromRoot { root => | ||
val scalaFile = SourceScalaFile(root, os.sub / "Main.scala") | ||
val Some(Right(result)) = ScalaPreprocessor.preprocess( | ||
scalaFile, | ||
logger = TestLogger(), | ||
allowRestrictedFeatures = false | ||
) | ||
expect(result.nonEmpty) | ||
val Some(directivesPositions) = result.head.directivesPositions | ||
expect(directivesPositions.specialCommentDirectives.startPos == 0 -> 0) | ||
expect(directivesPositions.specialCommentDirectives.endPos == 3 -> 0) | ||
} | ||
} | ||
|
||
test("should respect using directives in a .sc file with the shebang line") { | ||
TestInputs(os.rel / "sample.sc" -> | ||
"""#!/usr/bin/env -S scala-cli shebang | ||
|//> using lib "com.lihaoyi::os-lib::0.8.1" | ||
|println(os.pwd) | ||
|""".stripMargin).fromRoot { root => | ||
val scalaFile = SourceScalaFile(root, os.sub / "sample.sc") | ||
val Some(Right(result)) = ScalaPreprocessor.preprocess( | ||
scalaFile, | ||
logger = TestLogger(), | ||
allowRestrictedFeatures = false | ||
) | ||
expect(result.nonEmpty) | ||
val Some(directivesPositions) = result.head.directivesPositions | ||
expect(directivesPositions.specialCommentDirectives.startPos == 0 -> 0) | ||
expect(directivesPositions.specialCommentDirectives.endPos == 2 -> 0) | ||
} | ||
} | ||
} |