@@ -21,15 +21,14 @@ class SettingsTests {
21
21
assertEquals(1 , reporter.errorCount)
22
22
assertEquals(" 'not_here' does not exist or is not a directory or .jar file" , reporter.allErrors.head.message)
23
23
24
- @ Test def jarOutput : Unit = {
24
+ @ Test def jarOutput : Unit =
25
25
val source = " tests/pos/Foo.scala"
26
26
val out = Paths .get(" out/jaredFoo.jar" ).normalize
27
27
if (Files .exists(out)) Files .delete(out)
28
28
val options = Array (" -classpath" , TestConfiguration .basicClasspath, " -d" , out.toString, source)
29
29
val reporter = Main .process(options)
30
30
assertEquals(0 , reporter.errorCount)
31
31
assertTrue(Files .exists(out))
32
- }
33
32
34
33
@ Test def `t8124 Don't crash on missing argument` : Unit =
35
34
val source = Paths .get(" tests/pos/Foo.scala" ).normalize
@@ -45,15 +44,70 @@ class SettingsTests {
45
44
val foo = StringSetting (" -foo" , " foo" , " Foo" , " a" )
46
45
val bar = IntSetting (" -bar" , " Bar" , 0 )
47
46
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) {
53
51
assertEquals(" b" , Settings .foo.value)
54
52
assertEquals(1 , Settings .bar.value)
55
53
}
56
54
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
+
57
111
@ Test def validateChoices : Unit =
58
112
object Settings extends SettingGroup :
59
113
val foo = ChoiceSetting (" -foo" , " foo" , " Foo" , List (" a" , " b" ), " a" )
@@ -63,25 +117,27 @@ class SettingsTests {
63
117
val quux = ChoiceSetting (" -quux" , " quux" , " Quux" , List (), " " )
64
118
val quuz = IntChoiceSetting (" -quuz" , " Quuz" , List (), 0 )
65
119
66
- inContext {
120
+ locally {
67
121
val args = List (" -foo" , " b" , " -bar" , " 1" , " -baz" , " 5" )
68
122
val summary = Settings .processArguments(args, true )
69
123
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
+ }
74
129
}
75
130
76
- inContext {
131
+ locally {
77
132
val args = List (" -foo:b" )
78
133
val summary = Settings .processArguments(args, true )
79
134
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
+ }
82
138
}
83
139
84
- inContext {
140
+ locally {
85
141
val args = List (" -foo" , " c" , " -bar" , " 3" , " -baz" , " -1" )
86
142
val summary = Settings .processArguments(args, true )
87
143
val expectedErrors = List (
@@ -92,14 +148,14 @@ class SettingsTests {
92
148
assertEquals(expectedErrors, summary.errors)
93
149
}
94
150
95
- inContext {
151
+ locally {
96
152
val args = List (" -foo:c" )
97
153
val summary = Settings .processArguments(args, true )
98
154
val expectedErrors = List (" c is not a valid choice for -foo" )
99
155
assertEquals(expectedErrors, summary.errors)
100
156
}
101
157
102
- inContext {
158
+ locally {
103
159
val args = List (" -quux" , " a" , " -quuz" , " 0" )
104
160
val summary = Settings .processArguments(args, true )
105
161
val expectedErrors = List (
@@ -109,7 +165,7 @@ class SettingsTests {
109
165
assertEquals(expectedErrors, summary.errors)
110
166
}
111
167
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 )
113
169
114
170
extension [T ](setting : Setting [T ])
115
171
private def value (using ss : SettingsState ): T = setting.valueIn(ss)
0 commit comments