diff --git a/src/grader/learnocaml_report.ml b/src/grader/learnocaml_report.ml index 95b979340..800d602ff 100644 --- a/src/grader/learnocaml_report.ml +++ b/src/grader/learnocaml_report.ml @@ -78,7 +78,7 @@ and item = and status = | Success of int | Penalty of int | Failure - | Warning | Informative | Important + | Warning | Informative | Important | Absent and text = inline list @@ -100,7 +100,7 @@ let result items = | Success n -> (n, false) | Penalty n -> (-n, true) | Failure -> (0, true) - | Warning | Informative | Important -> (0, false) end + | Warning | Informative | Important | Absent -> (0, false) end | Section (_title, contents) -> do_report contents | SectionMin (_title, contents, min) -> @@ -158,6 +158,7 @@ let enc = else Failure) ; case (string_enum [ "failure", Failure ; + "absent", Absent ; "warning", Warning ; "informative", Informative ; "important", Important ]) @@ -220,6 +221,7 @@ let format items = | Penalty n -> (-n, true), "warning", Some ("-" ^ string_of_int n ^ " pts") | Failure -> (0, true), "failure", Some "0 pt" + | Absent -> (0, false), "absent", None | Warning -> (0, false), "warning", None | Informative -> (0, false), "informative", None | Important -> (0, false), "important", None in @@ -561,6 +563,7 @@ let print ppf items = | Section (text, contents) -> Format.fprintf ppf "@[@[%a@]@,%a@]" print_text text print_report contents | SectionMin (text, contents, min) -> Format.fprintf ppf "@[@[%a@ %a@]@,%a@]" print_text text print_min min print_report contents | Message (text, Failure) -> Format.fprintf ppf [%if"@[Failure: %a@]"] print_text text + | Message (text, Absent) -> Format.fprintf ppf [%if"@[Absent: %a@]"] print_text text | Message (text, Warning) -> Format.fprintf ppf [%if"@[Warning: %a@]"] print_text text | Message (text, Informative) -> Format.fprintf ppf "@[%a@]" print_text text | Message (text, Important) -> Format.fprintf ppf [%if"@[Important: %a@]"] print_text text @@ -621,6 +624,8 @@ let success ~points ~message = Message (split_text message, Success points) let failure ~message = Message (split_text message, Failure) +let absent ~message = + Message (split_text message, Absent) let message ~message = Message (split_text message, Informative) let info ~message = diff --git a/src/grader/learnocaml_report.mli b/src/grader/learnocaml_report.mli index 0427cfcdd..5a958461a 100644 --- a/src/grader/learnocaml_report.mli +++ b/src/grader/learnocaml_report.mli @@ -22,6 +22,7 @@ and status = | Warning (** A student error without influence on the grade *) | Informative (** A message for the student *) | Important (** An important message *) + | Absent (** With missed function *) and text = inline list @@ -58,6 +59,7 @@ val enc : t Json_encoding.encoding (** {2 Learnocaml_report building combinators} *) val failure : message:string -> item +val absent : message:string -> item val success : points:int -> message:string -> item val warning : message:string -> item val message : message:string -> item diff --git a/src/grader/test_lib.ml b/src/grader/test_lib.ml index 1e6690eec..7f491eb7d 100644 --- a/src/grader/test_lib.ml +++ b/src/grader/test_lib.ml @@ -799,7 +799,7 @@ module Make | [] -> [ Message ([ Text "I could not find " ; Code name ; Text "." ; Break ; Text "Check that it is defined as a simple " ; Code "let" ; - Text " at top level." ], Failure) ] + Text " at top level." ], Absent) ] | { pstr_desc = Pstr_value (_, bds); _ } :: rest -> let rec findvar = function | [] -> findlet rest @@ -826,7 +826,7 @@ module Make Text "is compatible with " ; Code exp ], Informative) ; match Introspection.compatible_type exp ("Code." ^ got) with | Introspection.Absent -> - Message ([ Text "Type not found" ], Failure) + Message ([ Text "Type not found" ], Absent) | Introspection.Incompatible msg -> Message ([ Text msg ], Failure) | Introspection.Present () -> @@ -839,7 +839,7 @@ module Make let path, _ = Env.find_type_by_name lid !Toploop.toplevel_env in let _ = Env.find_type path !Toploop.toplevel_env in true, [ Message ( [ Text "Type" ; Code name ; Text "found" ], Success score ) ] - with Not_found -> false, [ Message ( [ Text "type" ; Code name ; Text "not found" ], Failure ) ] + with Not_found -> false, [ Message ( [ Text "type" ; Code name ; Text "not found" ], Absent ) ] let abstract_type ?(allow_private = true) ?(score = 5) name = let open Learnocaml_report in @@ -853,7 +853,7 @@ module Make true, [ Message ([Text "Type" ; Code name ; Text "is private, I'll accept that :-)." ], Success score) ] | { Types. type_kind = _; _ } -> false, [ Message ([Text "Type" ; Code name ; Text "should be abstract!" ], Failure) ] - with Not_found -> false, [ Message ( [Text "Type" ; Code name ; Text "not found." ], Failure) ] + with Not_found -> false, [ Message ( [Text "Type" ; Code name ; Text "not found." ],Absent) ] let test_student_code ty cb = let open Learnocaml_report in @@ -869,7 +869,7 @@ module Make match Introspection.get_value ("Code." ^ name) ty with | Introspection.Present v -> cb v | Introspection.Absent -> - [ Message ([ Text "Module" ; Code name ; Text "not found." ], Failure) ] + [ Message ([ Text "Module" ; Code name ; Text "not found." ], Absent) ] | Introspection.Incompatible msg -> [ Message ([ Text "Module" ; Code name ; Text "doesn't match the expected signature." ; Break ; Code msg (* TODO: hide or fix locations *) ], Failure) ] @@ -1231,7 +1231,7 @@ module Make `Found (display_name, msg, v) | Introspection.Absent -> `Unbound - (name, [ Message ([ Text "Cannot find " ; Code display_name ], Failure) ]) + (name, [ Message ([ Text "Cannot find " ; Code display_name ], Absent) ]) | Introspection.Incompatible msg -> `Unbound (name, [ Message ([ Text "Found" ; Code display_name ; @@ -1249,7 +1249,7 @@ module Make `Found (name, msg, v) | Introspection.Absent -> `Unbound - (name, [ Message ([ Text "Cannot find " ; Code name ], Failure) ]) + (name, [ Message ([ Text "Cannot find " ; Code name ], Absent) ]) | Introspection.Incompatible msg -> `Unbound (name, [ Message ([ Text "Found" ; Code name ; @@ -1265,7 +1265,7 @@ module Make | Introspection.Absent -> `Unbound (name, [ Message ([ Text "Looking for " ; Code name ], Informative) ; - Message ([ Text "Solution not found!" ], Failure) ]) + Message ([ Text "Solution not found!" ], Absent) ]) | Introspection.Incompatible msg -> `Unbound (name, [ Message ([ Text "Looking for " ; Code name ], Informative) ; diff --git a/src/main/learnocaml_client.ml b/src/main/learnocaml_client.ml index 1b3496bf8..439ce639e 100644 --- a/src/main/learnocaml_client.ml +++ b/src/main/learnocaml_client.ml @@ -417,7 +417,7 @@ let console_report ?(verbose=false) ex report = (List.for_all @@ function | Section (_, report) | SectionMin (_, report, _) -> all_good report | Message (_, (Success _ | Penalty _ - | Informative | Warning | Important)) -> true + | Informative | Warning | Important | Absent)) -> true | Message (_, Failure) -> false) report in @@ -447,7 +447,9 @@ let console_report ?(verbose=false) ex report = | Message (text, Informative) -> format_text text | Message (text, Important) -> - color [`Bg `Cyan] "[important]" ^ " " ^ format_text text + color [`Bg `Cyan] "[important]" ^ " " ^ format_text text + | Message (text, Absent) -> + color [`Bg `White] "[ absent ]" ^ " " ^ format_text text in List.iter (fun i -> print_endline (format_item i)) report; print_newline ()