Skip to content

Commit 5191a99

Browse files
authored
Fix ./mill init example download paths (#5516)
Also add a simple smoketest that captiures the logs make sure the download path isn't malformed
1 parent 6bddfbf commit 5191a99

File tree

2 files changed

+80
-60
lines changed

2 files changed

+80
-60
lines changed

dist/package.mill

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ object `package` extends MillJavaModule with DistModule {
235235
for (path <- examplePaths()) yield {
236236
val example = path.subRelativeTo(BuildCtx.workspaceRoot)
237237
val artifactName = example.segments.mkString("-")
238-
(path, s"${build.dist.artifactFileNamePrefix()}-$artifactName")
238+
s"${build.dist.artifactFileNamePrefix()}-$artifactName"
239239
}
240240
}
241241

242242
def exampleZips: T[Seq[PathRef]] = Task {
243243
examplePathRefs().zip(exampleArtifactNames()).map {
244-
case (pr, (examplePath, exampleStr)) =>
244+
case (pr, exampleStr) =>
245245
os.copy(pr.path, Task.dest / exampleStr, createFolders = true)
246246
val ignoreErrorsOnCI = Task.dest / exampleStr / "ignoreErrorsOnCI"
247247
if (os.exists(ignoreErrorsOnCI)) os.remove(ignoreErrorsOnCI)

libs/init/test/src/mill/init/InitModuleTests.scala

Lines changed: 78 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,69 +19,89 @@ object InitModuleTests extends TestSuite {
1919

2020
override def tests: Tests = Tests {
2121

22-
test("init") {
23-
test("no args") {
24-
val outStream = new ByteArrayOutputStream()
25-
UnitTester(
26-
initmodule,
27-
null,
28-
outStream = new PrintStream(outStream, true),
29-
errStream = new PrintStream(OutputStream.nullOutputStream(), true)
30-
).scoped { evaluator =>
31-
32-
val results = evaluator.evaluator.execute(Seq(initmodule.init(None))).executionResults
33-
34-
assert(results.transitiveFailing.size == 0)
35-
36-
val mill.api.ExecResult.Success(Val(value)) = results.results.head: @unchecked
37-
val consoleShown = outStream.toString
38-
39-
val examplesList: Seq[String] = value.asInstanceOf[Seq[String]]
40-
assert(
41-
consoleShown.startsWith(initmodule.msg),
42-
examplesList.forall(_.nonEmpty)
43-
)
44-
}
22+
test("no args") {
23+
val outStream = new ByteArrayOutputStream()
24+
UnitTester(
25+
initmodule,
26+
null,
27+
outStream = new PrintStream(outStream, true),
28+
errStream = new PrintStream(OutputStream.nullOutputStream(), true)
29+
).scoped { evaluator =>
30+
31+
val results = evaluator.evaluator.execute(Seq(initmodule.init(None))).executionResults
32+
33+
assert(results.transitiveFailing.size == 0)
34+
35+
val mill.api.ExecResult.Success(Val(value)) = results.results.head: @unchecked
36+
val consoleShown = outStream.toString
37+
38+
val examplesList: Seq[String] = value.asInstanceOf[Seq[String]]
39+
assert(
40+
consoleShown.startsWith(initmodule.msg),
41+
examplesList.forall(_.nonEmpty)
42+
)
4543
}
46-
test("non existing example") {
47-
val outStream = new ByteArrayOutputStream()
48-
val errStream = new ByteArrayOutputStream()
49-
UnitTester(
50-
initmodule,
51-
null,
52-
outStream = new PrintStream(outStream, true),
53-
errStream = new PrintStream(errStream, true)
54-
).scoped { evaluator =>
55-
56-
val nonExistingModuleId = "nonExistingExampleId"
57-
val results = evaluator.evaluator.execute(Seq(
58-
initmodule.init(Some(nonExistingModuleId))
59-
)).executionResults
60-
assert(results.transitiveFailing.size == 1)
61-
val err = errStream.toString
62-
63-
def check(): Unit =
64-
try assert(err.contains(initmodule.moduleNotExistMsg(nonExistingModuleId)))
65-
catch {
66-
case ex: utest.AssertionError =>
67-
pprint.err.log(outStream)
68-
pprint.err.log(errStream)
69-
throw ex
70-
}
71-
72-
try check()
44+
}
45+
test("non existing example") {
46+
val outStream = new ByteArrayOutputStream()
47+
val errStream = new ByteArrayOutputStream()
48+
UnitTester(
49+
initmodule,
50+
null,
51+
outStream = new PrintStream(outStream, true),
52+
errStream = new PrintStream(errStream, true)
53+
).scoped { evaluator =>
54+
55+
val nonExistingModuleId = "nonExistingExampleId"
56+
val results = evaluator.evaluator.execute(Seq(
57+
initmodule.init(Some(nonExistingModuleId))
58+
)).executionResults
59+
assert(results.transitiveFailing.size == 1)
60+
val err = errStream.toString
61+
62+
def check(): Unit =
63+
try assert(err.contains(initmodule.moduleNotExistMsg(nonExistingModuleId)))
7364
catch {
74-
case ex: utest.AssertionError if Properties.isWin =>
75-
// On Windows, it seems there can be a delay until the messages land in errStream,
76-
// it's worth retrying
77-
ex.printStackTrace(System.err)
78-
val waitFor = 2.seconds
79-
System.err.println(s"Caught $ex, trying again in $waitFor")
80-
Thread.sleep(waitFor.toMillis)
81-
check()
65+
case ex: utest.AssertionError =>
66+
pprint.err.log(outStream)
67+
pprint.err.log(errStream)
68+
throw ex
8269
}
70+
71+
try check()
72+
catch {
73+
case ex: utest.AssertionError if Properties.isWin =>
74+
// On Windows, it seems there can be a delay until the messages land in errStream,
75+
// it's worth retrying
76+
ex.printStackTrace(System.err)
77+
val waitFor = 2.seconds
78+
System.err.println(s"Caught $ex, trying again in $waitFor")
79+
Thread.sleep(waitFor.toMillis)
80+
check()
8381
}
8482
}
8583
}
84+
test("example-zip") {
85+
val outStream = new java.io.ByteArrayOutputStream()
86+
UnitTester(
87+
initmodule,
88+
null,
89+
outStream = new PrintStream(outStream, true),
90+
errStream = new PrintStream(OutputStream.nullOutputStream(), true)
91+
).scoped { evaluator =>
92+
93+
val results = evaluator.evaluator.execute(
94+
Seq(initmodule.init(Some("scalalib/basic/1-simple")))
95+
).executionResults
96+
97+
val expected =
98+
"Downloading example from https://repo1.maven.org/maven2/com/lihaoyi/mill-dist/SNAPSHOT/mill-dist-SNAPSHOT-example-scalalib-basic-1-simple.zip."
99+
100+
// Make sure the download URL logged to the terminal looks reasonable
101+
assert(outStream.toString().contains(expected))
102+
// This should fail because there is no SNAPSHOT version published to maven central
103+
assert(results.results.flatMap(_.asFailing).nonEmpty)
104+
}
105+
}
86106
}
87107
}

0 commit comments

Comments
 (0)