@@ -8,14 +8,26 @@ import org.junit.Assert.{assertEquals, fail}
8
8
import org .junit .experimental .categories .Category
9
9
10
10
@ Category (Array (classOf [TestCategory ]))
11
- class CommunityBuildTest {
11
+ class CommunityBuildTest { suite =>
12
12
lazy val communitybuildDir : Path = Paths .get(sys.props(" user.dir" ))
13
13
14
14
lazy val compilerVersion : String = {
15
15
val file = communitybuildDir.resolve(" dotty-bootstrapped.version" )
16
16
new String (Files .readAllBytes(file), UTF_8 )
17
17
}
18
18
19
+ def log (msg : String ) = println(Console .GREEN + msg + Console .RESET )
20
+
21
+ /** Executes shell command, returns false in case of error. */
22
+ def exec (projectDir : Path , binary : String , arguments : String * ): Int = {
23
+ val command = binary +: arguments
24
+ log(command.mkString(" " ))
25
+ val builder = new ProcessBuilder (command : _* ).directory(projectDir.toFile).inheritIO()
26
+ val process = builder.start()
27
+ val exitCode = process.waitFor()
28
+ exitCode
29
+ }
30
+
19
31
def testSbt (project : String , testCommand : String , updateCommand : String , extraSbtArgs : Seq [String ] = Nil ) = {
20
32
// Workaround for https://github.com/sbt/sbt/issues/4395
21
33
new File (sys.props(" user.home" ) + " /.sbt/1.0/plugins" ).mkdirs()
@@ -39,9 +51,6 @@ class CommunityBuildTest {
39
51
test(project, " sbt" , arguments)
40
52
}
41
53
42
- def testMill (project : String , testCommand : String , extraMillArgs : Seq [String ] = Nil ) =
43
- test(project, " ./mill" , extraMillArgs :+ testCommand)
44
-
45
54
/** Build the given project with the published local compiler and sbt plugin.
46
55
*
47
56
* This test reads the compiler version from community-build/dotty-bootstrapped.version
@@ -53,8 +62,6 @@ class CommunityBuildTest {
53
62
* @param extraSbtArgs Extra arguments to pass to sbt
54
63
*/
55
64
def test (project : String , command : String , arguments : Seq [String ]): Unit = {
56
- def log (msg : String ) = println(Console .GREEN + msg + Console .RESET )
57
-
58
65
log(s " Building $project with dotty-bootstrapped $compilerVersion... " )
59
66
60
67
val projectDir = communitybuildDir.resolve(" community-projects" ).resolve(project)
@@ -69,17 +76,7 @@ class CommunityBuildTest {
69
76
| """ .stripMargin)
70
77
}
71
78
72
- /** Executes shell command, returns false in case of error. */
73
- def exec (binary : String , arguments : String * ): Int = {
74
- val command = binary +: arguments
75
- log(command.mkString(" " ))
76
- val builder = new ProcessBuilder (command : _* ).directory(projectDir.toFile).inheritIO()
77
- val process = builder.start()
78
- val exitCode = process.waitFor()
79
- exitCode
80
- }
81
-
82
- val exitCode = exec(command, arguments : _* )
79
+ val exitCode = exec(projectDir, command, arguments : _* )
83
80
84
81
if (exitCode != 0 ) {
85
82
fail(s """
@@ -98,23 +95,49 @@ class CommunityBuildTest {
98
95
}
99
96
}
100
97
101
- @ Test def utest = testMill(
102
- project = " utest" ,
103
- testCommand = s " utest.jvm[ $compilerVersion].test " ,
104
- extraMillArgs = List (" -i" , " -D" , s " dottyVersion= $compilerVersion" )
105
- )
106
-
107
- @ Test def oslib = testMill(
108
- project = " os-lib" ,
109
- testCommand = s " os[ $compilerVersion].test " ,
110
- extraMillArgs = List (" -i" , " -D" , s " dottyVersion= $compilerVersion" )
111
- )
112
-
113
- @ Test def oslibWatch = testMill(
114
- project = " os-lib" ,
115
- testCommand = s " os.watch[ $compilerVersion].test " ,
116
- extraMillArgs = List (" -i" , " -D" , s " dottyVersion= $compilerVersion" )
117
- )
98
+ case class MillCommunityProject (project : String , testCommand : String ,
99
+ publishCommand : String = " " , extraArgs : List [String ] = Nil ,
100
+ dependencies : List [MillCommunityProject ] = Nil )
101
+ final def test () =
102
+ dependencies.foreach(_.publish())
103
+ suite.test(project, " ./mill" , extraArgs :+ testCommand)
104
+
105
+ final def publish () =
106
+ log(s " Publishing $project" )
107
+ val projectDir = communitybuildDir.resolve(" community-projects" ).resolve(project)
108
+ if publishCommand.isEmpty
109
+ throw RuntimeException (s " Missing publish command for project $this" )
110
+ exec(projectDir, " ./mill" , (extraArgs :+ publishCommand): _* )
111
+
112
+ object projects {
113
+ val utest = MillCommunityProject (
114
+ project = " utest" ,
115
+ testCommand = s " utest.jvm[ $compilerVersion].test " ,
116
+ publishCommand = s " utest.jvm[ $compilerVersion].publishLocal " ,
117
+ extraArgs = List (" -i" , " -D" , s " dottyVersion= $compilerVersion" )
118
+ )
119
+
120
+ val sourcecode = MillCommunityProject (
121
+ project = " sourcecode" ,
122
+ testCommand = s " sourcecode.jvm[ $compilerVersion].test " ,
123
+ publishCommand = s " sourcecode.jvm[ $compilerVersion].publishLocal " ,
124
+ extraArgs = List (" -i" , " -D" , s " dottyVersion= $compilerVersion" ),
125
+ )
126
+
127
+ val oslib = MillCommunityProject (
128
+ project = " os-lib" ,
129
+ testCommand = s " os[ $compilerVersion].test " ,
130
+ extraArgs = List (" -i" , " -D" , s " dottyVersion= $compilerVersion" ),
131
+ dependencies = List (utest, sourcecode)
132
+ )
133
+
134
+ val oslibWatch = MillCommunityProject (
135
+ project = " os-lib" ,
136
+ testCommand = s " os.watch[ $compilerVersion].test " ,
137
+ extraArgs = List (" -i" , " -D" , s " dottyVersion= $compilerVersion" ),
138
+ dependencies = List (utest, sourcecode)
139
+ )
140
+ }
118
141
119
142
@ Test def intent = testSbt(
120
143
project = " intent" ,
@@ -188,11 +211,13 @@ class CommunityBuildTest {
188
211
updateCommand = " dotty-community-build/update"
189
212
)
190
213
191
- @ Test def sourcecode = testMill(
192
- project = " sourcecode" ,
193
- testCommand = s " sourcecode.jvm[ $compilerVersion].test " ,
194
- extraMillArgs = List (" -i" , " -D" , s " dottyVersion= $compilerVersion" )
195
- )
214
+ @ Test def utest = projects.utest.test()
215
+
216
+ @ Test def sourcecode = projects.sourcecode.test()
217
+
218
+ @ Test def oslib = projects.oslib.test()
219
+
220
+ @ Test def oslibWatch = projects.oslibWatch.test()
196
221
197
222
@ Test def stdLib213 = testSbt(
198
223
project = " stdLib213" ,
0 commit comments