@@ -3,6 +3,7 @@ package scala.build.tests
3
3
import com .eed3si9n .expecty .Expecty .expect
4
4
5
5
import java .io .IOException
6
+ import scala .Console .println
6
7
import scala .build .Ops .EitherThrowOps
7
8
import scala .build .errors .ToolkitDirectiveMissingVersionError
8
9
import scala .build .options .{
@@ -50,6 +51,27 @@ class SourceGeneratorTests extends munit.FunSuite {
50
51
" ivy:file:.../.ivy2/local/"
51
52
)
52
53
54
+ def initializeGit (
55
+ cwd : os.Path ,
56
+ tag : String = " test-inputs" ,
57
+ gitUserName : String = " testUser" ,
58
+ gitUserEmail :
String = " [email protected] "
59
+ ): Unit = {
60
+ println(s " Initializing git in $cwd... " )
61
+ os.proc(" git" , " init" ).call(cwd = cwd)
62
+ println(s " Setting git user.name to $gitUserName" )
63
+ os.proc(" git" , " config" , " --local" , " user.name" , gitUserName).call(cwd = cwd)
64
+ println(s " Setting git user.email to $gitUserEmail" )
65
+ os.proc(" git" , " config" , " --local" , " user.email" , gitUserEmail).call(cwd = cwd)
66
+ println(s " Adding $cwd to git... " )
67
+ os.proc(" git" , " add" , " ." ).call(cwd = cwd)
68
+ println(s " Doing an initial commit... " )
69
+ os.proc(" git" , " commit" , " -m" , " git init test inputs" ).call(cwd = cwd)
70
+ println(s " Tagging as $tag... " )
71
+ os.proc(" git" , " tag" , tag).call(cwd = cwd)
72
+ println(s " Git initialized at $cwd" )
73
+ }
74
+
53
75
test(s " BuildInfo source generated " ) {
54
76
val inputs = TestInputs (
55
77
os.rel / " main.scala" ->
@@ -73,54 +95,61 @@ class SourceGeneratorTests extends munit.FunSuite {
73
95
|""" .stripMargin
74
96
)
75
97
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))
98
+ inputs.fromRoot { root =>
99
+ initializeGit(root, " v1.0.0" )
85
100
86
- val buildInfoContent = os.read(buildInfoPath)
101
+ inputs.copy(forceCwd = Some (root))
102
+ .withBuild(baseOptions, buildThreads, bloopConfigOpt, skipCreatingSources = true ) {
103
+ (root, _, maybeBuild) =>
104
+ expect(maybeBuild.orThrow.success)
105
+ val projectDir = os.list(root / " .scala-build" ).filter(
106
+ _.baseName.startsWith(root.baseName + " _" )
107
+ )
108
+ expect(projectDir.size == 1 )
109
+ val buildInfoPath = projectDir.head / " src_generated" / " main" / " BuildInfo.scala"
110
+ expect(os.isFile(buildInfoPath))
87
111
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 Main {
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 Test {
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)
112
+ val buildInfoContent = os.read(buildInfoPath)
113
+
114
+ expect(normalizeResolvers(buildInfoContent) ==
115
+ s """ package scala.cli.build
116
+ |
117
+ |object BuildInfo {
118
+ | val scalaVersion = "3.2.2"
119
+ | val platform = "JVM"
120
+ | val jvmVersion = Some("11")
121
+ | val scalaJsVersion = None
122
+ | val jsEsVersion = None
123
+ | val scalaNativeVersion = None
124
+ | val mainClass = Some("Main")
125
+ | val projectVersion = Some("1.0.0")
126
+ |
127
+ |
128
+ | object Main {
129
+ | val sources = Seq(" ${root / " main.scala" }")
130
+ | val scalacOptions = Seq("-Xasync")
131
+ | val scalaCompilerPlugins = Seq("org.wartremover:wartremover_3.2.2:3.0.9")
132
+ | val dependencies = Seq("com.lihaoyi:os-lib_3:0.9.1")
133
+ | val resolvers = Seq("ivy:file:.../scala-cli-tests-extra-repo/local-repo/...", "https://repo1.maven.org/maven2", "ivy:file:.../.ivy2/local/")
134
+ | val resourceDirs = Seq(" ${root / " resources" }")
135
+ | val customJarsDecls = Seq(" ${root / " TEST1.jar" }", " ${root / " TEST2.jar" }")
136
+ | }
137
+ |
138
+ | object Test {
139
+ | val sources = Nil
140
+ | val scalacOptions = Nil
141
+ | val scalaCompilerPlugins = Nil
142
+ | val dependencies = Nil
143
+ | val resolvers = Nil
144
+ | val resourceDirs = Nil
145
+ | val customJarsDecls = Nil
146
+ | }
147
+ |
148
+ |}
149
+ | """ .stripMargin)
150
+ }
123
151
}
152
+
124
153
}
125
154
126
155
test(s " BuildInfo for native " ) {
@@ -171,6 +200,7 @@ class SourceGeneratorTests extends munit.FunSuite {
171
200
| val jsEsVersion = None
172
201
| val scalaNativeVersion = Some("0.4.6")
173
202
| val mainClass = Some("Main")
203
+ | val projectVersion = None
174
204
|
175
205
|
176
206
| object Main {
@@ -212,6 +242,7 @@ class SourceGeneratorTests extends munit.FunSuite {
212
242
|//> using platform scala-js
213
243
|//> using jsVersion 1.13.1
214
244
|//> using jsEsVersionStr es2015
245
+ |//> using computeVersion "command:echo TestVersion"
215
246
|
216
247
|//> using buildInfo
217
248
|
@@ -247,6 +278,7 @@ class SourceGeneratorTests extends munit.FunSuite {
247
278
| val jsEsVersion = Some("es2015")
248
279
| val scalaNativeVersion = None
249
280
| val mainClass = Some("Main")
281
+ | val projectVersion = Some("TestVersion")
250
282
|
251
283
|
252
284
| object Main {
@@ -285,6 +317,7 @@ class SourceGeneratorTests extends munit.FunSuite {
285
317
|//> using mainClass "Main"
286
318
|//> using resourceDir ./resources
287
319
|//> using jar TEST1.jar TEST2.jar
320
+ |//> using computeVersion "command:echo TestVersion"
288
321
|
289
322
|//> using buildInfo
290
323
|
@@ -320,6 +353,7 @@ class SourceGeneratorTests extends munit.FunSuite {
320
353
| val jsEsVersion = None
321
354
| val scalaNativeVersion = None
322
355
| val mainClass = Some("Main")
356
+ | val projectVersion = Some("TestVersion")
323
357
|
324
358
|
325
359
| object Main {
0 commit comments