@@ -7,6 +7,11 @@ import Settings._
7
7
import org .junit .Test
8
8
import org .junit .Assert ._
9
9
import core .Decorators .toMessage
10
+ import dotty .tools .io .{Path , PlainFile }
11
+
12
+ import java .net .URI
13
+ import java .nio .file .Files
14
+ import scala .util .Using
10
15
11
16
class ScalaSettingsTests :
12
17
@@ -96,5 +101,61 @@ class ScalaSettingsTests:
96
101
assertEquals(Action .Silent , sut.action(depr))
97
102
98
103
104
+ private def wconfSrcFilterTest (argsStr : String , source : util.SourceFile , expectedAction : reporting.Action ): Unit =
105
+ import reporting .Diagnostic
106
+ val settings = new ScalaSettings
107
+ val args = ArgsSummary (settings.defaultState, List (argsStr), errors = Nil , warnings = Nil )
108
+ val proc = settings.processArguments(args, processAll = true , skipped = Nil )
109
+ val wconfStr = settings.Wconf .valueIn(proc.sstate)
110
+ val warning = new Diagnostic .Warning (
111
+ " A warning" .toMessage,
112
+ util.SourcePosition (
113
+ source = source,
114
+ span = util.Spans .Span (1L )
115
+ )
116
+ )
117
+ val wconf = reporting.WConf .fromSettings(wconfStr)
118
+ assertEquals(Right (expectedAction), wconf.map(_.action(warning)))
119
+
120
+ @ Test def `WConf src filter silences warnings from a matching path for virtual file` : Unit =
121
+ wconfSrcFilterTest(
122
+ argsStr = " -Wconf:src=path/.*:s" ,
123
+ source = util.SourceFile .virtual(new URI (" file:///some/path/file.scala" ), " " ),
124
+ expectedAction = reporting.Action .Silent
125
+ )
126
+
127
+ @ Test def `WConf src filter doesn't silence warnings from a non-matching path` : Unit =
128
+ wconfSrcFilterTest(
129
+ argsStr = " -Wconf:src=another/.*:s" ,
130
+ source = util.SourceFile .virtual(new URI (" file:///some/path/file.scala" ), " " ),
131
+ expectedAction = reporting.Action .Warning
132
+ )
133
+
134
+ @ Test def `WConf src filter silences warnings from a matching path for real file` : Unit =
135
+ Using .resource(Files .createTempFile(" myfile" , " .scala" ).nn) { file =>
136
+ wconfSrcFilterTest(
137
+ argsStr = " -Wconf:src=myfile.*?\\ .scala:s" ,
138
+ source = util.SourceFile (new PlainFile (Path (file)), " UTF-8" ),
139
+ expectedAction = reporting.Action .Silent
140
+ )
141
+ }(Files .deleteIfExists(_))
142
+
143
+ @ Test def `WConf src filter doesn't silence warnings from a non-matching path for real file` : Unit =
144
+ Using .resource(Files .createTempFile(" myfile" , " .scala" ).nn) { file =>
145
+ wconfSrcFilterTest(
146
+ argsStr = " -Wconf:src=another.*?\\ .scala:s" ,
147
+ source = util.SourceFile (new PlainFile (Path (file)), " UTF-8" ),
148
+ expectedAction = reporting.Action .Warning
149
+ )
150
+ }(Files .deleteIfExists(_))
151
+
152
+ @ Test def `WConf src filter works when cache is not empty` : Unit =
153
+ (0 to 1 ).foreach { _ =>
154
+ wconfSrcFilterTest(
155
+ argsStr = " -Wconf:src=path/.*:s" ,
156
+ source = util.SourceFile .virtual(new URI (" file:///some/path/file.scala" ), " " ),
157
+ expectedAction = reporting.Action .Silent
158
+ )
159
+ }
99
160
100
161
end ScalaSettingsTests
0 commit comments