Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ocp-indent to ocamlformat and replace action with rule stanza #13

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions proj/.ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=0.17.0
2 changes: 0 additions & 2 deletions proj/.ocamlinit

This file was deleted.

22 changes: 0 additions & 22 deletions proj/.ocp-indent

This file was deleted.

7 changes: 6 additions & 1 deletion proj/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Frontend to dune.

.PHONY: default build install uninstall test clean
.PHONY: default build install uninstall test clean fmt
.IGNORE: fmt

default: build

Expand All @@ -21,3 +22,7 @@ clean:
# Optionally, remove all files/folders ignored by git as defined
# in .gitignore (-X).
git clean -dfXq

fmt:
dune build @fmt
dune promote
2 changes: 1 addition & 1 deletion proj/dune-project
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 1.0)
(lang dune 2.8)
(name proj) ; optional
(version 0.0.0) ; optional
1 change: 1 addition & 0 deletions proj/proj.opam
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ run-test: ["dune" "runtest" "-p" name]

depends: [
"dune"
"ocamlformat" { >= "0.17.0" }
"alcotest" {with-test}
]
3 changes: 1 addition & 2 deletions proj/sub1/lib/a.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
let now () =
Unix.gettimeofday ()
let now () = Unix.gettimeofday ()
2 changes: 1 addition & 1 deletion proj/sub1/lib/a.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*)

val now : unit -> float
(** Returns the time since 1970 in seconds. *)
(** Returns the time since 1970 in seconds. *)
3 changes: 1 addition & 2 deletions proj/sub1/lib/b.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions proj/sub1/lib/dune
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 1 addition & 3 deletions proj/sub1/test/a.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) ]
14 changes: 6 additions & 8 deletions proj/sub1/test/b.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this formatting style for lists but I'll get used to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was autogenerated by ocamlformat :D

5 changes: 1 addition & 4 deletions proj/sub1/test/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
(library
(name test_sub1)
(libraries
alcotest
proj.sub1
)
(libraries alcotest proj.sub1)
(synopsis "Tests for sub1"))
1 change: 1 addition & 0 deletions proj/sub2/bin/bar_main.ml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
;;
print_endline "Hello! The version is %%VERSION%%"
6 changes: 2 additions & 4 deletions proj/sub2/bin/dune
Original file line number Diff line number Diff line change
@@ -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))
40 changes: 14 additions & 26 deletions proj/sub2/bin/foo_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's happening here with the leading backslash?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let you take a look in case it's a bug with ocamlformat that needs reporting or something.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what, nevermind. I'll just fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't notice this 😅, Thanks for fixing this!

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 =
Expand All @@ -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 ()
3 changes: 1 addition & 2 deletions proj/sub2/lib/a.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions proj/sub2/lib/dune
Original file line number Diff line number Diff line change
@@ -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."))
3 changes: 1 addition & 2 deletions proj/sub2/test/a.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
Tests for Sub2.A
*)

let tests = [
]
let tests = []
5 changes: 1 addition & 4 deletions proj/sub2/test/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
(library
(name test_sub2)
(libraries
alcotest
proj.sub2
)
(libraries alcotest proj.sub2)
(synopsis "Tests for sub2"))
13 changes: 5 additions & 8 deletions proj/test/dune
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
(executable
(name run_tests)
(libraries
alcotest
test_sub1
test_sub2
))
(libraries alcotest test_sub1 test_sub2))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to have one thing per line so that the diff make sense when we add/remove items later.

Copy link
Contributor Author

@shubhamkumar13 shubhamkumar13 Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was something that was auto-generated by ocamlformat and as we are going to use ocamlformat in the future I thought leaving the formatted code in would be better here


(alias
(name runtest)
(rule
(alias runtest)
(deps run_tests.exe)
(action (run %{deps} -q --color=always)))
(action
(run %{deps} -q --color=always)))
11 changes: 6 additions & 5 deletions proj/test/run_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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