@@ -39,7 +39,166 @@ class SourceGeneratorTests extends munit.FunSuite {
39
39
)
40
40
)
41
41
42
+ private def normalizeResolvers (contents : String ): String =
43
+ contents
44
+ .replaceAll(
45
+ " ivy:file:[^\" ]*scala-cli-tests-extra-repo[^\" ]*/local-repo[^\" ]*" ,
46
+ " ivy:file:.../scala-cli-tests-extra-repo/local-repo/..."
47
+ )
48
+ .replaceAll(
49
+ " ivy:file:[^\" ]*\\ .ivy2/local[^\" ]*" ,
50
+ " ivy:file:.../.ivy2/local/"
51
+ )
52
+
42
53
test(s " BuildInfo source generated " ) {
54
+ val inputs = TestInputs (
55
+ os.rel / " main.scala" ->
56
+ """ //> using dep com.lihaoyi::os-lib:0.9.1
57
+ |//> using option -Xasync
58
+ |//> using plugin org.wartremover:::wartremover:3.0.9
59
+ |//> using scala 3.2.2
60
+ |//> using jvm 11
61
+ |//> using mainClass Main
62
+ |//> using resourceDir ./resources
63
+ |//> using jar TEST1.jar TEST2.jar
64
+ |
65
+ |//> using buildInfo
66
+ |
67
+ |import scala.cli.build.BuildInfo
68
+ |
69
+ |object Main extends App {
70
+ | println(s"Scala version: ${BuildInfo.scalaVersion}")
71
+ | BuildInfo.MainScopeInfo.customJarsDecls.foreach(println)
72
+ |}
73
+ |""" .stripMargin
74
+ )
75
+
76
+ inputs.withBuild(baseOptions, buildThreads, bloopConfigOpt) {
77
+ (root, _, maybeBuild) =>
78
+ expect(maybeBuild.orThrow.success)
79
+ val projectDir = os.list(root / " .scala-build" ).filter(
80
+ _.baseName.startsWith(root.baseName + " _" )
81
+ )
82
+ expect(projectDir.size == 1 )
83
+ val buildInfoPath = projectDir.head / " src_generated" / " main" / " BuildInfo.scala"
84
+ expect(os.isFile(buildInfoPath))
85
+
86
+ val buildInfoContent = os.read(buildInfoPath)
87
+
88
+ expect(normalizeResolvers(buildInfoContent) ==
89
+ s """ package scala.cli.build
90
+ |
91
+ |object BuildInfo {
92
+ | val scalaVersion = "3.2.2"
93
+ | val platform = "JVM"
94
+ | val jvmVersion = Some("11")
95
+ | val scalaJsVersion = None
96
+ | val jsEsVersion = None
97
+ | val scalaNativeVersion = None
98
+ | val mainClass = Some("Main")
99
+ |
100
+ |
101
+ | object MainScopeInfo {
102
+ | val sources = Seq(" ${root / " main.scala" }")
103
+ | val scalacOptions = Seq("-Xasync")
104
+ | val scalaCompilerPlugins = Seq("org.wartremover:wartremover_3.2.2:3.0.9")
105
+ | val dependencies = Seq("com.lihaoyi:os-lib_3:0.9.1")
106
+ | val resolvers = Seq("ivy:file:.../scala-cli-tests-extra-repo/local-repo/...", "https://repo1.maven.org/maven2", "ivy:file:.../.ivy2/local/")
107
+ | val resourceDirs = Seq(" ${root / " resources" }")
108
+ | val customJarsDecls = Seq(" ${root / " TEST1.jar" }", " ${root / " TEST2.jar" }")
109
+ | }
110
+ |
111
+ | object TestScopeInfo {
112
+ | val sources = Nil
113
+ | val scalacOptions = Nil
114
+ | val scalaCompilerPlugins = Nil
115
+ | val dependencies = Nil
116
+ | val resolvers = Nil
117
+ | val resourceDirs = Nil
118
+ | val customJarsDecls = Nil
119
+ | }
120
+ |
121
+ |}
122
+ | """ .stripMargin)
123
+ }
124
+ }
125
+
126
+ test(s " BuildInfo for native " ) {
127
+ val inputs = TestInputs (
128
+ os.rel / " main.scala" ->
129
+ s """ //> using dep "com.lihaoyi::os-lib:0.9.1"
130
+ |//> using option "-Xasync"
131
+ |//> using plugin "org.wartremover:::wartremover:3.0.9"
132
+ |//> using scala 3.2.2
133
+ |//> using jvm 11
134
+ |//> using mainClass "Main"
135
+ |//> using resourceDir ./resources
136
+ |//> using jar TEST1.jar TEST2.jar
137
+ |//> using platform scala-native
138
+ |//> using nativeVersion 0.4.6
139
+ |
140
+ |//> using buildInfo
141
+ |
142
+ |import scala.cli.build.BuildInfo
143
+ |
144
+ |object Main extends App {
145
+ | println(s"Scala version: $$ {BuildInfo.scalaVersion}")
146
+ | BuildInfo.MainScopeInfo.customJarsDecls.foreach(println)
147
+ |}
148
+ | """ .stripMargin
149
+ )
150
+
151
+ inputs.withBuild(baseOptions, buildThreads, bloopConfigOpt) {
152
+ (root, _, maybeBuild) =>
153
+ expect(maybeBuild.orThrow.success)
154
+ val projectDir = os.list(root / " .scala-build" ).filter(
155
+ _.baseName.startsWith(root.baseName + " _" )
156
+ )
157
+ expect(projectDir.size == 1 )
158
+ val buildInfoPath = projectDir.head / " src_generated" / " main" / " BuildInfo.scala"
159
+ expect(os.isFile(buildInfoPath))
160
+
161
+ val buildInfoContent = os.read(buildInfoPath)
162
+
163
+ expect(normalizeResolvers(buildInfoContent) ==
164
+ s """ package scala.cli.build
165
+ |
166
+ |object BuildInfo {
167
+ | val scalaVersion = "3.2.2"
168
+ | val platform = "Native"
169
+ | val jvmVersion = None
170
+ | val scalaJsVersion = None
171
+ | val jsEsVersion = None
172
+ | val scalaNativeVersion = Some("0.4.6")
173
+ | val mainClass = Some("Main")
174
+ |
175
+ |
176
+ | object MainScopeInfo {
177
+ | val sources = Seq(" ${root / " main.scala" }")
178
+ | val scalacOptions = Seq("-Xasync")
179
+ | val scalaCompilerPlugins = Seq("org.wartremover:wartremover_3.2.2:3.0.9")
180
+ | val dependencies = Seq("com.lihaoyi:os-lib_3:0.9.1")
181
+ | val resolvers = Seq("ivy:file:.../scala-cli-tests-extra-repo/local-repo/...", "https://repo1.maven.org/maven2", "ivy:file:.../.ivy2/local/")
182
+ | val resourceDirs = Seq(" ${root / " resources" }")
183
+ | val customJarsDecls = Seq(" ${root / " TEST1.jar" }", " ${root / " TEST2.jar" }")
184
+ | }
185
+ |
186
+ | object TestScopeInfo {
187
+ | val sources = Nil
188
+ | val scalacOptions = Nil
189
+ | val scalaCompilerPlugins = Nil
190
+ | val dependencies = Nil
191
+ | val resolvers = Nil
192
+ | val resourceDirs = Nil
193
+ | val customJarsDecls = Nil
194
+ | }
195
+ |
196
+ |}
197
+ | """ .stripMargin)
198
+ }
199
+ }
200
+
201
+ test(s " BuildInfo for js " ) {
43
202
val inputs = TestInputs (
44
203
os.rel / " main.scala" ->
45
204
s """ //> using dep "com.lihaoyi::os-lib:0.9.1"
@@ -50,6 +209,9 @@ class SourceGeneratorTests extends munit.FunSuite {
50
209
|//> using mainClass "Main"
51
210
|//> using resourceDir ./resources
52
211
|//> using jar TEST1.jar TEST2.jar
212
+ |//> using platform scala-js
213
+ |//> using jsVersion 1.13.1
214
+ |//> using jsEsVersionStr es2015
53
215
|
54
216
|//> using buildInfo
55
217
|
@@ -74,21 +236,41 @@ class SourceGeneratorTests extends munit.FunSuite {
74
236
75
237
val buildInfoContent = os.read(buildInfoPath)
76
238
77
- expect(buildInfoContent.contains(" val scalaVersion = \" 3.2.2\" " ))
78
- expect(buildInfoContent.contains(" val platform = \" JVM\" " ))
79
- expect(buildInfoContent.contains(" val jvmVersion = Some(\" 11\" )" ))
80
- expect(buildInfoContent.contains(" val mainClass = Some(\" Main\" )" ))
81
- expect(buildInfoContent.contains(s " val sources = Seq( \" ${root / " main.scala" }\" ) " ))
82
- expect(buildInfoContent.contains(
83
- " val scalaCompilerPlugins = Seq(\" org.wartremover:wartremover_3.2.2:3.0.9\" )"
84
- ))
85
- expect(buildInfoContent.contains(" val scalacOptions = Seq(\" -Xasync\" )" ))
86
- expect(buildInfoContent.contains(" val dependencies = Seq(\" com.lihaoyi:os-lib_3:0.9.1\" )" ))
87
- expect(buildInfoContent.contains(" val resolvers = Seq(\" ivy:" ))
88
- expect(buildInfoContent.contains(s " val resourceDirs = Seq( \" ${root / " resources" }\" ) " ))
89
- expect(buildInfoContent.contains(
90
- s " val customJarsDecls = Seq( \" ${root / " TEST1.jar" }\" , \" ${root / " TEST2.jar" }\" ) "
91
- ))
239
+ expect(normalizeResolvers(buildInfoContent) ==
240
+ s """ package scala.cli.build
241
+ |
242
+ |object BuildInfo {
243
+ | val scalaVersion = "3.2.2"
244
+ | val platform = "JS"
245
+ | val jvmVersion = None
246
+ | val scalaJsVersion = Some("1.13.1")
247
+ | val jsEsVersion = Some("es2015")
248
+ | val scalaNativeVersion = None
249
+ | val mainClass = Some("Main")
250
+ |
251
+ |
252
+ | object MainScopeInfo {
253
+ | val sources = Seq(" ${root / " main.scala" }")
254
+ | val scalacOptions = Seq("-Xasync")
255
+ | val scalaCompilerPlugins = Seq("org.wartremover:wartremover_3.2.2:3.0.9")
256
+ | val dependencies = Seq("com.lihaoyi:os-lib_3:0.9.1")
257
+ | val resolvers = Seq("ivy:file:.../scala-cli-tests-extra-repo/local-repo/...", "https://repo1.maven.org/maven2", "ivy:file:.../.ivy2/local/")
258
+ | val resourceDirs = Seq(" ${root / " resources" }")
259
+ | val customJarsDecls = Seq(" ${root / " TEST1.jar" }", " ${root / " TEST2.jar" }")
260
+ | }
261
+ |
262
+ | object TestScopeInfo {
263
+ | val sources = Nil
264
+ | val scalacOptions = Nil
265
+ | val scalaCompilerPlugins = Nil
266
+ | val dependencies = Nil
267
+ | val resolvers = Nil
268
+ | val resourceDirs = Nil
269
+ | val customJarsDecls = Nil
270
+ | }
271
+ |
272
+ |}
273
+ | """ .stripMargin)
92
274
}
93
275
}
94
276
}
0 commit comments