Created
December 1, 2024 22:06
-
-
Save danilopiazza/d8ba4cd243480c1883b29af9a8259d7b to your computer and use it in GitHub Desktop.
OCaml Dune project with unit tests
This file contains hidden or 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
| (executable | |
| (public_name helloworld) | |
| (name main) | |
| (libraries helloworld)) |
This file contains hidden or 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
| let () = | |
| if Array.length Sys.argv > 1 then | |
| print_endline (Helloworld.hello Sys.argv.(1)) | |
| else | |
| print_endline Helloworld.hello_world |
This file contains hidden or 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
| (lang dune 3.17) | |
| (name helloworld) | |
| (generate_opam_files true) | |
| (source | |
| (github username/reponame)) | |
| (authors "Author Name <[email protected]>") | |
| (maintainers "Maintainer Name <[email protected]>") | |
| (license LICENSE) | |
| (documentation https://url/to/documentation) | |
| (package | |
| (name helloworld) | |
| (synopsis "A short synopsis") | |
| (description "A longer description") | |
| (depends | |
| ocaml | |
| (alcotest :with-test)) | |
| (tags | |
| ("add topics" "to describe" your project))) | |
| ; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html |
This file contains hidden or 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
| (library | |
| (name helloworld)) |
This file contains hidden or 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
| let hello name = | |
| "Hello, " ^ name ^ "!" | |
| let hello_world = | |
| hello "World" |
This file contains hidden or 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
| (test | |
| (name test_helloworld) | |
| (libraries alcotest helloworld)) |
This file contains hidden or 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
| open Helloworld | |
| let test_hello_world () = | |
| Alcotest.(check string) "same string" "Hello, World!" (hello_world) | |
| let test_hello_name () = | |
| Alcotest.(check string) "same string" "Hello, Jane!" (hello "Jane") | |
| let () = | |
| let open Alcotest in | |
| run "Helloworld" [ | |
| "hello_world", [ test_case "hello_world with default message" `Quick test_hello_world ]; | |
| "hello", [ test_case "hello with given name" `Quick test_hello_name ]; | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment