janestreet / ppx_expect

Cram like framework for OCaml
MIT License
146 stars 28 forks source link

Does not compile with OCaml 4.10 #19

Closed jaapb closed 4 years ago

jaapb commented 4 years ago

When trying to compile ppx_expect (either the latest release or the latest commit) with OCaml 4.10, I get the following error:

In file included from /usr/pkg/lib/ocaml/caml/misc.h:30,
                 from /usr/pkg/lib/ocaml/caml/alloc.h:23,
                 from expect_test_collector_stubs.c:1:
expect_test_collector_stubs.c: In function 'expect_test_collector_before_test':
expect_test_collector_stubs.c:54:19: error: expected identifier or '(' before '&' token
   struct channel* stdout = Channel(vstdout);
                   ^~~~~~
expect_test_collector_stubs.c:55:19: error: expected identifier or '(' before '&' token
   struct channel* stderr = Channel(vstderr);
                   ^~~~~~
expect_test_collector_stubs.c:57:18: error: 'FILE' {aka 'struct __sFILE'} has no member named 'fd'
   fd = dup(stdout->fd);
                  ^~
expect_test_collector_stubs.c:60:18: error: 'FILE' {aka 'struct __sFILE'} has no member named 'fd'
   fd = dup(stderr->fd);
                  ^~
expect_test_collector_stubs.c:63:32: error: 'FILE' {aka 'struct __sFILE'} has no member named 'fd'
   ret = dup2(output->fd, stdout->fd);
                                ^~
expect_test_collector_stubs.c:65:32: error: 'FILE' {aka 'struct __sFILE'} has no member named 'fd'
   ret = dup2(output->fd, stderr->fd);
                                ^~
In file included from /usr/pkg/lib/ocaml/caml/misc.h:30,
                 from /usr/pkg/lib/ocaml/caml/alloc.h:23,
                 from expect_test_collector_stubs.c:1:
expect_test_collector_stubs.c: In function 'expect_test_collector_after_test':
expect_test_collector_stubs.c:71:19: error: expected identifier or '(' before '&
 member named 'fd'
   ret = dup2(output->fd, stderr->fd);
                                ^~
In file included from /usr/pkg/lib/ocaml/caml/misc.h:30,
                 from /usr/pkg/lib/ocaml/caml/alloc.h:23,
                 from expect_test_collector_stubs.c:1:
expect_test_collector_stubs.c: In function 'expect_test_collector_after_test':
expect_test_collector_stubs.c:71:19: error: expected identifier or '(' before '&' token
   struct channel* stdout = Channel(vstdout);
                   ^~~~~~
expect_test_collector_stubs.c:72:19: error: expected identifier or '(' before '&' token
   struct channel* stderr = Channel(vstderr);
                   ^~~~~~
expect_test_collector_stubs.c:74:56: error: 'FILE' {aka 'struct __sFILE'} has no member named 'fd'
   ret = dup2(expect_test_collector_saved_stdout, stdout->fd);
                                                        ^~
expect_test_collector_stubs.c:76:56: error: 'FILE' {aka 'struct __sFILE'} has no member named 'fd'
   ret = dup2(expect_test_collector_saved_stderr, stderr->fd);
                                                        ^~
hhugo commented 4 years ago

I'm not able to reproduce this with a 4.10 opam switch

jaapb commented 4 years ago

All right, then it probably is something NetBSD-specific, thanks for checking. I'll investigate further.

jaapb commented 4 years ago

So, it turns out that calling variables stdout and/or stderr leads to problems on NetBSD (they are #defined in stdio.h). If I modify expect_test_collector_stubs.c so that the variables are called something else, everything compiles correctly. Would you like me to put in a pull request?

hhugo commented 4 years ago

A PR would be welcome. Thanks for the investigation.

avsm commented 4 years ago

This is also being discussed in https://github.com/ocaml/ocaml/pull/9483#issuecomment-620531237 upstream. A fix to avoid the use of stdout/stderr in ppx_expect would be very useful.

hhugo commented 4 years ago

fixed by https://github.com/janestreet/ppx_expect/commit/acefef378dd50d5af3e624619a998c90ad2793ef