From e9a2ac48ed57a04a120697bd5507bf2fa289b7c2 Mon Sep 17 00:00:00 2001 From: shubhamkumar13 Date: Fri, 9 Apr 2021 23:13:41 +0530 Subject: [PATCH 1/2] replace ocp-indent with ocamlformat --- proj/.ocamlformat | 1 + proj/.ocamlinit | 2 -- proj/.ocp-indent | 22 ---------------------- proj/Makefile | 6 +++++- proj/proj.opam | 1 + 5 files changed, 7 insertions(+), 25 deletions(-) create mode 100644 proj/.ocamlformat delete mode 100644 proj/.ocamlinit delete mode 100644 proj/.ocp-indent diff --git a/proj/.ocamlformat b/proj/.ocamlformat new file mode 100644 index 0000000..9f28a3f --- /dev/null +++ b/proj/.ocamlformat @@ -0,0 +1 @@ +version=0.17.0 diff --git a/proj/.ocamlinit b/proj/.ocamlinit deleted file mode 100644 index 9bb7beb..0000000 --- a/proj/.ocamlinit +++ /dev/null @@ -1,2 +0,0 @@ -#use "topfind";; -open Printf;; diff --git a/proj/.ocp-indent b/proj/.ocp-indent deleted file mode 100644 index fb580a5..0000000 --- a/proj/.ocp-indent +++ /dev/null @@ -1,22 +0,0 @@ -# See https://github.com/OCamlPro/ocp-indent/blob/master/.ocp-indent for more - -# Indent for clauses inside a pattern-match (after the arrow): -# match foo with -# | _ -> -# ^^^^bar -# the default is 2, which aligns the pattern and the expression -match_clause = 4 - -# When nesting expressions on the same line, their indentation are in -# some cases stacked, so that it remains correct if you close them one -# at a line. This may lead to large indents in complex code though, so -# this parameter can be used to set a maximum value. Note that it only -# affects indentation after function arrows and opening parens at end -# of line. -# -# for example (left: `none`; right: `4`) -# let f = g (h (i (fun x -> # let f = g (h (i (fun x -> -# x) # x) -# ) # ) -# ) # ) -max_indent = 2 diff --git a/proj/Makefile b/proj/Makefile index 448d954..fd4c5a9 100644 --- a/proj/Makefile +++ b/proj/Makefile @@ -1,6 +1,6 @@ # Frontend to dune. -.PHONY: default build install uninstall test clean +.PHONY: default build install uninstall test clean fmt default: build @@ -21,3 +21,7 @@ clean: # Optionally, remove all files/folders ignored by git as defined # in .gitignore (-X). git clean -dfXq + +fmt: + dune build @fmt + dune promote diff --git a/proj/proj.opam b/proj/proj.opam index c4b5ca4..23a7991 100644 --- a/proj/proj.opam +++ b/proj/proj.opam @@ -25,5 +25,6 @@ run-test: ["dune" "runtest" "-p" name] depends: [ "dune" + "ocamlformat" { >= "0.17.0" } "alcotest" {with-test} ] From 70cc3f9eef55b0060de0e7b220da1853d8261470 Mon Sep 17 00:00:00 2001 From: shubhamkumar13 Date: Sun, 11 Apr 2021 19:39:25 +0530 Subject: [PATCH 2/2] update dune version to 2.8.0, update runtest alias to a rule stanza, create a fmt target to format the files using ocamlformat and also update the foramtting of each file --- proj/Makefile | 1 + proj/dune-project | 2 +- proj/sub1/lib/a.ml | 3 +-- proj/sub1/lib/a.mli | 2 +- proj/sub1/lib/b.ml | 3 +-- proj/sub1/lib/dune | 1 + proj/sub1/test/a.ml | 4 +--- proj/sub1/test/b.ml | 14 ++++++-------- proj/sub1/test/dune | 5 +---- proj/sub2/bin/bar_main.ml | 1 + proj/sub2/bin/dune | 6 ++---- proj/sub2/bin/foo_main.ml | 40 ++++++++++++++------------------------- proj/sub2/lib/a.ml | 3 +-- proj/sub2/lib/dune | 6 +----- proj/sub2/test/a.ml | 3 +-- proj/sub2/test/dune | 5 +---- proj/test/dune | 13 +++++-------- proj/test/run_tests.ml | 11 ++++++----- 18 files changed, 46 insertions(+), 77 deletions(-) diff --git a/proj/Makefile b/proj/Makefile index fd4c5a9..1273b42 100644 --- a/proj/Makefile +++ b/proj/Makefile @@ -1,6 +1,7 @@ # Frontend to dune. .PHONY: default build install uninstall test clean fmt +.IGNORE: fmt default: build diff --git a/proj/dune-project b/proj/dune-project index 5263ef1..bec64cd 100644 --- a/proj/dune-project +++ b/proj/dune-project @@ -1,3 +1,3 @@ -(lang dune 1.0) +(lang dune 2.8) (name proj) ; optional (version 0.0.0) ; optional diff --git a/proj/sub1/lib/a.ml b/proj/sub1/lib/a.ml index aa630c8..c5942f6 100644 --- a/proj/sub1/lib/a.ml +++ b/proj/sub1/lib/a.ml @@ -1,2 +1 @@ -let now () = - Unix.gettimeofday () +let now () = Unix.gettimeofday () diff --git a/proj/sub1/lib/a.mli b/proj/sub1/lib/a.mli index 75ae905..2af142e 100644 --- a/proj/sub1/lib/a.mli +++ b/proj/sub1/lib/a.mli @@ -3,4 +3,4 @@ *) val now : unit -> float - (** Returns the time since 1970 in seconds. *) +(** Returns the time since 1970 in seconds. *) diff --git a/proj/sub1/lib/b.ml b/proj/sub1/lib/b.ml index 5b7f5f8..3153848 100644 --- a/proj/sub1/lib/b.ml +++ b/proj/sub1/lib/b.ml @@ -6,5 +6,4 @@ open Printf let do_something () = let unixtime = A.now () in - printf "%.3f seconds have elapsed since 1970-01-01T00:00:00.\n%!" - unixtime + printf "%.3f seconds have elapsed since 1970-01-01T00:00:00.\n%!" unixtime diff --git a/proj/sub1/lib/dune b/proj/sub1/lib/dune index bbfff57..874c252 100644 --- a/proj/sub1/lib/dune +++ b/proj/sub1/lib/dune @@ -1,5 +1,6 @@ ; name = name of the supermodule that will wrap all source files as submodules ; public_name = name of the library for ocamlfind and opam + (library (name proj_sub1) (public_name proj.sub1) diff --git a/proj/sub1/test/a.ml b/proj/sub1/test/a.ml index d150132..0bb30b3 100644 --- a/proj/sub1/test/a.ml +++ b/proj/sub1/test/a.ml @@ -8,6 +8,4 @@ let test_time () = check "now is greater than 1000" (Proj_sub1.A.now () > 1000.); check "now is fix" (Proj_sub1.A.now () > 1_522_882_648.) -let tests = [ - "time", `Quick, test_time; -] +let tests = [ ("time", `Quick, test_time) ] diff --git a/proj/sub1/test/b.ml b/proj/sub1/test/b.ml index 7dc33ba..09ee18d 100644 --- a/proj/sub1/test/b.ml +++ b/proj/sub1/test/b.ml @@ -2,13 +2,11 @@ Tests for Sub1.B *) -let test_string () = - Alcotest.(check (neg string)) "foo is not bar" "foo" "bar" +let test_string () = Alcotest.(check (neg string)) "foo is not bar" "foo" "bar" -let test_string_hasty () = - assert ("foo" <> "bar") +let test_string_hasty () = assert ("foo" <> "bar") -let tests = [ - "string", `Quick, test_string; - "string, hasty", `Quick, test_string_hasty; -] +let tests = + [ + ("string", `Quick, test_string); ("string, hasty", `Quick, test_string_hasty); + ] diff --git a/proj/sub1/test/dune b/proj/sub1/test/dune index cf64bed..e740cab 100644 --- a/proj/sub1/test/dune +++ b/proj/sub1/test/dune @@ -1,7 +1,4 @@ (library (name test_sub1) - (libraries - alcotest - proj.sub1 - ) + (libraries alcotest proj.sub1) (synopsis "Tests for sub1")) diff --git a/proj/sub2/bin/bar_main.ml b/proj/sub2/bin/bar_main.ml index e0f36bf..3fd1b9f 100644 --- a/proj/sub2/bin/bar_main.ml +++ b/proj/sub2/bin/bar_main.ml @@ -1 +1,2 @@ +;; print_endline "Hello! The version is %%VERSION%%" diff --git a/proj/sub2/bin/dune b/proj/sub2/bin/dune index ba7f4eb..e32fafe 100644 --- a/proj/sub2/bin/dune +++ b/proj/sub2/bin/dune @@ -1,10 +1,8 @@ ; names = name of the files to compile into executables ; public_names = name of the executables + (executables (names foo_main bar_main) (public_names sub2-foo sub2-bar) - (libraries - proj.sub1 - proj.sub2 - ) + (libraries proj.sub1 proj.sub2) (package proj)) diff --git a/proj/sub2/bin/foo_main.ml b/proj/sub2/bin/foo_main.ml index fc41b1c..c03e878 100644 --- a/proj/sub2/bin/foo_main.ml +++ b/proj/sub2/bin/foo_main.ml @@ -11,42 +11,32 @@ open Printf You may want to use Arg.parse_argv to read the remaining command-line arguments. *) -let run _argv_offset = - Proj_sub2.A.do_something () +let run _argv_offset = Proj_sub2.A.do_something () -let walk _argv_offset = - print_endline "Nice." +let walk _argv_offset = print_endline "Nice." (* Add your own subcommands as needed. *) -let subcommands = [ - "run", run; - "walk", walk; -] +let subcommands = [ ("run", run); ("walk", walk) ] let help () = let subcommand_names = String.concat "\n" (List.map (fun (name, _f) -> " " ^ name) subcommands) in - let usage_msg = sprintf "\ -Usage: %s SUBCOMMAND [ARGS] -where SUBCOMMAND is one of: -%s - -For help on a specific subcommand, try: - %s SUBCOMMAND --help -" - Sys.argv.(0) subcommand_names Sys.argv.(0) + let usage_msg = + sprintf + "Usage: %s SUBCOMMAND [ARGS]\n\ + where SUBCOMMAND is one of:\n\ + %s\n\n\ + For help on a specific subcommand, try:\n\ + \ %s SUBCOMMAND --help\n" + Sys.argv.(0) subcommand_names Sys.argv.(0) in eprintf "%s%!" usage_msg let dispatch_subcommand () = assert (Array.length Sys.argv > 1); match Sys.argv.(1) with - | "help" - | "-h" - | "-help" - | "--help" -> - help () + | "help" | "-h" | "-help" | "--help" -> help () | subcmd -> let argv_offset = 1 in let action = @@ -62,10 +52,8 @@ let main () = let len = Array.length Sys.argv in if len <= 1 then ( help (); - exit 1 - ) - else - dispatch_subcommand () + exit 1) + else dispatch_subcommand () (* Run now. *) let () = main () diff --git a/proj/sub2/lib/a.ml b/proj/sub2/lib/a.ml index 063e342..3164c88 100644 --- a/proj/sub2/lib/a.ml +++ b/proj/sub2/lib/a.ml @@ -6,5 +6,4 @@ open Printf let do_something () = let unixtime = Proj_sub1.A.now () in - printf "%.3f seconds have elapsed since 1970-01-01T00:00:00.\n%!" - unixtime + printf "%.3f seconds have elapsed since 1970-01-01T00:00:00.\n%!" unixtime diff --git a/proj/sub2/lib/dune b/proj/sub2/lib/dune index dd9bd03..54fc7c5 100644 --- a/proj/sub2/lib/dune +++ b/proj/sub2/lib/dune @@ -1,9 +1,5 @@ (library (name proj_sub2) (public_name proj.sub2) - (libraries - unix - str - proj.sub1 - ) + (libraries unix str proj.sub1) (synopsis "This is a short description of the sub2 library.")) diff --git a/proj/sub2/test/a.ml b/proj/sub2/test/a.ml index d31911c..9134e03 100644 --- a/proj/sub2/test/a.ml +++ b/proj/sub2/test/a.ml @@ -2,5 +2,4 @@ Tests for Sub2.A *) -let tests = [ -] +let tests = [] diff --git a/proj/sub2/test/dune b/proj/sub2/test/dune index 00a0a9c..883c442 100644 --- a/proj/sub2/test/dune +++ b/proj/sub2/test/dune @@ -1,7 +1,4 @@ (library (name test_sub2) - (libraries - alcotest - proj.sub2 - ) + (libraries alcotest proj.sub2) (synopsis "Tests for sub2")) diff --git a/proj/test/dune b/proj/test/dune index 8f95be8..bd94115 100644 --- a/proj/test/dune +++ b/proj/test/dune @@ -1,12 +1,9 @@ (executable (name run_tests) - (libraries - alcotest - test_sub1 - test_sub2 -)) + (libraries alcotest test_sub1 test_sub2)) -(alias - (name runtest) +(rule + (alias runtest) (deps run_tests.exe) - (action (run %{deps} -q --color=always))) + (action + (run %{deps} -q --color=always))) diff --git a/proj/test/run_tests.ml b/proj/test/run_tests.ml index f620f6f..647daae 100644 --- a/proj/test/run_tests.ml +++ b/proj/test/run_tests.ml @@ -2,10 +2,11 @@ Run all the OCaml test suites defined in the project. *) -let test_suites: unit Alcotest.test list = [ - "Sub1.A", Test_sub1.A.tests; - "Sub1.B", Test_sub1.B.tests; - "Sub2.A", Test_sub2.A.tests; -] +let test_suites : unit Alcotest.test list = + [ + ("Sub1.A", Test_sub1.A.tests); + ("Sub1.B", Test_sub1.B.tests); + ("Sub2.A", Test_sub2.A.tests); + ] let () = Alcotest.run "proj" test_suites