Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ulysse Gérard <[email protected]>
  • Loading branch information
voodoos committed Nov 19, 2021
1 parent 1ba2962 commit a726a2d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 12 deletions.
10 changes: 10 additions & 0 deletions test/blackbox-tests/test-cases/cxx-flags.t/baz.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
#include <caml/mlvalues.h>
#include <caml/io.h>
#include <iostream>

extern "C" value baz(value unit) { return Val_int(2046); }

extern "C" void hello_world_baz ();

void hello_world_baz ()
{
std::cout << "Hello World Baz!\n";
}
11 changes: 11 additions & 0 deletions test/blackbox-tests/test-cases/cxx-flags.t/bazexe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <caml/mlvalues.h>
#include <iostream>

extern "C" value bazexe(value unit) { return Val_int(4096); }

extern "C" void hello_world_bazexe ();

void hello_world_bazexe ()
{
std::cout << "Hello World Bazexe!";
}
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/cxx-flags.t/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
(executable
(name main)
(libraries quad)
(foreign_stubs (language cxx) (names bazexe))
(modules main))

10 changes: 9 additions & 1 deletion test/blackbox-tests/test-cases/cxx-flags.t/main.ml
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
let () = Printf.printf "%d" (Quad.quad ())
external bazexe : unit -> int = "bazexe"
external hello_world_bazexe : unit -> unit = "hello_world_bazexe"

let () = Quad.hello (); hello_world_bazexe ()


let () = Printf.printf "%d\n%d\n"
(Quad.quad ())
(bazexe ())
4 changes: 4 additions & 0 deletions test/blackbox-tests/test-cases/cxx-flags.t/quad.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
external baz : unit -> int = "baz"

external hello_world_baz : unit -> unit = "hello_world_baz"

let quad x = baz x
let hello () = hello_world_baz ()
71 changes: 61 additions & 10 deletions test/blackbox-tests/test-cases/cxx-flags.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ Default: use_standard_c_and_cxx_flags = false
> (lang dune 2.8)
> EOF

> The flags that Dune should use
$ GCCF="-x c++ -lstdc++ -shared-libgcc"
$ ClangF="-x c++"
$ MsvcF="/TP"
> The flags that Dune should use for compilation
$ GCC_CF="-x c++"
$ Clang_CF="-x c++"
$ Msvc_CF="/TP"

> And linking
$ GCC_LF_OPT=" -ldopt -lstdc++ -ldopt -shared-libgcc"
$ Clang_LF_OPT=" -ldopt -lc++"
$ Msvc_LF_OPT=""
$ GCC_LF_LIB=" -cclib -lstdc++ -cclib -shared-libgcc"
$ Clang_LF_LIB=" -cclib -lc++"
$ Msvc_LF_LIB=""

> Check that compiler detection is done
$ dune build .dune/ccomp/ccomp
Expand All @@ -17,12 +25,25 @@ Default: use_standard_c_and_cxx_flags = false
> grep -ce "clang\|gcc\|msvc"
1

> No specific flags added
> No specific flags added for compilation...
$ dune rules baz.o | tr -s '\n' ' ' |
> grep -ce "$GCCF\|$ClangF|$MsvcF"
> grep -ce "$GCC_CF\|$Clang_CF|$Msvc_CF"
0
[1]

$ dune rules bazexe.o | tr -s '\n' ' ' |
> grep -ce "$GCC_CF\|$Clang_CF\|$Msvc_CF"
0
[1]

> ...nor linking
$ dune rules libquad_stubs.a | tr -s '\n' ' ' |
> grep -ce "quad_stubs baz.o)"
1

$ dune rules main.exe | tr -s '\n' ' ' |
> grep -ce "Main.cmx)"
1

With use_standard_c_and_cxx_flags = false
=========================================
Expand All @@ -32,12 +53,26 @@ With use_standard_c_and_cxx_flags = false
> (use_standard_c_and_cxx_flags false)
> EOF

> No specific flags added
> No specific flags added for compilation...
$ dune rules baz.o | tr -s '\n' ' ' |
> grep -ce "$GCCF\|$ClangF|$MsvcF"
> grep -ce "$GCC_CF\|$Clang_CF|$Msvc_CF"
0
[1]

$ dune rules bazexe.o | tr -s '\n' ' ' |
> grep -ce "$GCC_CF\|$Clang_CF\|$Msvc_CF"
0
[1]

> ...nor linking
$ dune rules libquad_stubs.a | tr -s '\n' ' ' |
> grep -ce "quad_stubs baz.o)"
1

$ dune rules main.exe | tr -s '\n' ' ' |
> grep -ce "Main.cmx)"
1

With use_standard_c_and_cxx_flags = true
========================================

Expand All @@ -53,10 +88,26 @@ With use_standard_c_and_cxx_flags = true
> grep -ce "clang\|gcc\|msvc"
1

> Specific flags added
> Specific flags added for compilation...
$ dune rules baz.o | tr -s '\n' ' ' |
> grep -ce "$GCCF\|$ClangF\|$MsvcF"
> grep -ce "$GCC_CF\|$Clang_CF\|$Msvc_CF"
1

$ dune rules bazexe.o | tr -s '\n' ' ' |
> grep -ce "$GCC_CF\|$Clang_CF\|$Msvc_CF"
1

> ..and link
$ dune rules libquad_stubs.a | tr -s '\n' ' ' |
> grep -ce "quad_stubs baz.o$GCC_LF_OPT)\|quad_stubs baz.o$Clang_LF_OPT)\|quad_stubs baz.o$Msvc_LF_OPT)"
1

$ dune rules main.exe | tr -s '\n' ' ' |
> grep -ce "Main.cmx$GCC_LF)\|Main.cmx$Clang_LF)\|Main.cmx$Msvc_LF)"
1

$ dune exec ./main.exe
2046
4096
Hello World Baz!
Hello World Bazexe!

0 comments on commit a726a2d

Please sign in to comment.