Old version, I use custom syntax for OUnit. Now, I use the OUnit's operator directly.
.PHONY: clean integrate
-.SUBDIRS: test src util camlp4
+.SUBDIRS: test src util
clean:
rm -f *~ *.omc
+habc-scm: src/habc-scm
+ cp src/habc-scm .
+
integrate: src/habc-scm
sh example/test.sh example/*.scm
-.DEFAULT: src/habc-scm
+.DEFAULT: habc-scm
+++ /dev/null
-.PHONY: clean
-
-OCAMLINCLUDES += +camlp4
-NATIVE_ENABLED = false
-BYTE_ENABLED = true
-OCAMLPPFLAGS += -pp camlp4of
-OCAMLDEPFLAGS += $(OCAMLPPFLAGS)
-
-OCamlProgram(TestCaseCollector , TestCaseCollector)
-
-clean:
- rm -f *.cm[iox] *.o *.omc *.opt *.run *~
\ No newline at end of file
+++ /dev/null
-module Id = struct
- let name = "TestCaseCollector"
- let version = "1.0"
-end
-
-open Camlp4
-module Make(Syntax : Sig.Camlp4Syntax) = struct
- open Sig
- include Syntax
-
- let (@@) f g = f g
- let start_with pre str =
- let n =
- String.length pre in
- let m =
- String.length str in
- if n > m then
- false
- else
- pre = (String.sub str 0 n)
-
- EXTEND Gram
- GLOBAL: str_item;
- str_item: LEVEL "top"
- [[ "test"; name = LIDENT; "=" ; e = expr ->
- let s =
- Printf.sprintf "%s(line %d)" (Loc.file_name _loc) (Loc.start_line _loc) in
- <:str_item< let _ = Testtbl.add $`str:s$ $str:name$ (fun () -> $exp:e$) >>
- ]];
- END
-end
-
-let module M = Register.OCamlSyntaxExtension(Id)(Make) in
- ()
#
OCAMLFLAGS += -thread
-OCAMLPPFLAGS += -pp "camlp4o ../camlp4/TestCaseCollector.cmo"
+OCAMLPPFLAGS +=
OCAMLDEPFLAGS += $(OCAMLPPFLAGS)
################################################
OCAML_OTHER_LIBS += threads
-OCamlProgram($(PROGRAM), $(FILES) runner)
+OCamlProgram($(PROGRAM), $(FILES))
-.DEFAULT: check
+#############################################################
+#
+# PHONY Target
+#
+.DEFAULT: $(PROGRAM)
check: $(PROGRAM)
./$(PROGRAM)
-################################################
-# Dependcy rule
-
-CAMLP4FILES[] =
- ../camlp4/TestCaseCollector.cmo
-
-
-runner.h: $(addsuffix .ml, $(FILES))
- @rm -f $@
- foreach(name, $^)
- @echo open $(capitalize $(removesuffix $(name))) >> $@
-
-
-.SCANNER: scan-ocaml-%.ml: %.ml $(CAMLP4FILES)
- section
- OCAMLDEPFLAGS += -pp 'camlp4o $(CAMLP4FILES)'
- $(OCamlScanner $<)
-
clean:
rm -f $(PROGRAM) *.cm[iox] *.o *.omc *.opt *.run *~ runner.h
+++ /dev/null
-#include "runner.h"
-
-let _ =
- Testtbl.run_test ()
-
open ClosureTrans
open OUnit
+let compile_string str =
+ ClosTrans.trans @@ Lisp.compile_string str
+
let ok x y =
OUnit.assert_equal
~printer:(fun x-> (Std.dump (List.map Ast.to_string_stmt x) ^ "\n"))
open OUnit
(** util function *)
+let compile_string str =
+ ClosTrans.trans @@ Lisp.compile_string str
+
let string_of_insts xs =
let ys =
String.concat "; \n\t" @@ List.map string_of_instruction xs in
open Base
open Sexp
+open OUnit
-let assert_equal sexp str =
+let ok sexp str =
let sexp' =
parse_string str in
- OUnit.assert_equal
+ OUnit.assert_equal
~printer:(String.concat ";\n" $ List.map Sexp.to_string)
sexp
sexp'
-
-test empty =
- assert_equal [] "";
- assert_equal [] "; foo bar"
-test int =
- assert_equal [(Int 42)] "42";
- assert_equal [(Int ~-42)] "-42"
-
-test bool =
- assert_equal [(Bool true)] "#t";
- assert_equal [(Bool false)] "#f"
-
-test float =
- assert_equal [(Float 42.)] "42."
-
-test string =
- assert_equal [(String "")] "\"\"";
- assert_equal [(String "foo")] "\"foo\"";
- assert_equal [(String "foo\"x")] "\"foo\\\"x\"";
- assert_equal [(String "foo\"")] "\"foo\\\"\"";
-
-test symbol =
- assert_equal [(String "foo")] "\"foo\"";
- assert_equal [(String "+")] "\"+\"";
- assert_equal [(Symbol ".")] "."
-
-test add =
- assert_equal [List [Symbol "+";Int 1; Int 2]] "(+ 1 2)"
-
-test list =
- assert_equal [List [Symbol "print";String "hello"]] "(print \"hello\")"
-
-test bracket_list =
- assert_equal [List [Symbol "print";String "hello"]] "[print \"hello\"]"
-
-test quote =
- assert_equal [List [Symbol "quote";Symbol "hello"]] "(quote hello)";
- assert_equal [List [Symbol "quote";Symbol "hello"]] "'hello";
+let _ =
+ ("S expression module test" >::: [
+ "empty" >::
+ (fun () ->
+ ok [] "";
+ ok [] "; foo bar");
+ "int" >::
+ (fun () ->
+ ok [(Int 42)] "42";
+ ok [(Int ~-42)] "-42");
+ "bool" >::
+ (fun () ->
+ ok [(Bool true)] "#t";
+ ok [(Bool false)] "#f");
+ "float" >::
+ (fun () ->
+ ok [(Float 42.)] "42.";
+ ok [(Float 42.5)] "42.5");
+ "string" >::
+ (fun () ->
+ ok [(String "")] "\"\"";
+ ok [(String "foo")] "\"foo\"";
+ ok [(String "foo\"x")] "\"foo\\\"x\"";
+ ok [(String "foo\"")] "\"foo\\\"\"");
+ "symbol" >::
+ (fun () ->
+ ok [(String "foo")] "\"foo\"";
+ ok [(String "+")] "\"+\"";
+ ok [(Symbol ".")] ".");
+ "+" >::
+ (fun () ->
+ ok [List [Symbol "+";Int 1; Int 2]] "(+ 1 2)");
+ "call" >::
+ (fun () ->
+ ok [List [Symbol "print";String "hello"]] "(print \"hello\")");
+ "bracket" >::
+ (fun () ->
+ ok [List [Symbol "print";String "hello"]] "[print \"hello\"]");
+ "quote" >::
+ (fun () ->
+ ok [List [Symbol "quote";Symbol "hello"]] "(quote hello)";
+ ok [List [Symbol "quote";Symbol "hello"]] "'hello")
+ ]) +> run_test_tt
open Base
-let assert_equal ?(msg="") =
- OUnit.assert_equal ~msg:msg ~printer:Std.dump
-
let ok ?(msg="") =
OUnit.assert_equal ~msg:msg ~printer:Std.dump
let assert_raises =
OUnit.assert_raises
-let compile_string str =
- ClosTrans.trans @@ Lisp.compile_string str
+