Skip to content

Commit 46dbb4f

Browse files
committed
Add coursier tests
1 parent 4b2ac53 commit 46dbb4f

File tree

6 files changed

+95
-10
lines changed

6 files changed

+95
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111

112112
- name: Cmd Tests
113113
run: |
114-
./project/scripts/sbt ";scala3-bootstrapped/compile ;scala3-bootstrapped/test;sjsSandbox/run;sjsSandbox/test;sjsJUnitTests/test;sjsCompilerTests/test ;sbt-test/scripted scala2-compat/* ;configureIDE ;stdlib-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test"
114+
./project/scripts/sbt ";scala3-bootstrapped/compile ; scala3-compiler-bootstrapped/publishLocal; scala3-bootstrapped/test;sjsSandbox/run;sjsSandbox/test;sjsJUnitTests/test;sjsCompilerTests/test ;sbt-test/scripted scala2-compat/* ;configureIDE ;stdlib-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test"
115115
./project/scripts/bootstrapCmdTests
116116
117117
- name: MiMa

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ community-build/dotty-community-build-deps
9696

9797
# Bloop
9898
.bsp
99+
100+
# Coursier
101+
cs

compiler/src/MainGenericRunner.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,13 @@ object MainGenericRunner {
7373
)
7474
case arg :: tail =>
7575
val line = Try(Source.fromFile(arg).getLines.toList).toOption.flatMap(_.headOption)
76-
val newSettings = if arg.endsWith(".scala") || arg.endsWith(".sc") || (line.nonEmpty && shebangscala.matches(line.get))
77-
then {
78-
settings
79-
.withExecuteMode(ExecuteMode.Script)
80-
.withTargetScript(arg)
81-
.withScriptArgs(tail*)
82-
} else
83-
settings.withResidualArgs(arg)
84-
process(tail, newSettings.withResidualArgs(arg))
76+
if arg.endsWith(".scala") || arg.endsWith(".sc") || (line.nonEmpty && shebangscala.matches(line.get)) then
77+
settings
78+
.withExecuteMode(ExecuteMode.Script)
79+
.withTargetScript(arg)
80+
.withScriptArgs(tail*)
81+
else
82+
process(tail, settings.withResidualArgs(arg))
8583

8684
def main(args: Array[String]): Unit =
8785
val settings = process(args.toList, Settings())
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package dotty
2+
package tools
3+
package scripting
4+
5+
import java.io.File
6+
import java.nio.file.{Path, Paths, Files}
7+
import scala.sys.process._
8+
9+
import org.junit.Test
10+
import org.junit.BeforeClass
11+
12+
import vulpix.TestConfiguration
13+
14+
import dotty.tools.absPath
15+
import scala.collection.mutable.ListBuffer
16+
17+
class CoursierScalaTests:
18+
19+
// classpath tests are managed by scripting.ClasspathTests.scala
20+
def testFiles = scripts("/scripting").filter { ! _.getName.startsWith("classpath") }
21+
22+
// Cannot run tests in parallel, more info here: https://stackoverflow.com/questions/6345660/java-executing-bash-script-error-26-text-file-busy
23+
@Test def allTests =
24+
def scriptArgs() =
25+
val scriptPath = scripts("/scripting").find(_.getName == "showArgs.sc").get.absPath
26+
val testScriptArgs = Seq("a", "b", "c", "-repl", "-run", "-script", "-debug")
27+
28+
val args = scriptPath +: testScriptArgs
29+
val output = CoursierScalaTests.csCmd(args*)
30+
val expectedOutput = List(
31+
"arg 0:[a]",
32+
"arg 1:[b]",
33+
"arg 2:[c]",
34+
"arg 3:[-repl]",
35+
"arg 4:[-run]",
36+
"arg 5:[-script]",
37+
"arg 6:[-debug]",
38+
)
39+
assert(output == expectedOutput)
40+
scriptArgs()
41+
42+
def version() =
43+
val output = CoursierScalaTests.csCmd("-version")
44+
assert(output.mkString("\n").contains(sys.env("DOTTY_BOOTSTRAPPED_VERSION")))
45+
version()
46+
47+
def emptyArgsEqualsRepl() =
48+
val output = CoursierScalaTests.csCmd()
49+
assert(output.mkString("\n").contains("Unable to create a system terminal")) // Scala attempted to create REPL so we can assume it is working
50+
emptyArgsEqualsRepl()
51+
52+
def repl() =
53+
val output = CoursierScalaTests.csCmd("-repl")
54+
assert(output.mkString("\n").contains("Unable to create a system terminal")) // Scala attempted to create REPL so we can assume it is working
55+
repl()
56+
57+
58+
object CoursierScalaTests:
59+
60+
def execCmd(command: String, options: String*): List[String] =
61+
val cmd = (command :: options.toList).toSeq.mkString(" ")
62+
val out = new ListBuffer[String]
63+
cmd.!(ProcessLogger(out += _, out += _))
64+
out.toList
65+
66+
67+
def csCmd(options: String*): List[String] =
68+
val newOptions = options match
69+
case Nil => options
70+
case _ => "--" +: options
71+
execCmd("./cs", (s"""launch "org.scala-lang:scala3-compiler_3:${sys.env("DOTTY_BOOTSTRAPPED_VERSION")}" --main-class "dotty.tools.MainGenericRunner" --property "scala.usejavacp=true"""" +: newOptions)*)
72+
73+
/** Get coursier script */
74+
@BeforeClass def setup(): Unit =
75+
val ver = execCmd("uname").head.replace('L', 'l').replace('D', 'd')
76+
execCmd("curl", s"-fLo cs https://git.io/coursier-cli-$ver") #&& execCmd("chmod", "+x cs")
77+

compiler/test/dotty/tools/utils.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def scripts(path: String): Array[File] = {
1515
dir.listFiles
1616
}
1717

18+
extension (f: File) def absPath =
19+
f.getAbsolutePath.replace('\\', '/')
20+
21+
extension (str: String) def dropExtension =
22+
str.reverse.dropWhile(_ != '.').drop(1).reverse
23+
1824
private def withFile[T](file: File)(action: Source => T): T =
1925
resource(Source.fromFile(file, UTF_8.name))(action)
2026

project/Build.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ object Build {
190190
// Avoid various sbt craziness involving classloaders and parallelism
191191
run / fork := true,
192192
Test / fork := true,
193+
Test / envVars := Map("DOTTY_BOOTSTRAPPED_VERSION" -> dottyVersion),
193194
Test / parallelExecution := false,
194195

195196
outputStrategy := Some(StdoutOutput),

0 commit comments

Comments
 (0)