Skip to content

Commit 86095f7

Browse files
committed
Add coursier tests
1 parent 4b2ac53 commit 86095f7

File tree

6 files changed

+97
-10
lines changed

6 files changed

+97
-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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
for (line, expect) <- output zip expectedOutput do
40+
printf("expected: %-17s\nactual : %s\n", expect, line)
41+
assert(output == expectedOutput)
42+
scriptArgs()
43+
44+
def version() =
45+
val output = CoursierScalaTests.csCmd("-version")
46+
assert(output.mkString("\n").contains(sys.env("DOTTY_BOOTSTRAPPED_VERSION")))
47+
version()
48+
49+
def emptyArgsEqualsRepl() =
50+
val output = CoursierScalaTests.csCmd()
51+
assert(output.mkString("\n").contains("Unable to create a system terminal")) // Scala attempted to create REPL so we can assume it is working
52+
emptyArgsEqualsRepl()
53+
54+
def repl() =
55+
val output = CoursierScalaTests.csCmd("-repl")
56+
assert(output.mkString("\n").contains("Unable to create a system terminal")) // Scala attempted to create REPL so we can assume it is working
57+
repl()
58+
59+
60+
object CoursierScalaTests:
61+
62+
def execCmd(command: String, options: String*): List[String] =
63+
val cmd = (command :: options.toList).toSeq.mkString(" ")
64+
val out = new ListBuffer[String]
65+
cmd.!(ProcessLogger(out += _, out += _))
66+
out.toList
67+
68+
69+
def csCmd(options: String*): List[String] =
70+
val newOptions = options match
71+
case Nil => options
72+
case _ => "--" +: options
73+
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)*)
74+
75+
/** Get coursier script */
76+
@BeforeClass def setup(): Unit =
77+
val ver = execCmd("uname").head.replace('L', 'l').replace('D', 'd')
78+
execCmd("curl", s"-fLo cs https://git.io/coursier-cli-$ver") #&& execCmd("chmod", "+x cs")
79+

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)