-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The match expression rewriter inserts expressions that can cause spurious warnings. These warnings would be especially surprising to a user, because they would be coming from unseen generated code. The new tests check that these warnings are properly suppressed. We were checking this implicitly until #92. Closes #94.
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(* Trigger at least one warning to make sure they are on. *) | ||
let () = | ||
let f ?maybe () = ignore maybe in | ||
() |> f | ||
|
||
type t = A | B | C | ||
type u = {a : int; b : int; c : int} | ||
|
||
(* Triggers (suppressed) warning 4 without -inexhaustive-matching: fragile | ||
pattern matching (due to wildcard). *) | ||
(* Triggers (suppressed) warning 11 without -inexhaustive-matching: unused match | ||
case (wildcard). *) | ||
let f x = | ||
match x with | ||
| A | B | C -> 42 | ||
|
||
(* Triggers (suppressed) warning 8 with -inexhaustive-matching: inexhaustive | ||
matching. *) | ||
let g x = | ||
match x with | ||
| A | B -> 42 | ||
| C -> 43 | ||
|
||
(* Triggers a (suppressed) duplicate set of warning 9 (missing record | ||
labels). *) | ||
(* Triggers (suppressed) warning 27: unused variable a. *) | ||
let h x = | ||
match x with | ||
| {a} | {a} -> ignore a | ||
|
||
(* Triggers (suppressed) warning 26: unused variable x. *) | ||
let i x = | ||
match x with | ||
| (A as x) | (B as x) -> ignore x; 42 | ||
| C -> 43 | ||
|
||
(* Triggers (suppressed) duplicate warning 28 (wildcard given to constant | ||
constructor). *) | ||
let j x = | ||
match x with | ||
| A _ | B | C -> () |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
File "source.ml", line 4, characters 8-9: | ||
Warning 48: implicit elimination of optional argument ?maybe | ||
File "source.ml", line 29, characters 4-7: | ||
Warning 9: the following labels are not bound in this record pattern: | ||
b, c | ||
Either bind these labels explicitly or add '; _' to the pattern. | ||
File "source.ml", line 29, characters 10-13: | ||
Warning 9: the following labels are not bound in this record pattern: | ||
b, c | ||
Either bind these labels explicitly or add '; _' to the pattern. | ||
File "source.ml", line 29, characters 10-13: | ||
Warning 12: this sub-pattern is unused. | ||
File "source.ml", line 41, characters 6-7: | ||
Warning 28: wildcard pattern given as argument to a constant constructor |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
(* | ||
* This file is part of Bisect_ppx. | ||
* Copyright (C) 2016 Anton Bachin. | ||
* | ||
* Bisect is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Bisect is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*) | ||
|
||
open OUnit2 | ||
open Test_helpers | ||
|
||
(* OCaml 4.02 and 4.03 order output of warnings 12 and 28 differently. To get | ||
around that, these tests sort the output lines. *) | ||
let sorted_diff () = | ||
run "sort < output.raw > output"; | ||
run "sort < ../warnings/source.ml.reference > reference"; | ||
diff ~preserve_as:"warnings/source.ml.reference" "_scratch/reference" | ||
|
||
let tests = "warnings" >::: [ | ||
test "default" begin fun () -> | ||
compile | ||
((with_bisect ()) ^ " -w +A") "warnings/source.ml" ~r:"2> output.raw"; | ||
sorted_diff () | ||
end; | ||
|
||
test "inexhaustive-matching" begin fun () -> | ||
compile | ||
((with_bisect_args "-inexhaustive-matching") ^ " -w +A") | ||
"warnings/source.ml" | ||
~r:"2> output.raw"; | ||
sorted_diff () | ||
end | ||
] |