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

Add absent status #485

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions src/grader/learnocaml_report.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) ->
Expand Down Expand Up @@ -158,6 +158,7 @@ let enc =
else Failure) ;
case
(string_enum [ "failure", Failure ;
"absent", Absent ;
"warning", Warning ;
"informative", Informative ;
"important", Important ])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -561,6 +563,7 @@ let print ppf items =
| Section (text, contents) -> Format.fprintf ppf "@[<v 2>@[<hv>%a@]@,%a@]" print_text text print_report contents
| SectionMin (text, contents, min) -> Format.fprintf ppf "@[<v 2>@[<hv>%a@ %a@]@,%a@]" print_text text print_min min print_report contents
| Message (text, Failure) -> Format.fprintf ppf [%if"@[<v 2>Failure: %a@]"] print_text text
| Message (text, Absent) -> Format.fprintf ppf [%if"@[<v 2>Absent: %a@]"] print_text text
| Message (text, Warning) -> Format.fprintf ppf [%if"@[<v 2>Warning: %a@]"] print_text text
| Message (text, Informative) -> Format.fprintf ppf "@[<v 2>%a@]" print_text text
| Message (text, Important) -> Format.fprintf ppf [%if"@[<v 2>Important: %a@]"] print_text text
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions src/grader/learnocaml_report.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/grader/test_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 () ->
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) ]
Expand Down Expand Up @@ -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 ;
Expand All @@ -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 ;
Expand All @@ -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) ;
Expand Down
6 changes: 4 additions & 2 deletions src/main/learnocaml_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ()
Expand Down