#!/bin/sh set -eu compiler=${OCAMLC:-ocamlc} rewriter=$(cd "$(dirname "$1")" && pwd)/$(basename "$1") library=$(cd "$2" && pwd) directory=$(mktemp -d) trap 'rm -rf "$directory"' EXIT HUP INT TERM cat > "$directory/unit.mli" <<'ML' type t = { colour : string; label : string } val colour : t -> string val set_colour : string -> t -> t val _colour : (t -> string) * (string -> t -> t) ML cat > "$directory/unit.ml" <<'ML' type t = { colour : string; label : string } [@@fieldglass generate] ML cat > "$directory/client.ml" <<'ML' let () = let original = Unit.{ colour = "grey"; label = "sample" } in let changed = Fieldglass.over Unit._colour ~f:String.uppercase_ascii original in assert (Unit.colour changed = "GREY"); assert (changed.Unit.label = original.Unit.label); assert (Unit.colour original = "grey") ML "$compiler" -c "$directory/unit.mli" "$compiler" -I "$directory" -ppx "$rewriter" -c "$directory/unit.ml" "$compiler" -I "$library" -I "$directory" "$library/fieldglass.cma" \ "$directory/unit.cmo" "$directory/client.ml" -o "$directory/client.byte" "$directory/client.byte"