example.com -> example.org
[Seppo.git] / test / t_make.ml
blobc7ee3b191c4a08b4d65b7d2e078f81aeb0e6cbba
2 include Seppo_lib
3 open Assrt
5 let _test_fkt () =
6 let bifu _rs _pqs dst _src =
7 let pfrt _oc =
9 Ok dst in
10 let ( let* ) = Result.bind in
11 let* _ = File.mkdir_p File.pDir dst in
12 dst |> File.out_channel_replace pfrt
13 in
14 let mmk rs t : (string, string) result =
15 match Make.M2.find_rule rs t with
16 | Some (r,v) ->
17 let j_src' = r.prerequisites |> List.hd in
18 let j_src = j_src' |> Make.Jig.make in
19 let src = v |> Make.Jig.paste j_src |> Option.get in
20 Logr.info (fun m -> m "%s.%s %s -> %s" "Make_test" "test_fkt.build" src t);
21 src |> bifu rs r.prerequisites t
22 | None -> Error "no rules found to make" in
23 let rs : Make.t list = [{
24 target = "%-%/index.xml";
25 prerequisites = ["app/var/db/%/%.ix"];
26 fresh = Make.Outdated;
27 command = (fun _ _ _ _ -> Error "Not implemented");
28 }] in
29 "o/p-0/index.xml"
30 |> mmk rs
31 |> Result.get_ok
32 |> Assrt.equals_string __LOC__ "o/p-0/index.xml"
34 let test_pat () =
35 let ji = "a%b%c" |> Make.Jig.make in
36 match Make.Jig.cut ji "aSomebThingc" with
37 | Some ["Some";"Thing"] as v ->
38 Option.bind v ("A_%_B_%_C" |> Make.Jig.make |> Make.Jig.paste)
39 |> Option.value ~default:"-"
40 |> Assrt.equals_string __LOC__ "A_Some_B_Thing_C"
41 | _ -> "Ouch" |> Assrt.equals_string __LOC__ ""
43 module Jig = struct
44 let test_make () =
45 let jig_src = "%/%.ix" |> Make.Jig.make in
46 let jig_dst = "%-%/index.xml" |> Make.Jig.make in
47 "o/p/2.ix"
48 |> Make.Jig.cut jig_src
49 |> Option.get
50 |> Make.Jig.paste jig_dst
51 |> Option.get
52 |> Assrt.equals_string __LOC__ "o/p-2/index.xml"
54 let test_paste () =
55 let jig = "%/%/%.ix" |> Make.Jig.make in
56 "foo/bar/baz.ix"
57 |> Make.Jig.cut jig
58 |> Option.get
59 |> Make.Jig.paste jig
60 |> Option.get
61 |> equals_string __LOC__ "foo/bar/baz.ix"
62 end
64 let _test_mk1 () =
65 Logr.info (fun m -> m "%s" __LOC__);
66 let r : Make.t = {
67 target = {|a/b-%.xml|};
68 fresh = Make.Outdated;
69 prerequisites = [{|c/d-%.ix|}];
70 command = (fun _ _r _rz t ->
71 Logr.info (fun m -> m "%s '%s'" __LOC__ t);
72 t |> Assrt.equals_string __LOC__ "a/b-37.xml";
73 Ok t);
74 } in
75 Make.M2.make [r] "a/b-37.xml"
76 |> Result.get_ok
77 |> Assrt.equals_string __LOC__ "a/b-37.xml"
79 let () =
80 (* _test_fkt (); *)
81 test_pat ();
82 Jig.test_make ();
83 Jig.test_paste ();
84 (* _test_mk1 (); *)
85 assert true