-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support src filter in -WConf (Closes #17635) #18783
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,11 @@ import Settings._ | |
import org.junit.Test | ||
import org.junit.Assert._ | ||
import core.Decorators.toMessage | ||
import dotty.tools.io.{Path, PlainFile} | ||
|
||
import java.net.URI | ||
import java.nio.file.Files | ||
import scala.util.Using | ||
|
||
class ScalaSettingsTests: | ||
|
||
|
@@ -96,5 +101,100 @@ class ScalaSettingsTests: | |
assertEquals(Action.Silent, sut.action(depr)) | ||
|
||
|
||
private def wconfSrcFilterTest(argsStr: String, | ||
warning: reporting.Diagnostic.Warning): Either[List[String], reporting.Action] = | ||
import reporting.Diagnostic | ||
val settings = new ScalaSettings | ||
val args = ArgsSummary(settings.defaultState, List(argsStr), errors = Nil, warnings = Nil) | ||
val proc = settings.processArguments(args, processAll = true, skipped = Nil) | ||
val wconfStr = settings.Wconf.valueIn(proc.sstate) | ||
val wconf = reporting.WConf.fromSettings(wconfStr) | ||
wconf.map(_.action(warning)) | ||
|
||
@Test def `WConf src filter silences warnings from a matching path for virtual file`: Unit = | ||
val result = wconfSrcFilterTest( | ||
argsStr = "-Wconf:src=path/.*:s", | ||
warning = reporting.Diagnostic.Warning( | ||
"A warning".toMessage, | ||
util.SourcePosition( | ||
source = util.SourceFile.virtual(new URI("file:///some/path/file.scala"), ""), | ||
span = util.Spans.Span(1L) | ||
) | ||
) | ||
) | ||
assertEquals(result, Right(reporting.Action.Silent)) | ||
|
||
@Test def `WConf src filter doesn't silence warnings from a non-matching path`: Unit = | ||
val result = wconfSrcFilterTest( | ||
argsStr = "-Wconf:src=another/.*:s", | ||
warning = reporting.Diagnostic.Warning( | ||
"A warning".toMessage, | ||
util.SourcePosition( | ||
source = util.SourceFile.virtual(new URI("file:///some/path/file.scala"), ""), | ||
span = util.Spans.Span(1L) | ||
) | ||
) | ||
) | ||
assertEquals(result, Right(reporting.Action.Warning)) | ||
|
||
@Test def `WConf src filter silences warnings from a matching path for real file`: Unit = | ||
val result = Using.resource(Files.createTempFile("myfile", ".scala").nn) { file => | ||
wconfSrcFilterTest( | ||
argsStr = "-Wconf:src=myfile.*?\\.scala:s", | ||
warning = reporting.Diagnostic.Warning( | ||
"A warning".toMessage, | ||
util.SourcePosition( | ||
source = util.SourceFile(new PlainFile(Path(file)), "UTF-8"), | ||
span = util.Spans.Span(1L) | ||
) | ||
) | ||
) | ||
}(Files.deleteIfExists(_)) | ||
assertEquals(result, Right(reporting.Action.Silent)) | ||
|
||
@Test def `WConf src filter doesn't silence warnings from a non-matching path for real file`: Unit = | ||
val result = Using.resource(Files.createTempFile("myfile", ".scala").nn) { file => | ||
wconfSrcFilterTest( | ||
argsStr = "-Wconf:src=another.*?\\.scala:s", | ||
warning = reporting.Diagnostic.Warning( | ||
"A warning".toMessage, | ||
util.SourcePosition( | ||
source = util.SourceFile(new PlainFile(Path(file)), "UTF-8"), | ||
span = util.Spans.Span(1L) | ||
) | ||
) | ||
) | ||
}(Files.deleteIfExists(_)) | ||
assertEquals(result, Right(reporting.Action.Warning)) | ||
|
||
@Test def `WConf src filter reports an error on an invalid regex`: Unit = | ||
val result = wconfSrcFilterTest( | ||
argsStr = """-Wconf:src=\:s""", | ||
warning = reporting.Diagnostic.Warning( | ||
"A warning".toMessage, | ||
util.SourcePosition( | ||
source = util.SourceFile.virtual(new URI("file:///some/path/file.scala"), ""), | ||
span = util.Spans.Span(1L) | ||
) | ||
), | ||
) | ||
assertTrue( | ||
result.left.exists(errors => | ||
errors.sizeIs == 1 && errors.headOption.exists(_.startsWith("invalid pattern")) | ||
) | ||
) | ||
|
||
@Test def `WConf src filter can be mixed with other filters with rightmost taking precedence`: Unit = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, in Scala 2 the leftmost takes precedence. Also So this is a bug that should be fixed. I think a separate PR is better, so I filed #19885. |
||
val result = wconfSrcFilterTest( | ||
argsStr = "-Wconf:src=.*:s,cat=deprecation:e", | ||
warning = reporting.Diagnostic.DeprecationWarning( | ||
"A warning".toMessage, | ||
util.SourcePosition( | ||
source = util.SourceFile.virtual(new URI("file:///some/path/file.scala"), ""), | ||
span = util.Spans.Span(1L) | ||
) | ||
) | ||
) | ||
assertEquals(result, Right(reporting.Action.Error)) | ||
|
||
end ScalaSettingsTests |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old code had a cache, shouldn't that be provided too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache added