@@ -21,15 +21,14 @@ class SettingsTests {
2121 assertEquals(1 , reporter.errorCount)
2222 assertEquals(" 'not_here' does not exist or is not a directory or .jar file" , reporter.allErrors.head.message)
2323
24- @ Test def jarOutput : Unit = {
24+ @ Test def jarOutput : Unit =
2525 val source = " tests/pos/Foo.scala"
2626 val out = Paths .get(" out/jaredFoo.jar" ).normalize
2727 if (Files .exists(out)) Files .delete(out)
2828 val options = Array (" -classpath" , TestConfiguration .basicClasspath, " -d" , out.toString, source)
2929 val reporter = Main .process(options)
3030 assertEquals(0 , reporter.errorCount)
3131 assertTrue(Files .exists(out))
32- }
3332
3433 @ Test def `t8124 Don't crash on missing argument` : Unit =
3534 val source = Paths .get(" tests/pos/Foo.scala" ).normalize
@@ -45,15 +44,70 @@ class SettingsTests {
4544 val foo = StringSetting (" -foo" , " foo" , " Foo" , " a" )
4645 val bar = IntSetting (" -bar" , " Bar" , 0 )
4746
48- inContext {
49- val args = List (" -foo" , " b" , " -bar" , " 1" )
50- val summary = Settings .processArguments(args, true )
51- assertTrue(summary.errors.isEmpty)
52- given SettingsState = summary.sstate
47+ val args = List (" -foo" , " b" , " -bar" , " 1" )
48+ val summary = Settings .processArguments(args, true )
49+ assertTrue(summary.errors.isEmpty)
50+ withProcessedArgs(summary) {
5351 assertEquals(" b" , Settings .foo.value)
5452 assertEquals(1 , Settings .bar.value)
5553 }
5654
55+ @ Test def `workaround dont crash on many files` : Unit =
56+ object Settings extends SettingGroup
57+
58+ val args = " --" :: List .fill(6000 )(" file.scala" )
59+ val summary = Settings .processArguments(args, processAll = true )
60+ assertTrue(summary.errors.isEmpty)
61+ assertEquals(6000 , summary.arguments.size)
62+
63+ @ Test def `dont crash on many files` : Unit =
64+ object Settings extends SettingGroup
65+
66+ val args = List .fill(6000 )(" file.scala" )
67+ val summary = Settings .processArguments(args, processAll = true )
68+ assertTrue(summary.errors.isEmpty)
69+ assertEquals(6000 , summary.arguments.size)
70+
71+ @ Test def `dont crash on many options` : Unit =
72+ object Settings extends SettingGroup :
73+ val option = BooleanSetting (" -option" , " Some option" )
74+
75+ val limit = 6000
76+ val args = List .fill(limit)(" -option" )
77+ val summary = Settings .processArguments(args, processAll = true )
78+ assertTrue(summary.errors.isEmpty)
79+ assertEquals(limit- 1 , summary.warnings.size)
80+ assertTrue(summary.warnings.head.contains(" repeatedly" ))
81+ assertEquals(0 , summary.arguments.size)
82+ withProcessedArgs(summary) {
83+ assertTrue(Settings .option.value)
84+ }
85+
86+ @ Test def `bad option warning consumes an arg` : Unit =
87+ object Settings extends SettingGroup :
88+ val option = BooleanSetting (" -option" , " Some option" )
89+
90+ val args = List (" -adoption" , " dogs" , " cats" )
91+ val summary = Settings .processArguments(args, processAll = true )
92+ assertTrue(summary.errors.isEmpty)
93+ assertFalse(summary.warnings.isEmpty)
94+ assertEquals(2 , summary.arguments.size)
95+
96+ @ Test def `bad option settings throws` : Unit =
97+ object Settings extends SettingGroup :
98+ val option = BooleanSetting (" -option" , " Some option" )
99+
100+ def checkMessage (s : String ): (Throwable => Boolean ) = t =>
101+ if t.getMessage == s then true
102+ else
103+ println(s " Expected: $s, Actual: ${t.getMessage}" )
104+ false
105+
106+ val default = Settings .defaultState
107+ assertThrows[IllegalArgumentException ](checkMessage(" found: not an option of type java.lang.String, required: Boolean" )) {
108+ Settings .option.updateIn(default, " not an option" )
109+ }
110+
57111 @ Test def validateChoices : Unit =
58112 object Settings extends SettingGroup :
59113 val foo = ChoiceSetting (" -foo" , " foo" , " Foo" , List (" a" , " b" ), " a" )
@@ -63,25 +117,27 @@ class SettingsTests {
63117 val quux = ChoiceSetting (" -quux" , " quux" , " Quux" , List (), " " )
64118 val quuz = IntChoiceSetting (" -quuz" , " Quuz" , List (), 0 )
65119
66- inContext {
120+ locally {
67121 val args = List (" -foo" , " b" , " -bar" , " 1" , " -baz" , " 5" )
68122 val summary = Settings .processArguments(args, true )
69123 assertTrue(summary.errors.isEmpty)
70- given SettingsState = summary.sstate
71- assertEquals(" b" , Settings .foo.value)
72- assertEquals(1 , Settings .bar.value)
73- assertEquals(5 , Settings .baz.value)
124+ withProcessedArgs(summary) {
125+ assertEquals(" b" , Settings .foo.value)
126+ assertEquals(1 , Settings .bar.value)
127+ assertEquals(5 , Settings .baz.value)
128+ }
74129 }
75130
76- inContext {
131+ locally {
77132 val args = List (" -foo:b" )
78133 val summary = Settings .processArguments(args, true )
79134 assertTrue(summary.errors.isEmpty)
80- given SettingsState = summary.sstate
81- assertEquals(" b" , Settings .foo.value)
135+ withProcessedArgs(summary) {
136+ assertEquals(" b" , Settings .foo.value)
137+ }
82138 }
83139
84- inContext {
140+ locally {
85141 val args = List (" -foo" , " c" , " -bar" , " 3" , " -baz" , " -1" )
86142 val summary = Settings .processArguments(args, true )
87143 val expectedErrors = List (
@@ -92,14 +148,14 @@ class SettingsTests {
92148 assertEquals(expectedErrors, summary.errors)
93149 }
94150
95- inContext {
151+ locally {
96152 val args = List (" -foo:c" )
97153 val summary = Settings .processArguments(args, true )
98154 val expectedErrors = List (" c is not a valid choice for -foo" )
99155 assertEquals(expectedErrors, summary.errors)
100156 }
101157
102- inContext {
158+ locally {
103159 val args = List (" -quux" , " a" , " -quuz" , " 0" )
104160 val summary = Settings .processArguments(args, true )
105161 val expectedErrors = List (
@@ -109,7 +165,7 @@ class SettingsTests {
109165 assertEquals(expectedErrors, summary.errors)
110166 }
111167
112- private def inContext ( f : Context ?=> Unit ) = f(using ( new ContextBase ).initialCtx.fresh )
168+ private def withProcessedArgs ( summary : ArgsSummary )( f : SettingsState ?=> Unit ) = f(using summary.sstate )
113169
114170 extension [T ](setting : Setting [T ])
115171 private def value (using ss : SettingsState ): T = setting.valueIn(ss)
0 commit comments