Fix encoding of inline_tests
Encode optional fields as records where optional keys that are None will be omitted in the resultant sexp. This will match reading the keys back with field_o
This commit is contained in:
parent
019740a115
commit
4a0f4c0ff9
|
@ -89,14 +89,13 @@ module Backend = struct
|
||||||
let lib x = string (Lib.name x) in
|
let lib x = string (Lib.name x) in
|
||||||
let f x = string (Lib.name x.lib) in
|
let f x = string (Lib.name x.lib) in
|
||||||
((1, 0),
|
((1, 0),
|
||||||
record
|
record_fields
|
||||||
[ "runner_libraries", list lib (Result.ok_exn t.runner_libraries)
|
[ field "runner_libraries" (list lib)
|
||||||
; "flags" , Ordered_set_lang.Unexpanded.sexp_of_t
|
(Result.ok_exn t.runner_libraries)
|
||||||
t.info.flags
|
; field "flags" Ordered_set_lang.Unexpanded.sexp_of_t t.info.flags
|
||||||
; "generate_runner" , option Action.Unexpanded.sexp_of_t
|
; field_o "generate_runner" Action.Unexpanded.sexp_of_t
|
||||||
t.info.generate_runner
|
t.info.generate_runner
|
||||||
; "extends" , option (list f)
|
; field_o "extends" (list f) (Option.map t.extends ~f:Result.ok_exn)
|
||||||
(Option.map t.extends ~f:Result.ok_exn)
|
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
include M
|
include M
|
||||||
|
|
|
@ -104,6 +104,15 @@ module To_sexp = struct
|
||||||
string_map f
|
string_map f
|
||||||
(Hashtbl.foldi h ~init:String_map.empty ~f:(fun key data acc ->
|
(Hashtbl.foldi h ~init:String_map.empty ~f:(fun key data acc ->
|
||||||
String_map.add acc key data))
|
String_map.add acc key data))
|
||||||
|
|
||||||
|
type field = string * Usexp.t option
|
||||||
|
|
||||||
|
let field name f v = (name, Some (f v))
|
||||||
|
let field_o name f v = (name, Option.map ~f v)
|
||||||
|
|
||||||
|
let record_fields (l : field list) =
|
||||||
|
List (List.filter_map l ~f:(fun (k, v) ->
|
||||||
|
Option.map v ~f:(fun v -> List[Atom (Atom.of_string k); v])))
|
||||||
end
|
end
|
||||||
|
|
||||||
module Of_sexp = struct
|
module Of_sexp = struct
|
||||||
|
|
|
@ -46,6 +46,13 @@ module To_sexp : sig
|
||||||
include Combinators with type 'a t = 'a -> t
|
include Combinators with type 'a t = 'a -> t
|
||||||
|
|
||||||
val record : (string * sexp) list -> sexp
|
val record : (string * sexp) list -> sexp
|
||||||
|
|
||||||
|
type field
|
||||||
|
|
||||||
|
val field : string -> 'a t -> 'a -> field
|
||||||
|
val field_o : string -> 'a t-> 'a option -> field
|
||||||
|
|
||||||
|
val record_fields : field list t
|
||||||
end with type sexp := t
|
end with type sexp := t
|
||||||
|
|
||||||
module Of_sexp : sig
|
module Of_sexp : sig
|
||||||
|
|
|
@ -34,12 +34,11 @@
|
||||||
-diff-cmd
|
-diff-cmd
|
||||||
-))
|
-))
|
||||||
(generate_runner
|
(generate_runner
|
||||||
((progn
|
(progn
|
||||||
(echo "let () = print_int 41")
|
(echo "let () = print_int 41")
|
||||||
(echo "\n")
|
(echo "\n")
|
||||||
(echo "let () = print_int 42")
|
(echo "let () = print_int 42")
|
||||||
(echo "\n")
|
(echo "\n")
|
||||||
(echo "let () = print_int 43;;"))))
|
(echo "let () = print_int 43;;")))))))
|
||||||
(extends ())))))
|
|
||||||
run alias dune-file/runtest
|
run alias dune-file/runtest
|
||||||
414243
|
414243
|
||||||
|
|
Loading…
Reference in New Issue