Skip to content

Commit 2ea4041

Browse files
committed
Test --cross with the publish local sub-command
1 parent a96c6f7 commit 2ea4041

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

modules/integration/src/test/scala/scala/cli/integration/PublishLocalTestDefinitions.scala

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
1414

1515
def testPublishVersion: String = "1.5.6"
1616

17-
private object PublishTestInputs {
17+
protected object PublishTestInputs {
1818
def testOrg: String = "test-local-org.sth"
1919
def testName: String = "my-proj"
20-
def projFile(message: String, exclude: Boolean = false): String =
21-
s"""//> using scala $testedPublishedScalaVersion
20+
def projFile(
21+
message: String,
22+
exclude: Boolean = false,
23+
useTestScope: Boolean = false,
24+
crossVersions: Option[Seq[String]] = None
25+
): String =
26+
s"""//> using scala ${crossVersions.map(
27+
_.mkString(" ")
28+
).getOrElse(testedPublishedScalaVersion)}
29+
|${if (useTestScope) "//> using target.scope test" else ""}
2230
|//> using dep com.lihaoyi::os-lib:0.11.3${Some(",exclude=com.lihaoyi%%geny").filter(_ =>
2331
exclude
2432
).getOrElse("")}
@@ -43,14 +51,18 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
4351
|""".stripMargin
4452
}
4553

54+
lazy val projectFilePath: os.RelPath = os.rel / "src" / "project.scala"
55+
lazy val projectConfPath: os.RelPath = os.rel / "src" / "publish-conf.scala"
4656
def inputs(
4757
message: String = "Hello",
4858
includePublishVersion: Boolean = true,
49-
excludeGeny: Boolean = false
59+
excludeGeny: Boolean = false,
60+
useTestScope: Boolean = false,
61+
crossVersions: Option[Seq[String]] = None
5062
): TestInputs =
5163
TestInputs(
52-
os.rel / "project.scala" -> projFile(message, excludeGeny),
53-
os.rel / "publish-conf.scala" -> publishConfFile(includePublishVersion)
64+
projectFilePath -> projFile(message, excludeGeny, useTestScope, crossVersions),
65+
projectConfPath -> publishConfFile(includePublishVersion)
5466
)
5567
}
5668

@@ -146,7 +158,7 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
146158
val output1 = output()
147159
expect(output1 == "Hello")
148160

149-
os.write.over(root / "project.scala", PublishTestInputs.projFile("olleH"))
161+
os.write.over(root / PublishTestInputs.projectFilePath, PublishTestInputs.projFile("olleH"))
150162
publishLocal()
151163
val output2 = output()
152164
expect(output2 == "olleH")
Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
11
package scala.cli.integration
22

3-
class PublishLocalTestsDefault extends PublishLocalTestDefinitions with TestDefault
3+
import com.eed3si9n.expecty.Expecty.expect
4+
5+
class PublishLocalTestsDefault extends PublishLocalTestDefinitions with TestDefault {
6+
test(
7+
s"publish local --cross $actualScalaVersion with ${Constants.scala213} and ${Constants.scala212}"
8+
) {
9+
val expectedMessage = "Hello"
10+
val crossVersions = Seq(actualScalaVersion, Constants.scala213, Constants.scala212)
11+
PublishTestInputs.inputs(message = expectedMessage, crossVersions = Some(crossVersions))
12+
.fromRoot { root =>
13+
os.proc(
14+
TestUtil.cli,
15+
"--power",
16+
"publish",
17+
"local",
18+
".",
19+
extraOptions,
20+
"--cross"
21+
)
22+
.call(cwd = root)
23+
def publishedDep(scalaVersionSuffix: String) =
24+
s"${PublishTestInputs.testOrg}:${PublishTestInputs.testName}_$scalaVersionSuffix:$testPublishVersion"
25+
val r3 =
26+
os.proc(TestUtil.cli, "run", "--dep", publishedDep("3"), extraOptions).call(cwd = root)
27+
expect(r3.out.trim() == expectedMessage)
28+
val r213 = os.proc(
29+
TestUtil.cli,
30+
"run",
31+
"--dep",
32+
publishedDep("2.13"),
33+
"-S",
34+
Constants.scala213,
35+
extraOptions
36+
).call(cwd = root)
37+
expect(r213.out.trim() == expectedMessage)
38+
val r212 = os.proc(
39+
TestUtil.cli,
40+
"run",
41+
"--dep",
42+
publishedDep("2.12"),
43+
"-S",
44+
Constants.scala212,
45+
extraOptions
46+
).call(cwd = root)
47+
expect(r212.out.trim() == expectedMessage)
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)