File: TestMETA.ml

package info (click to toggle)
oasis 0.4.4-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,432 kB
  • ctags: 2,908
  • sloc: ml: 31,357; makefile: 166; sh: 75; ansic: 48; awk: 26
file content (263 lines) | stat: -rw-r--r-- 8,251 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
(******************************************************************************)
(* OASIS: architecture for building OCaml libraries and applications          *)
(*                                                                            *)
(* Copyright (C) 2011-2013, Sylvain Le Gall                                   *)
(* Copyright (C) 2008-2011, OCamlCore SARL                                    *)
(*                                                                            *)
(* This library is free software; you can redistribute it and/or modify it    *)
(* under the terms of the GNU Lesser General Public License as published by   *)
(* the Free Software Foundation; either version 2.1 of the License, or (at    *)
(* your option) any later version, with the OCaml static compilation          *)
(* exception.                                                                 *)
(*                                                                            *)
(* This library is distributed in the hope that it will be useful, but        *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *)
(* or FITNESS FOR A PARTICULAR PURPOSE. See the file COPYING for more         *)
(* details.                                                                   *)
(*                                                                            *)
(* You should have received a copy of the GNU Lesser General Public License   *)
(* along with this library; if not, write to the Free Software Foundation,    *)
(* Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA              *)
(******************************************************************************)


(** Test plugin META
    @author Sylvain Le Gall
  *)


open OUnit2
open TestCommon
open Fl_metascanner
open OASISTypes
open OASISFindlib


let tests =
  let test_of_vector (nm, oasis_str, pkg_tests) =
    nm >::
    (fun test_ctxt ->
       let fn, _ =
         bracket_tmpfile ~prefix:"oasis-meta-" ~suffix:".meta" test_ctxt
       in
       (* Parse string to get OASIS package *)
       let pkg =
         OASISParse.from_string
           ~ctxt:oasis_ctxt
           oasis_str
       in

       (* Generate META file *)
       let groups, findlib_name_of_library_name, _ =
         OASISFindlib.findlib_mapping pkg
       in
       let write_meta fndlb_nm =
         let grp =
           try
             (* Find the package in all group *)
             List.find
               (fun grp ->
                  match grp with
                    | Container (nm, _)
                    | Package (nm, _, _, _, _) -> nm = fndlb_nm)
               groups
           with Not_found ->
             failwith
               (Printf.sprintf
                  "Cannot find group of name '%s'"
                  fndlb_nm)
         in
         let chn =
           open_out fn
         in
         let fmt =
           Format.formatter_of_out_channel chn
         in
         let root_t =
           let root_cs, _, _ =
             root_of_group grp
           in
             METAPlugin.generator root_cs.cs_data
         in
           METAPlugin.pp_print_meta
             pkg root_t findlib_name_of_library_name fmt grp;
           close_out chn
       in

       (* Check META file *)
       let rec find_pkg_defs pkg_expr =
         function
           | hd :: tl ->
               begin
                 try
                   find_pkg_defs
                     (List.assoc hd pkg_expr.pkg_children)
                     tl
                 with Not_found ->
                   failwith
                     (Printf.sprintf
                        "Could not find subpackage component '%s'"
                        hd)
               end
           | [] ->
               pkg_expr.pkg_defs
       in
       let Some (_, _) | None =
         List.fold_left
           (fun former_meta (pkg_name, var, preds, res) ->
              let pkg_root, pkg_paths =
                match OASISString.nsplit pkg_name '.' with
                  | hd :: tl -> hd, tl
                  | _ -> assert(false)
              in
              let pkg_expr =
                match former_meta with
                  | Some (nm, pkg_expr) when nm = pkg_root ->
                      pkg_expr
                  | _ ->
                      begin
                        let chn =
                          write_meta pkg_root;
                          dbug_file_content test_ctxt fn;
                          open_in fn
                        in
                        let res =
                          parse chn
                        in
                          close_in chn;
                          res
                      end
              in
              let pkg_defs =
                find_pkg_defs pkg_expr pkg_paths
              in
                begin
                  let msg =
                    Printf.sprintf
                      "%s %s(%s)"
                      pkg_name
                      var
                      (String.concat "," preds)
                  in
                    try
                      assert_equal
                        ~msg
                        ~printer:(fun s -> s)
                        res
                        (lookup var preds pkg_defs)
                    with Not_found ->
                      failwith
                        (Printf.sprintf
                           "Cannot find META variable '%s'"
                           msg)
                end;
                Some (pkg_root, pkg_expr))
           None
           pkg_tests
       in
         ())
  in

    "META" >:::
    (List.map test_of_vector
       [
(* TODO: move that to files. *)
         "2-subpackages",
         "\
OASISFormat:  0.1
Name:         ocaml-data-notation
Version:      0.0.1
Synopsis:     store data using OCaml notation
License:      LGPL with OCaml linking exception
Authors:      me

Library odn
  Path:    src
  Modules: ODN

Library pa_odn
  Path:              src
  Modules:           Pa_odn
  FindlibParent:     odn
  XMETADescription:  Syntax extension for odn
  FindlibContainers: with
  FindlibName:       syntax

Library pa_noodn
  Path:              src
  Modules:           Pa_noodn
  FindlibParent:     odn
  XMETADescription:  Syntax extension that removes 'with odn'
  FindlibContainers: without
  FindlibName:       syntax",
         [
           "odn", "archive", ["byte"], "odn.cma";
           "odn.with.syntax", "archive", ["byte"], "pa_odn.cma";

           "odn.without.syntax", "description", [],
           "Syntax extension that removes 'with odn'";
         ];

         "virtual-root",
         "\
OASISFormat:  0.1
Name:         ocaml-data-notation
Version:      0.0.1
Synopsis:     store data using OCaml notation
License:      LGPL with OCaml linking exception
Authors:      me

Library odn
  Path:    src
  Modules: ODN
  FindlibContainers:  myext.toto",
         [
           "myext.toto.odn", "archive", ["byte"], "odn.cma";
         ];

         "syntax",
         "\
OASISFormat:  0.1
Name:         ocaml-data-notation
Version:      0.0.1
Synopsis:     store data using OCaml notation
License:      LGPL with OCaml linking exception
Authors:      me

Library odn
  Path:    src
  Modules: ODN

Library pa_odn
  Path:             src
  Modules:          Pa_odn
  FindlibParent:    odn
  XMETADescription: Syntax extension for odn
  XMETAType:        syntax
  XMETARequires:    type-conv.syntax, camlp4
  FindlibName:      syntax",
         [
           "odn.syntax", "archive", ["syntax"; "preprocessor"], "pa_odn.cma";
           "odn.syntax", "archive", ["syntax"; "toploop"], "pa_odn.cma";
           "odn.syntax", "requires", [], "type-conv.syntax camlp4";
         ];

         "long-synopsis",
         "\
OASISFormat:  0.1
Name:         ocaml-data-notation
Version:      0.0.1
Synopsis:     store data using OCaml notation with a very very very very very \
                                                     very very long synopsis
              and with line breaks
License:      LGPL with OCaml linking exception
Authors:      me

Library odn
  Path:    src
  Modules: ODN",
         [
           "odn", "archive", ["byte"], "odn.cma";
         ];

       ])