-
Notifications
You must be signed in to change notification settings - Fork 91
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
Make expect tests compiler-independent #330
Conversation
Using `Pprintast` from the compiler, as was done before, has the problem that the test output can differ on different compiler versions. Signed-off-by: Sonja Heinze <sonjaleaheinze@gmail.com>
I'm only wondering, why What would happen if at some point, we want to update this function? (for instance, to behave like in 4.14, which seems a better behaviour (see ocaml/ocaml#10565). In conclusion, I think that this PR should be merged, but independently I think we should have a story on when to update |
Thanks @panglesd!
That's a very good point! And in fact, I've also added a second commit now which should indeed fix the CI in #327. See commit message of that commit for more explanation. I admit that inlining
Let me know if you have an idea for a better solution and, if not, let me know what you think about this! |
I think we should only keep the first commit. Promoting the test in #327 will fix the CI test for all versions of OCaml. |
Are you sure that that's the case if we only keep the first commit? I think that's the case if we only keep the second commit (although, also in that case, I'd keep the first commit, since the first commit is a simple improvement) |
Sorry for my previous comment, you are right it's the second commit that will make CI pass and that the first one is still good to keep! However I have a suggestion: instead of inlining, why not modify the (* To achieve 4.14 printing behaviour, see
https://github.com/ocaml/ocaml/pull/10565 *)
let rec map_tree = function
| Outcometree.Oval_constr (name, params) ->
Outcometree.Oval_constr (name, List.map ~f:map_tree params)
| Oval_variant (name, Some param) ->
Oval_variant (name, Some (map_tree param))
| Oval_string (s, maxlen, kind) ->
Oval_string (s, (if maxlen < 8 then 8 else maxlen), kind)
| Oval_tuple tl -> Oval_tuple (List.map ~f:map_tree tl)
| Oval_array tl -> Oval_array (List.map ~f:map_tree tl)
| Oval_list tl -> Oval_list (List.map ~f:map_tree tl)
| Oval_record fel ->
Oval_record
(List.map ~f:(fun (name, tree) -> (name, map_tree tree)) fel)
| tree -> tree
in
let print_out_value = !Toploop.print_out_value in
(Toploop.print_out_value :=
fun ppf tree -> print_out_value ppf (map_tree tree)); |
3f88d2d
to
5be4bb2
Compare
Ooh nice, I love that idea, @panglesd! Side-note: I haven't checked carefully if all variant constructors are recursed correctly. If not, the worst case would be that the CI breaks again and it would be very easy to fix it. |
5be4bb2
to
e4518c4
Compare
The ppxlib custom expect test uses the compiler's Toploop.print_out_value indirectly when executing the toplevel phrase. Toploop.print_out_vale truncates strings that exceed a certain maximum length. That maximum length has been modified in OCaml 4.14. To stay compiler-agnostic, this commit stabilizes the maximum length in print_out_value. Signed-off-by: Sonja Heinze <sonjaleaheinze@gmail.com>
Using
Pprintast
from the compiler, as was done before, has the problem that the test output can differ on different compiler versions. See failing CI on #327.