Skip to content

Commit 9af7daa

Browse files
committed
Add tests that verify parsing and output behaviour
1 parent a73a40d commit 9af7daa

File tree

3 files changed

+145
-20
lines changed

3 files changed

+145
-20
lines changed

Diff for: compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+10-9
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ private sealed trait XSettings:
340340
val XdebugMacros: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xdebug-macros", "Show debug info when quote pattern match fails")
341341

342342
/** Pipeline compilation options */
343-
val XjavaTasty: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xjava-tasty", "Pickler phase should compute TASTy for .java defined symbols for use by build tools", aliases = List("-Xpickle-java"), preferPrevious = true)
344-
val XearlyTastyOutput: Setting[AbstractFile] = OutputSetting(AdvancedSetting, "Xearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Xpickle-write"), preferPrevious = true)
345-
val XallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.")
343+
val XjavaTasty: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xjava-tasty", "Pickler phase should compute TASTy for .java defined symbols for use by build tools", aliases = List("-Xpickle-java", "-Yjava-tasty", "-Ypickle-java"), preferPrevious = true)
344+
val XearlyTastyOutput: Setting[AbstractFile] = OutputSetting(AdvancedSetting, "Xearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Xpickle-write", "-Yearly-tasty-output", "-Ypickle-write"), preferPrevious = true)
345+
val XallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.", aliases = List("-Yallow-outline-from-tasty"))
346346

347347
val XmixinForceForwarders = ChoiceSetting(
348348
AdvancedSetting,
@@ -490,12 +490,13 @@ private sealed trait YSettings:
490490
val YnoEnrichErrorMessages: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-enrich-error-messages", "Show raw error messages, instead of enriching them with contextual information.", deprecation = Some(Deprecation("Use -Xno-enrich-error-messages instead.", "-Xno-enrich-error-messages")))
491491
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
492492
val YdebugMacros: Setting[Boolean] = BooleanSetting(ForkSetting, "Ydebug-macros", "Show debug info when quote pattern match fails", deprecation = Some(Deprecation("Use -Xdebug-macros instead.", "-Xdebug-macros")))
493-
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
494-
val YjavaTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yjava-tasty", "Pickler phase should compute TASTy for .java defined symbols for use by build tools", aliases = List("-Ypickle-java"), preferPrevious = true, deprecation = Some(Deprecation("Use -Xjava-tasty instead.", "-Xjava-tasty")))
495-
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
496-
val YearlyTastyOutput: Setting[AbstractFile] = OutputSetting(ForkSetting, "Yearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Ypickle-write"), preferPrevious = true, deprecation = Some(Deprecation("Use -Xearly-tasty-output instead.", "-Xearly-tasty-output")))
497-
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
498-
val YallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.", deprecation = Some(Deprecation("Use -Xallow-outline-from-tasty instead.", "-Xallow-outline-from-tasty")))
493+
494+
// @deprecated(message = "Lifted to -X, Scheduled for removal in 3.8.0", since = "3.7.0")
495+
// val YjavaTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yjava-tasty", "Pickler phase should compute TASTy for .java defined symbols for use by build tools", aliases = List("-Ypickle-java"), preferPrevious = true, deprecation = Some(Deprecation("Use -Xjava-tasty instead.", "-Xjava-tasty")))
496+
// @deprecated(message = "Lifted to -X, Scheduled for removal in 3.8.0", since = "3.7.0")
497+
// val YearlyTastyOutput: Setting[AbstractFile] = OutputSetting(ForkSetting, "Yearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Ypickle-write"), preferPrevious = true, deprecation = Some(Deprecation("Use -Xearly-tasty-output instead.", "-Xearly-tasty-output")))
498+
// @deprecated(message = "Lifted to -X, Scheduled for removal in 3.8.0", since = "3.7.0")
499+
// val YallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.", deprecation = Some(Deprecation("Use -Xallow-outline-from-tasty instead.", "-Xallow-outline-from-tasty")))
499500

500501
// Deprecated: lifted from -Y to -W
501502
@deprecated(message = "Lifted to -W, Scheduled for removal in 3.6.0", since = "3.5.0")

Diff for: compiler/test/dotty/tools/dotc/SettingsTests.scala

+126-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ import reporting.StoreReporter
77
import vulpix.TestConfiguration
88

99
import core.Contexts.{Context, ContextBase}
10-
import dotty.tools.dotc.config.Settings._
11-
import dotty.tools.dotc.config.ScalaSettingCategories._
10+
import dotty.tools.dotc.config.Settings.*
11+
import dotty.tools.dotc.config.Settings.Setting.ChoiceWithHelp
12+
import dotty.tools.dotc.config.ScalaSettingCategories.*
1213
import dotty.tools.vulpix.TestConfiguration.mkClasspath
14+
import dotty.tools.io.PlainDirectory
15+
import dotty.tools.io.Directory
16+
import dotty.tools.dotc.config.ScalaVersion
1317

1418
import java.nio.file._
1519

