Skip to content

Instantly share code, notes, and snippets.

@danilopiazza
Created December 1, 2024 22:06
Show Gist options
  • Save danilopiazza/d8ba4cd243480c1883b29af9a8259d7b to your computer and use it in GitHub Desktop.
Save danilopiazza/d8ba4cd243480c1883b29af9a8259d7b to your computer and use it in GitHub Desktop.
OCaml Dune project with unit tests
(executable
(public_name helloworld)
(name main)
(libraries helloworld))
let () =
if Array.length Sys.argv > 1 then
print_endline (Helloworld.hello Sys.argv.(1))
else
print_endline Helloworld.hello_world
(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
(library
(name helloworld))
let hello name =
"Hello, " ^ name ^ "!"
let hello_world =
hello "World"
(test
(name test_helloworld)
(libraries alcotest helloworld))
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