-
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
Report all warnings on Werror and fail at the end #18829
Conversation
26bc4ba
to
4aa8e40
Compare
still tbd: massive refactor of tests, but I want to hear if anyone has something against this solution |
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.
We need to be able to check if a line emitted a warning or not in the neg tests.
One option would be to make the test framework detect the warnings and // warn
tags to validate them as we do with // error
.
Another option would be to make the test framework interpret fatal warnings as errors.
tests/neg-deep-subtype/1828.scala
Outdated
@@ -2,10 +2,12 @@ | |||
|
|||
class Test { | |||
def remove[S](a: S | Int, f: Int => S):S = a match { | |||
case a: S => a // error | |||
case a: S => a // warn |
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.
This tag is not checked by the testing framework. This implies that this file in not testing anything. This implies that all tests that do not have a test file are broken.
We need to make sure that we check the position and number of warnings emitted under -Xfatal-warnings
/-Werror
. Our assumption when designing those tests was that we would check them as errors.
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.
Dale recently added that feature, it should be working (at least it's in Vulpix in ParallelTesting). I will make sure it works.
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.
Oh. Now I see. It won't test both
The drawback of this approach is that we might need to add more |
Move it to |
We have tests that check both warnings and errors at the same time. |
I can move most of them to warn. For the rest, I will maybe just create the output check files. |
fe5a5e2
to
71a66c4
Compare
All the tests are passing now. There are a lot of changes, but most are just simple modifications done by scripts. |
Right now one failing was added, and this branch fails after rebase. But I will fix it after the review, as broken tests keep appearing on main and I will need to fix the ones that will appear before the review is finished. |
@@ -214,6 +209,10 @@ abstract class Reporter extends interfaces.ReporterResult { | |||
def incomplete(dia: Diagnostic)(using Context): Unit = | |||
incompleteHandler(dia, ctx) | |||
|
|||
def finalizeReporting()(using Context) = | |||
if (hasWarnings && ctx.settings.XfatalWarnings.value) | |||
report(new Error("No warnings can be incurred under -Werror.", NoSourcePosition)) |
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.
report(new Error("No warnings can be incurred under -Werror.", NoSourcePosition)) | |
report(new Error("Unexpected warnings under -Werror.", NoSourcePosition)) |
@@ -216,7 +216,10 @@ class CompilationTests { | |||
@Test def checkInitGlobal: Unit = { | |||
implicit val testGroup: TestGroup = TestGroup("checkInitGlobal") | |||
val options = defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings") | |||
compileFilesInDir("tests/init-global/neg", options).checkExpectedErrors() |
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.
compileFilesInDir("tests/init-global/neg", options).checkExpectedErrors() |
This one is repeated. Keep the one with the filter (2 lines bellow).
compileFilesInDir("tests/init-global/neg", options, FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkExpectedErrors()
@@ -216,7 +216,10 @@ class CompilationTests { | |||
@Test def checkInitGlobal: Unit = { | |||
implicit val testGroup: TestGroup = TestGroup("checkInitGlobal") | |||
val options = defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings") | |||
compileFilesInDir("tests/init-global/neg", options).checkExpectedErrors() | |||
compileFilesInDir("tests/init-global/pos", options).checkCompile() |
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.
compileFilesInDir("tests/init-global/pos", options).checkCompile() |
same duplication
compileFilesInDir("tests/init-global/neg", options, FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkExpectedErrors() | ||
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkWarnings() |
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.
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkWarnings() | |
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.warnInitGlobalScala2LibraryTastyBlacklisted)).checkWarnings() |
Create the blacklist only if it is necessary. Otherwise remove the filter.
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkWarnings() | |
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global")).checkWarnings() |
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.
These will only be tested on lightly or with [test_scala2_library_tasty]
. I will add this to your PR.
tests/init-global/neg/i12544b.scala
Outdated
|
||
def f(e: Enum): Enum = e | ||
|
||
@main def main(): Unit = println(Enum.b) | ||
|
||
// nopos-error: No warnings can be incurred under -Werror. |
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.
This test should probably be moved to tests/init-global/warn/i12544b.scala
.
Same for other tests that only have warnings and no errors. We do not need to add checkfiles for these kinds of tests.
@@ -776,7 +776,7 @@ trait ParallelTesting extends RunnerOrchestration { self => | |||
end maybeFailureMessage | |||
|
|||
def getWarnMapAndExpectedCount(files: Seq[JFile]): (HashMap[String, Integer], Int) = |
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.
If we do not have any // warn
or // nopos-warn
we should emit an error. Similar to the one for neg test:
tests/warn/i9740.scala
Outdated
case TypedRecoveryCompleted => | ||
} | ||
} |
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.
Dont remove the last \n
of the files
@@ -15,3 +15,5 @@ object A: | |||
val box1: Box = new Box(new C(5)) | |||
val box2: Box = new Box(new D(10)) | |||
val m: Int = box1.value.foo() | |||
|
|||
// nopos-error: No warnings can be incurred under -Werror. |
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.
Don't forget to add the last \n
of the file.
@@ -10,7 +10,7 @@ class M(x: Int) { | |||
class L1(x: Int) { val n: Int = 5 } | |||
|
|||
class A(b: B, x: Int) { | |||
println(d.n) | |||
println(d.n) |
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.
println(d.n) | |
println(d.n) |
tests/init/warn/simple1.scala
Outdated
class Foo { | ||
val len = name.size | ||
val name: String = "Jack" // warn | ||
} |
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.
} | |
} | |
tests/warn/i16649-refutable.scala
Outdated
val '{ $a: Int } = x | ||
val '{ $b: Any } = x | ||
val '{ $c } = x | ||
|
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.
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.
We can simplify the work needed to get this PR considerably if we split it in parts.
- Add warn test infrastructure
- Migrate neg tests into warn tests (in batches)
- Change warning/error behavior
Good idea. I will split it in a couple of PRs. |
5c96677
to
feed938
Compare
Moves first batch of tests. PR 1/5 (merge consecutively, per [Nicolas' suggestion](#18829 (review)) Split up version of #18829
…Batch 1 (#19242) Adds functionality to vulpix that allows putting nopos-warns in comments & First batch of tests moved from tests/neg to tests/warn. PR 2/5 (merge consecutively, per [Nicolas' suggestion](#18829 (review)) Split up version of #18829
The second batch of tests moved from tests/neg to tests/warn. PR 3/5 (merge consecutively, per [Nicolas' suggestion](#18829 (review)) Split up version of #18829
The last batch of tests, move tests other than tests/init/neg and tests/neg to warn. PR 4/5 (merge consecutively, per [Nicolas' suggestion](#18829 (review)) Split up version of #18829
) Final PR. Adds functionality that changes the behaviour of fatal-warnings - fixes #18634 PR 5/5 (merge consecutively, per [Nicolas' suggestion](#18829 (review)) Split up version of #18829
Fix #18634
[test_scala2_library_tasty]