1620
import org.junit.Test
1721
import org.junit.Assert._
22+
import scala.util.Using
1823

1924
class SettingsTests {
2025

@@ -199,6 +204,125 @@ class SettingsTests {
199204
assertEquals(List("Flag -qux set repeatedly"), summary.warnings)
200205
}
201206

207+
@Test def `Output setting is overriding existing jar`: Unit =
208+
val result = Using.resource(Files.createTempFile("myfile", ".jar").nn){ file =>
209+
object Settings extends SettingGroup:
210+
val defaultDir = new PlainDirectory(Directory("."))
211+
val testOutput = OutputSetting(RootSetting, "testOutput", "testOutput", "", defaultDir)
212+
213+
import Settings._
214+
215+
val creationTime = Files.getLastModifiedTime(file)
216+
val args = List(s"-testOutput:${file.toString}")
217+
val summary = processArguments(args, processAll = true)
218+
219+
val creationTimeAfterProcessing = Files.getLastModifiedTime(file)
220+
221+
assert(creationTimeAfterProcessing.toMillis > creationTime.toMillis, "Jar should have been overriden")
222+
223+
}(Files.deleteIfExists(_))
224+
225+
@Test def `Output setting is respecting previous setting`: Unit =
226+
val result = Using.resources(
227+
Files.createTempFile("myfile", ".jar").nn, Files.createTempFile("myfile2", ".jar").nn
228+
){ (file1, file2) =>
229+
object Settings extends SettingGroup:
230+
val defaultDir = new PlainDirectory(Directory("."))
231+
val testOutput = OutputSetting(RootSetting, "testOutput", "testOutput", "", defaultDir, preferPrevious = true)
232+
233+
import Settings._
234+
235+
Files.writeString(file1, "test1")
236+
Files.writeString(file2, "test2")
237+
238+
val file1StateBefore = Files.readString(file1)
239+
val file2StateBefore = Files.readString(file2)
240+
241+
val creationTime = Files.getLastModifiedTime(file1)
242+
val args = List(s"-testOutput:${file1.toString}", s"-testOutput:${file2.toString}")
243+
val summary = processArguments(args, processAll = true)
244+
245+
// The output is a new filesystem without information of original path
246+
// We can't check the `testOutput.value` as in other tests.
247+
assertNotEquals(file1StateBefore, Files.readString(file1))
248+
assertEquals(file2StateBefore, Files.readString(file2))
249+
250+
}(Files.deleteIfExists(_), Files.deleteIfExists(_))
251+
252+
@Test def `Output side effect is not present when setting is deprecated`: Unit =
253+
val result = Using.resource(Files.createTempFile("myfile", ".jar").nn){ file =>
254+
object Settings extends SettingGroup:
255+
val defaultDir = new PlainDirectory(Directory("."))
256+
val testOutput = OutputSetting(RootSetting, "testOutput", "testOutput", "", defaultDir, preferPrevious = true, deprecation = Some(Deprecation("deprecated", "XtestOutput")))
257+
258+
import Settings._
259+
260+
val creationTime = Files.getLastModifiedTime(file)
261+
val args = List(s"-testOutput:${file.toString}")
262+
val summary = processArguments(args, processAll = true)
263+
264+
val creationTimeAfterProcessing = Files.getLastModifiedTime(file)
265+
266+
assertEquals(creationTimeAfterProcessing, creationTime)
267+
268+
}(Files.deleteIfExists(_))
269+
270+
@Test def `Arguments of flags are correctly parsed with both ":" and " " separating`: Unit =
271+
object Settings extends SettingGroup:
272+
val booleanSetting = BooleanSetting(RootSetting, "booleanSetting", "booleanSetting", false)
273+
val stringSetting = StringSetting(RootSetting, "stringSetting", "stringSetting", "", "test")
274+
val choiceSetting = ChoiceSetting(RootSetting, "choiceSetting", "choiceSetting", "", List("a", "b"), "a")
275+
val multiChoiceSetting= MultiChoiceSetting(RootSetting, "multiChoiceSetting", "multiChoiceSetting", "", List("a", "b"), List())
276+
val multiChoiceHelpSetting= MultiChoiceHelpSetting(RootSetting, "multiChoiceHelpSetting", "multiChoiceHelpSetting", "", List(ChoiceWithHelp("a", "a"), ChoiceWithHelp("b", "b")), List())
277+
val intSetting = IntSetting(RootSetting, "intSetting", "intSetting", 0)
278+
val intChoiceSetting = IntChoiceSetting(RootSetting, "intChoiceSetting", "intChoiceSetting", List(1,2,3), 1)
279+
val multiStringSetting = MultiStringSetting(RootSetting, "multiStringSetting", "multiStringSetting", "", List("a", "b"), List())
280+
val outputSetting = OutputSetting(RootSetting, "outputSetting", "outputSetting", "", new PlainDirectory(Directory(".")))
281+
val pathSetting = PathSetting(RootSetting, "pathSetting", "pathSetting", ".")
282+
val phasesSetting = PhasesSetting(RootSetting, "phasesSetting", "phasesSetting", "all")
283+
val versionSetting= VersionSetting(RootSetting, "versionSetting", "versionSetting")
284+
285+
import Settings._
286+
Using.resource(Files.createTempDirectory("testDir")) { dir =>
287+
288+
val args = List(
289+
List("-booleanSetting", "true"),
290+
List("-stringSetting", "newTest"),
291+
List("-choiceSetting", "b"),
292+
List("-multiChoiceSetting", "a,b"),
293+
List("-multiChoiceHelpSetting", "a,b"),
294+
List("-intSetting", "42"),
295+
List("-intChoiceSetting", "2"),
296+
List("-multiStringSetting", "a,b"),
297+
List("-outputSetting", dir.toString),
298+
List("-pathSetting", dir.toString),
299+
List("-phasesSetting", "parser,typer"),
300+
List("-versionSetting", "1.0.0"),
301+
)
302+
303+
def testValues(summary: ArgsSummary) =
304+
withProcessedArgs(summary) {
305+
assertEquals(true, booleanSetting.value)
306+
assertEquals("newTest", stringSetting.value)
307+
assertEquals("b", choiceSetting.value)
308+
assertEquals(List("a", "b"), multiChoiceSetting.value)
309+
assertEquals(List("a", "b"), multiChoiceHelpSetting.value)
310+
assertEquals(42, intSetting.value)
311+
assertEquals(2, intChoiceSetting.value)
312+
assertEquals(List("a", "b"), multiStringSetting.value)
313+
assertEquals(dir.toString, outputSetting.value.path)
314+
assertEquals(dir.toString, pathSetting.value)
315+
assertEquals(List("parser", "typer"), phasesSetting.value)
316+
assertEquals(ScalaVersion.parse("1.0.0").get, versionSetting.value)
317+
}
318+
319+
val summaryColon = processArguments(args.map(_.mkString(":")), processAll = true)
320+
val summaryWhitespace = processArguments(args.flatten, processAll = true)
321+
testValues(summary = summaryColon)
322+
testValues(summary = summaryWhitespace)
323+
324+
}(Files.deleteIfExists(_))
325+
202326
private def withProcessedArgs(summary: ArgsSummary)(f: SettingsState ?=> Unit) = f(using summary.sstate)
203327

204328
extension [T](setting: Setting[T])

Diff for: compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala

+9-9
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ class ScalaSettingsTests:
108108
createTestCase(settings.YnoDecodeStacktraces , settings.XnoDecodeStacktraces),
109109
createTestCase(settings.YnoEnrichErrorMessages, settings.XnoEnrichErrorMessages),
110110
createTestCase(settings.YdebugMacros , settings.XdebugMacros),
111-
createTestCase(settings.YjavaTasty , settings.XjavaTasty),
112-
createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput, ":./"),
113-
createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty),
111+
// createTestCase(settings.YjavaTasty , settings.XjavaTasty),
112+
// createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput, ":./"),
113+
// createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty),
114114
createTestCase(settings.YcheckInit , settings.WcheckInit),
115115
createTestCase(settings.Xlint , settings.Wshadow, ":all"),
116116
).map: (deprecatedArgument, newSetting) =>
@@ -137,9 +137,9 @@ class ScalaSettingsTests:
137137
createTestCase(settings.YnoDecodeStacktraces , settings.XnoDecodeStacktraces),
138138
createTestCase(settings.YnoEnrichErrorMessages, settings.XnoEnrichErrorMessages),
139139
createTestCase(settings.YdebugMacros , settings.XdebugMacros),
140-
createTestCase(settings.YjavaTasty , settings.XjavaTasty),
141-
createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput),
142-
createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty),
140+
// createTestCase(settings.YjavaTasty , settings.XjavaTasty),
141+
// createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput),
142+
// createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty),
143143
createTestCase(settings.YcheckInit , settings.WcheckInit),
144144
createTestCase(settings.Xlint , settings.Wshadow),
145145
).map: (deprecatedArgument, newSetting) =>
@@ -167,9 +167,9 @@ class ScalaSettingsTests:
167167
createTestCase(settings.YnoDecodeStacktraces , settings.XnoDecodeStacktraces),
168168
createTestCase(settings.YnoEnrichErrorMessages, settings.XnoEnrichErrorMessages),
169169
createTestCase(settings.YdebugMacros , settings.XdebugMacros),
170-
createTestCase(settings.YjavaTasty , settings.XjavaTasty),
171-
createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput, ":./"),
172-
createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty),
170+
// createTestCase(settings.YjavaTasty , settings.XjavaTasty),
171+
// createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput, ":./"),
172+
// createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty),
173173
createTestCase(settings.YcheckInit , settings.WcheckInit),
174174
createTestCase(settings.Xlint , settings.Wshadow, ":all"),
175175
).flatten.map: (deprecatedArgument, newSetting) =>

0 commit comments

Comments
 (0)