From a726a2d7bd57221c53721df4df0bdf045ea2f4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Tue, 16 Nov 2021 16:37:12 +0100 Subject: [PATCH] Update tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ulysse GĂ©rard --- .../test-cases/cxx-flags.t/baz.cpp | 10 +++ .../test-cases/cxx-flags.t/bazexe.cpp | 11 +++ .../test-cases/cxx-flags.t/dune | 2 +- .../test-cases/cxx-flags.t/main.ml | 10 ++- .../test-cases/cxx-flags.t/quad.ml | 4 ++ .../test-cases/cxx-flags.t/run.t | 71 ++++++++++++++++--- 6 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 test/blackbox-tests/test-cases/cxx-flags.t/bazexe.cpp diff --git a/test/blackbox-tests/test-cases/cxx-flags.t/baz.cpp b/test/blackbox-tests/test-cases/cxx-flags.t/baz.cpp index 9fbd06bf4fd1..5cbbc00c0c7b 100644 --- a/test/blackbox-tests/test-cases/cxx-flags.t/baz.cpp +++ b/test/blackbox-tests/test-cases/cxx-flags.t/baz.cpp @@ -1,2 +1,12 @@ #include +#include +#include + 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"; +} diff --git a/test/blackbox-tests/test-cases/cxx-flags.t/bazexe.cpp b/test/blackbox-tests/test-cases/cxx-flags.t/bazexe.cpp new file mode 100644 index 000000000000..c44efd5cc3e4 --- /dev/null +++ b/test/blackbox-tests/test-cases/cxx-flags.t/bazexe.cpp @@ -0,0 +1,11 @@ +#include +#include + +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!"; +} diff --git a/test/blackbox-tests/test-cases/cxx-flags.t/dune b/test/blackbox-tests/test-cases/cxx-flags.t/dune index 56b17d50b042..6f4cc7ca9042 100644 --- a/test/blackbox-tests/test-cases/cxx-flags.t/dune +++ b/test/blackbox-tests/test-cases/cxx-flags.t/dune @@ -6,5 +6,5 @@ (executable (name main) (libraries quad) + (foreign_stubs (language cxx) (names bazexe)) (modules main)) - diff --git a/test/blackbox-tests/test-cases/cxx-flags.t/main.ml b/test/blackbox-tests/test-cases/cxx-flags.t/main.ml index 782f3f1b49c4..33d67253f523 100644 --- a/test/blackbox-tests/test-cases/cxx-flags.t/main.ml +++ b/test/blackbox-tests/test-cases/cxx-flags.t/main.ml @@ -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 ()) diff --git a/test/blackbox-tests/test-cases/cxx-flags.t/quad.ml b/test/blackbox-tests/test-cases/cxx-flags.t/quad.ml index 49a7e9108094..1334cfe4f56d 100644 --- a/test/blackbox-tests/test-cases/cxx-flags.t/quad.ml +++ b/test/blackbox-tests/test-cases/cxx-flags.t/quad.ml @@ -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 () diff --git a/test/blackbox-tests/test-cases/cxx-flags.t/run.t b/test/blackbox-tests/test-cases/cxx-flags.t/run.t index 5d0ab42d0b4b..b6511d614587 100644 --- a/test/blackbox-tests/test-cases/cxx-flags.t/run.t +++ b/test/blackbox-tests/test-cases/cxx-flags.t/run.t @@ -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 @@ -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 ========================================= @@ -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 ======================================== @@ -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!