File: TestOCamlbuild.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 (121 lines) | stat: -rw-r--r-- 5,218 bytes parent folder | download
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
(******************************************************************************)
(* 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              *)
(******************************************************************************)

open OUnit2
open TestCommon
open OASISPlugin
open OASISFileTemplate
open TestFullUtils


let tests =
  "Plugin OCamlbuild" >:::
  [
    "missing-source" >::
    (fun test_ctxt ->
       let dn =
         in_testdata_dir test_ctxt ["TestOCamlbuild"; "missing-source"]
       in
       let fn = Filename.concat dn OASISParse.default_oasis_fn in
       let pkg = OASISParse.from_file ~ctxt:oasis_ctxt fn in
       let ctxt, _ =
         with_bracket_chdir test_ctxt dn
           (fun test_ctxt ->
              BaseSetup.of_package ~setup_update:false OASISSetupUpdate.NoUpdate pkg)
       in
       let () =
         assert_bool "No error during generation." (not ctxt.error)
       in
       let tmpl = find "test.mllib" ctxt.files in
         match tmpl.body with
           | Body lst | BodyWithDigest (_, lst) ->
               assert_equal
                 ~printer:(fun lst ->
                             String.concat ", "
                               (List.map (Printf.sprintf "%S") lst))
                 ["A"; "B"; "C"]
                 (List.sort String.compare lst);
           | NoBody ->
               assert_failure "No content for test.mllib.");

    "set-ocamlfind" >::
    (fun test_ctxt ->
       let t =
         setup_test_directories test_ctxt
           ~is_native:(is_native test_ctxt)
           ~native_dynlink:(native_dynlink test_ctxt)
           (in_testdata_dir test_ctxt ["TestOCamlbuild"; "set-ocamlfind"])
       in
       let () =
         skip_if
           (OASISVersion.version_compare_string t.ocaml_version "3.12.1" < 0)
           "OCaml >= 3.12.1 needed."
       in
       let real_ocamlfind = FileUtil.which "ocamlfind" in
       let fake_ocamlfind =
         Filename.concat t.bin_dir (Filename.basename real_ocamlfind)
       in
       let extra_env = ["REAL_OCAMLFIND", real_ocamlfind] in
       let () =
         oasis_setup test_ctxt t;
         FileUtil.cp [fake_ocamlfind_exec test_ctxt] fake_ocamlfind;
         Unix.chmod fake_ocamlfind 0o755;
         run_ocaml_setup_ml ~with_ocaml_env:true ~extra_env test_ctxt t
           ["-configure"]
       in
       let env = BaseEnvLight.load ~filename:(in_src_dir t "setup.data") () in
       let () =
         assert_equal ~printer:(Printf.sprintf "%S")
           fake_ocamlfind
           (BaseEnvLight.var_get "ocamlfind" env);
         run_ocaml_setup_ml ~extra_env test_ctxt t ["-build"]
       in
       let build_log =
         file_content (in_src_dir t (Filename.concat "_build" "_log"))
       in
         logf test_ctxt `Info "%s" build_log;
         List.iter
           (fun line ->
              if OASISString.contains ~what:"ocamlfind" line then
                assert_bool
                  (Printf.sprintf
                     "line %S should starts with %S"
                     line fake_ocamlfind)
                  (OASISString.starts_with ~what:fake_ocamlfind line))
           (OASISString.nsplit build_log '\n'));

    "use-ocamlfind" >::
    (fun test_ctxt ->
       let t =
         setup_test_directories test_ctxt
           ~is_native:(is_native test_ctxt)
           ~native_dynlink:(native_dynlink test_ctxt)
           (in_testdata_dir test_ctxt ["TestOCamlbuild"; "use-ocamlfind"])
       in
       oasis_setup test_ctxt t;
       run_ocaml_setup_ml ~check_output:true test_ctxt t
         ["-configure"; "--enable-docs"];
       run_ocaml_setup_ml ~check_output:true test_ctxt t
         ["-build"];
       run_ocaml_setup_ml ~check_output:true test_ctxt t
         ["-doc"]);
  ]