Skip to content

Commit

Permalink
Merge pull request #9 from mbarbin/more-tests
Browse files Browse the repository at this point in the history
Add tests - increase coverage
  • Loading branch information
mbarbin authored Sep 15, 2024
2 parents 159c32f + 2a2dc6d commit 8ceddf0
Show file tree
Hide file tree
Showing 40 changed files with 1,465 additions and 767 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"cmdliner",
"janestreet",
"odoc",
"opam"
"opam",
"stringable"
]
}
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 0.0.5 (unreleased)

### Added

- Increase test coverage.

### Changed

### Deprecated

### Fixed

### Removed

## 0.0.4 (2024-09-07)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion lib/cmdlang/src/command.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Param = struct

let assoc ?docv choices =
match choices with
| [] -> invalid_arg "Command.Arg.enum"
| [] -> invalid_arg "Command.Param.assoc"
| hd :: tl -> Ast.Param.Enum { docv; choices = hd :: tl }
;;

Expand Down
8 changes: 3 additions & 5 deletions lib/cmdlang/test/test__command.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
let%expect_test "Param.enum" =
let%expect_test "Param.assoc" =
let open Command.Std in
require_does_raise [%here] (fun () ->
let+ _ = Arg.named [ "a" ] (Param.assoc []) ~doc:"empty enum" in
(() [@coverage off]));
[%expect {| (Invalid_argument Command.Arg.enum) |}];
require_does_raise [%here] (fun () -> Param.assoc []);
[%expect {| (Invalid_argument Command.Param.assoc) |}];
()
;;
5 changes: 5 additions & 0 deletions test/cram/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Cmdlang cram tests

In addition to expect tests we also have cram tests. The reason we have both is that some of the code is not easy to cover from pure OCaml code.

It is not necessary that each piece of code in cmdlang be covered by both expect-tests AND cram-tests. In priority, we favor expect-tests (we prefer writing OCaml over bash).
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(executable
(name main_base)
(flags :standard -w +a-4-40-41-42-44-45-48-66 -warn-error +a)
(libraries cmdlang_to_base core_unix.command_unix test_command)
(libraries cmdlang_to_base core_unix.command_unix cram_test_command)
(instrumentation
(backend bisect_ppx))
(preprocess no_preprocessing))
1 change: 1 addition & 0 deletions test/cram/bin/base/main_base.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = Command_unix.run (Cmdlang_to_base.Translate.unit Cram_test_command.Cmd.main)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(executable
(name main_climate)
(flags :standard -w +a-4-40-41-42-44-45-48-66 -warn-error +a)
(libraries climate cmdlang_to_climate test_command)
(libraries climate cmdlang_to_climate cram_test_command)
(instrumentation
(backend bisect_ppx))
(preprocess no_preprocessing))
3 changes: 3 additions & 0 deletions test/cram/bin/climate/main_climate.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let () =
Climate.Command.run (Cmdlang_to_climate.Translate.command Cram_test_command.Cmd.main)
;;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(executable
(name main_cmdliner)
(flags :standard -w +a-4-40-41-42-44-45-48-66 -warn-error +a)
(libraries cmdlang_to_cmdliner test_command)
(libraries cmdlang_to_cmdliner cram_test_command)
(instrumentation
(backend bisect_ppx))
(preprocess no_preprocessing))
6 changes: 6 additions & 0 deletions test/cram/bin/cmdliner/main_cmdliner.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let () =
Cmdlang_to_cmdliner.run
Cram_test_command.Cmd.main
~name:Sys.argv.(0)
~version:"%%VERSION%%"
;;
61 changes: 61 additions & 0 deletions test/cram/const.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Checking the help when there are no arguments.

$ ./main_base.exe return --help
return

main_base.exe return

=== flags ===

[-help], -? . print this help text and exit


$ ./main_climate.exe return --help
Usage: ./main_climate.exe return [OPTIONS]

return

Options:
--help, -h Print help

$ ./main_cmdliner.exe return --help=plain
NAME
./main_cmdliner.exe-return - return

SYNOPSIS
./main_cmdliner.exe return [OPTION]…

COMMON OPTIONS
--help[=FMT] (default=auto)
Show this help in format FMT. The value FMT must be one of auto,
pager, groff or plain. With auto, the format is pager or plain
whenever the TERM env var is dumb or undefined.

--version
Show version information.

EXIT STATUS
./main_cmdliner.exe return exits with:

0 on success.

123 on indiscriminate errors reported on standard error.

124 on command line parsing errors.

125 on unexpected internal errors (bugs).

SEE ALSO
./main_cmdliner.exe(1)


And run it too.

$ ./main_base.exe return
()

$ ./main_climate.exe return
()

$ ./main_cmdliner.exe return
()
1 change: 0 additions & 1 deletion test/cram/deprecated/base/bin/main_base.ml

This file was deleted.

8 changes: 0 additions & 8 deletions test/cram/deprecated/base/dune

This file was deleted.

181 changes: 0 additions & 181 deletions test/cram/deprecated/base/run.t

This file was deleted.

1 change: 0 additions & 1 deletion test/cram/deprecated/climate/bin/main_climate.ml

This file was deleted.

8 changes: 0 additions & 8 deletions test/cram/deprecated/climate/dune

This file was deleted.

Loading

0 comments on commit 8ceddf0

Please sign in to comment.