Permalink
Browse files

move Base64 tests to lib_test and improve Makefile performance

  • Loading branch information...
avsm committed Jan 7, 2012
1 parent be748e7 commit 1ca69612c216aba814d25d589745aa83d127f762
Showing with 393 additions and 59 deletions.
  1. +4 −0 .gitignore
  2. +24 −13 Makefile
  3. +19 −0 _oasis
  4. +15 −1 _tags
  5. +0 −14 lib/base64.ml
  6. +58 −0 lib_test/test_base64.ml
  7. +12 −1 myocamlbuild.ml
  8. +261 −30 setup.ml
View
@@ -2,3 +2,7 @@
_build/
setup.data
setup.log
+setup.bin
+*.docdir
+*.native
+*.byte
View
@@ -1,22 +1,33 @@
.PHONY: all clean install build
-all: build doc
+all: build test doc
-setup.data:
- ocaml setup.ml -configure
+NAME=cohttp
-build: setup.data
- ocaml setup.ml -build
+export OCAMLRUNPARAM=b
-doc: setup.data
- ocaml setup.ml -doc
+setup.bin: setup.ml
+ ocamlopt.opt -o $@ $< || ocamlopt -o $@ $< || ocamlc -o $@ $<
+ rm -f setup.cmx setup.cmi setup.o setup.cmo
-install:
- ocaml setup.ml -install
+setup.data: setup.bin
+ ./setup.bin -configure
-reinstall:
- ocamlfind remove cohttp || true
- ocaml setup.ml -reinstall
+build: setup.data setup.bin
+ ./setup.bin -build
+
+doc: setup.data setup.bin
+ ./setup.bin -doc
+
+install: setup.bin
+ ./setup.bin -install
+
+test: setup.bin build
+ ./setup.bin -test
+
+reinstall: setup.bin
+ ocamlfind remove $(NAME) || true
+ ./setup.bin -reinstall
clean:
ocamlbuild -clean
- rm -f setup.data setup.log
+ rm -f setup.data setup.log setup.bin
View
19 _oasis
@@ -20,3 +20,22 @@ Document cohttp
BuildTools+: ocamldoc
XOCamlbuildPath: lib
XOCamlbuildLibraries: cohttp
+
+Flag tests
+ Description: Build and run tests
+ Default: true
+
+Executable test_base64
+ Path: lib_test
+ MainIs: test_base64.ml
+ Build$: flag(tests)
+ Custom: true
+ CompiledObject: best
+ Install: false
+ BuildDepends: cohttp,oUnit (>= 1.0.2)
+
+Test test_base64
+ Run$: flag(tests)
+ Command: $test_base64
+ WorkingDirectory: lib_test
+
View
16 _tags
@@ -1,5 +1,5 @@
# OASIS_START
-# DO NOT EDIT (digest: 3bc0cbc4439d58dac70e44f3fc2c2529)
+# DO NOT EDIT (digest: fdc4899b5a37c52dcab0e63b34081e56)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
@@ -41,6 +41,20 @@
<lib/*.ml{,i}>: pkg_lwt.unix
<lib/*.ml{,i}>: pkg_lwt.syntax
<lib/*.ml{,i}>: pkg_lwt
+# Executable test_base64
+<lib_test/test_base64.{native,byte}>: use_cohttp
+<lib_test/test_base64.{native,byte}>: pkg_regexp
+<lib_test/test_base64.{native,byte}>: pkg_oUnit
+<lib_test/test_base64.{native,byte}>: pkg_lwt.unix
+<lib_test/test_base64.{native,byte}>: pkg_lwt.syntax
+<lib_test/test_base64.{native,byte}>: pkg_lwt
+<lib_test/*.ml{,i}>: use_cohttp
+<lib_test/*.ml{,i}>: pkg_regexp
+<lib_test/*.ml{,i}>: pkg_oUnit
+<lib_test/*.ml{,i}>: pkg_lwt.unix
+<lib_test/*.ml{,i}>: pkg_lwt.syntax
+<lib_test/*.ml{,i}>: pkg_lwt
+<lib_test/test_base64.{native,byte}>: custom
# OASIS_STOP
<lib/*>: syntax_camlp4o
<lib/*>: pkg_lwt.syntax
View
@@ -66,17 +66,3 @@ let encode x =
output.[String.length output - i] <- '=';
done;
output
-
-let test x =
- let x' = encode x in
- let x'' = decode x' in
- if x <> x''
- then failwith (Printf.sprintf "Original: '%s'; encoded = '%s'; decoded = '%s'" x x' x'')
-
-let tests = [ "hello";
- "this is a basic test"; "1"; "22"; "333"; "4444"; "5555";
- "\000"; "\000\000"; "\000\000\000"; "\000\000\000\000" ]
-
-(*
-let _ = List.iter test tests
-*)
View
@@ -0,0 +1,58 @@
+(*
+ * Copyright (c) 2010 Thomas Gazagnaire <thomas@gazagnaire.org>
+ * Copyright (c) 2012 Anil Madhavapeddy <anil@recoil.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ *)
+
+open OUnit
+open Printf
+
+let test x () =
+ let x' = Cohttp.Base64.encode x in
+ let x'' = Cohttp.Base64.decode x' in
+ assert_equal ~printer:(fun x -> x) x x''
+
+let tests = [
+ "hello";
+ "this is a basic test"; "1"; "22"; "333"; "4444"; "5555";
+ "\000"; "\000\000"; "\000\000\000"; "\000\000\000\000"
+]
+
+let test_cases = List.map (fun s -> s >:: (test s)) tests
+
+(* Returns true if the result list contains successes only.
+ Copied from oUnit source as it isnt exposed by the mli *)
+let rec was_successful =
+ function
+ | [] -> true
+ | RSuccess _::t
+ | RSkip _::t ->
+ was_successful t
+ | RFailure _::_
+ | RError _::_
+ | RTodo _::_ ->
+ false
+
+let _ =
+ let suite = "Base64" >::: test_cases in
+ let verbose = ref false in
+ let set_verbose _ = verbose := true in
+ Arg.parse
+ [("-verbose", Arg.Unit set_verbose, "Run the test in verbose mode.");]
+ (fun x -> raise (Arg.Bad ("Bad argument : " ^ x)))
+ ("Usage: " ^ Sys.argv.(0) ^ " [-verbose]");
+ if not (was_successful (run_test_tt ~verbose:!verbose suite)) then
+ exit 1
+
View
@@ -462,4 +462,15 @@ let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
# 464 "myocamlbuild.ml"
(* OASIS_STOP *)
-Ocamlbuild_plugin.dispatch dispatch_default;;
+open Ocamlbuild_plugin
+
+let () =
+ dispatch
+ (fun hook ->
+ dispatch_default hook;
+ match hook with
+ | After_rules ->
+ flag [ "ocaml"; "compile"; "lwt_debug" ] & S[A"-ppopt"; A"-lwt-debug"];
+ flag [ "ocaml"; "ocamldep"; "lwt_debug" ] & S[A"-ppopt"; A"-lwt-debug"];
+ | _ -> ()
+ )
Oops, something went wrong.

0 comments on commit 1ca6961

Please sign in to comment.