@@ -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