Browse Source

Apply reviews, create test directory

pull/41/head
Dario Pinto 3 years ago
parent
commit
2c2fa19eda
  1. 60
      src/check_directory.ml
  2. 15
      src/html.ml
  3. 9
      src/orel.ml
  4. 2
      src/orel_opam_repo.ml
  5. 11
      src/raw.ml
  6. 10
      src/utils.ml
  7. 0
      test/content_tests.ml
  8. 0
      test/dir_tests.ml
  9. 3
      test/dune
  10. 0
      test/existence_tests.ml
  11. 1
      test/orel_tests.ml
  12. 0
      test/repo_tests.ml

60
src/check_directory.ml

@ -39,44 +39,36 @@ let opamlint () =
if current path satisfies minimum requirements, when all sub directories
have been traversed, or predicate is satified, it returns true. *)
let rec check_dir_for_ml_and_dune in_path =
let content =
match Bos.OS.Dir.contents ~dotfiles:true ~rel:true in_path with
| Error _e ->
Utils.error
( "Cant list contents of subdirectory " ^ Fpath.to_string in_path
^ ". (Check_directory.check_dir_for_ml_and_dune)" )
| Ok contents -> contents
in
if
Check_existence.has_file "dune" content
&& List.exists (fun p -> Fpath.has_ext ".ml" p) content
then
true
else
let contents =
List.filter
(fun x ->
match Bos.OS.Dir.must_exist x with
| Ok _p -> true
| Error _e -> false )
content
in
let results = List.map check_dir_for_ml_and_dune contents in
List.exists (fun x -> x) results
match Bos.OS.Dir.contents ~dotfiles:true ~rel:true in_path with
| Error _e -> false
| Ok contents ->
let content = contents in
if
Check_existence.has_file "dune" content
&& List.exists (fun p -> Fpath.has_ext ".ml" p) content
then
true
else
let contents =
List.filter
(fun x ->
match Bos.OS.Dir.must_exist x with
| Ok _p -> true
| Error _e -> false )
content
in
let results = List.map check_dir_for_ml_and_dune contents in
List.exists (fun x -> x) results
(** [check_dir_for_mld_and_dune in_path] takes a Fpath.t returns true if minimum
requirements are met, false otherwise. *)
let check_dir_for_mld_and_dune in_path =
let content =
match Bos.OS.Dir.contents ~dotfiles:true ~rel:true in_path with
| Error _e ->
Utils.error
( "Cant list contents of subdirectory " ^ Fpath.to_string in_path
^ ". (Check_directory.check_dir_for_ml_and_dune)" )
| Ok contents -> contents
in
Check_existence.has_file "dune" content
&& Check_existence.has_file "index.mld" content
match Bos.OS.Dir.contents ~dotfiles:true ~rel:true in_path with
| Error _e -> false
| Ok contents ->
let content = contents in
Check_existence.has_file "dune" content
&& Check_existence.has_file "index.mld" content
(** [minimum_requirement_of directory requirements] takes a directory, converts
it to type [Fpath.t] and applies a given [requirements] function to it. *)

15
src/html.ml

@ -1,16 +1,11 @@
let result_to_html fmt (results, verbose) =
let result_to_html fmt results =
let score, max_score =
List.fold_left
(fun (acc_score, acc_max_score) r ->
match r with
| Ok (msg, max_score) ->
if verbose then (
Format.fprintf fmt "-- %s (%d/%d)<br />" msg max_score max_score;
(acc_score + max_score, acc_max_score + max_score)
) else (
Format.ifprintf fmt "-- %s (%d/%d)<br />" msg max_score max_score;
(acc_score + max_score, acc_max_score + max_score)
)
Utils.log fmt "-- %s (%d/%d)<br />" msg max_score max_score;
(acc_score + max_score, acc_max_score + max_score)
| Error (msg, score, max_score) ->
Format.fprintf fmt "-- %s (%d/%d)<br />" msg score max_score;
(acc_score + score, acc_max_score + max_score) )
@ -18,7 +13,7 @@ let result_to_html fmt (results, verbose) =
in
Format.fprintf fmt "Final score: %d / %d<br />" score max_score
let output fmt result verbose =
let output fmt result =
Format.fprintf fmt
{|<!DOCTYPE html>
<html lang="en">
@ -39,4 +34,4 @@ let output fmt result verbose =
</body>
</html>
|}
result_to_html (result, verbose)
result_to_html result

9
src/orel.ml

@ -12,9 +12,9 @@ let html =
let verbose =
let doc =
"By default, orel will only print messages of unsatisfied checks.\n\
\ With flag, all check messages are printed."
\ With this flag, all check messages are printed."
in
Arg.(value & flag & info [ "verbose" ] ~docv:"VERBOSE" ~doc)
Arg.(value & flag & info [ "verbose"; "v" ] ~docv:"VERBOSE" ~doc)
let info =
let doc = "Repository checker, outputs results to HTML format or raw." in
@ -26,10 +26,11 @@ let info =
let check verbose repo html =
let results = Check.check repo in
Utils.set_verbose verbose;
if html then
Html.output Format.std_formatter results verbose
Html.output Format.std_formatter results
else
Raw.output Format.std_formatter results verbose
Raw.output Format.std_formatter results
let orel_t = Term.(const check $ verbose $ repo $ html)

2
src/orel_opam_repo.ml

@ -106,5 +106,5 @@ let () =
(fun (p, url) ->
Format.printf "======== CHECKING PACKAGE %s ========@." p;
let results = Orel.Check.check url in
Orel.Raw.output Format.std_formatter results true )
Orel.Raw.output Format.std_formatter results )
packages

11
src/raw.ml

@ -1,16 +1,11 @@
let output fmt results verbose =
let output fmt results =
let score, max_score =
List.fold_left
(fun (acc_score, acc_max_score) r ->
match r with
| Ok (msg, max_score) ->
if verbose then (
Format.fprintf fmt "-- %s (%d/%d)@." msg max_score max_score;
(acc_score + max_score, acc_max_score + max_score)
) else (
Format.ifprintf fmt "-- %s (%d/%d)@." msg max_score max_score;
(acc_score + max_score, acc_max_score + max_score)
)
Utils.log fmt "-- %s (%d/%d)@." msg max_score max_score;
(acc_score + max_score, acc_max_score + max_score)
| Error (msg, score, max_score) ->
Format.fprintf fmt "-- %s (%d/%d)@." msg score max_score;
(acc_score + score, acc_max_score + max_score) )

10
src/utils.ml

@ -1,3 +1,13 @@
let error msg =
Format.eprintf "error: %s @." msg;
exit 1
let verbose = ref false
let set_verbose v = verbose := v
let log fmt =
if !verbose then
Format.fprintf fmt
else
Format.ifprintf fmt

0
test/content_tests.ml

0
test/dir_tests.ml

3
test/dune

@ -0,0 +1,3 @@
(test
(name orel_tests)
(libraries orel))

0
test/existence_tests.ml

1
test/orel_tests.ml

@ -0,0 +1 @@
let () = Format.printf "This will hold all calls to orel's test suite.@."

0
test/repo_tests.ml

Loading…
Cancel
Save