Stefan pushed to branch master at Stefan / Typer
Commits: a90614fc by Pierre Delaunay at 2016-01-18T11:54:44-05:00 new make file
- - - - - 908e455e by Pierre Delaunay at 2016-01-21T09:58:20-05:00 new make file
- - - - - f509e8a2 by Pierre Delaunay at 2016-01-22T10:42:40-05:00 Merge remote-tracking branch 'origin/master' into work
- - - - - 6cb6f695 by Pierre Delaunay at 2016-01-22T13:34:33-05:00 utest_main + Makefile update
- - - - - 482a5aab by Pierre Delaunay at 2016-01-22T14:04:28-05:00 utest_main + Makefile update
- - - - - ad00ffbd by Pierre Delaunay at 2016-01-22T14:08:57-05:00 Merge branch 'work' of gitlab.com:monnier/typer into work
Conflicts: Makefile tests/utest_main.ml
- - - - - 4e901ec3 by Stefan Monnier at 2016-02-14T15:57:51-05:00 * .gitignore: Add ChangeLog.
- - - - -
32 changed files:
- .gitignore - − GNUmakefile - + Makefile - + README.md - manual.texi → doc/manual.texi - + samples/lexer_test.typer - + samples/pexp_test.typer - + samples/pretoken_test.typer - + samples/token_test.typer - elaborate.ml → src/elaborate.ml - + src/fmt.ml - javascript.ml → src/javascript.ml - lexer.ml → src/lexer.ml - lexp.ml → src/lexp.ml - main.ml → src/main.ml - myers.ml → src/myers.ml - pervasive.typer → src/pervasive.typer - pexp.ml → src/pexp.ml - prelexer.ml → src/prelexer.ml - sexp.ml → src/sexp.ml - test.typer → src/test.typer - ulexp.ml → src/ulexp.ml - unify.ml → src/unify.ml - util.ml → src/util.ml - + tests/debug.ml - + tests/dummy1_test.ml - + tests/dummy2_test.ml - + tests/dummy_test.ml - + tests/lexer_debug.ml - + tests/prelexer_debug.ml - + tests/primary_debug.ml - + tests/utest_main.ml
Changes:
===================================== .gitignore ===================================== --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +ChangeLog typer *.elc *.annot @@ -10,3 +11,6 @@ typer *.aux manual.?? *.info +_build/ +*~ +#*#
===================================== GNUmakefile deleted ===================================== --- a/GNUmakefile +++ /dev/null @@ -1,37 +0,0 @@ -OCAMLC = ocamlc -OCAMLDEP = ocamldep -OCAMLC_FLAGS = -annot -g -OCAMLLD = ocamlc -OCAMLLD_FLAGS = -g -RM = rm -f - -FILES = $(wildcard *.ml) - -# OCAMLC wants its object files in the right order so the modules get -# initialized correctly. Ideally `make' should do this job (it already has -# the dependency info and knows all too weel how to do a topological sort), -# but I don't know how to get `make' to do what I want, so I used some `sed' -# magic to massage the .depend in a form that `tsort' can take. -ORDERED_OBJECTS = $(shell sed -e '/([^ :]*.cmo) *:/{ : start; s/^([^ :]*) *: *([^ :\][^ :\]*)/\2 \1\n\1:/; t loop2; /\$$/{; N; s/\.//; b start}; d; : loop2; P; D}; d' .depend | tsort) - -all: typer - -%.cmi %.cmo: %.ml - $(OCAMLC) $(OCAMLC_FLAGS) -c $< - -clean: - $(RM) *.cmo *.cmi *.cmx *.annot - -typer: $(ORDERED_OBJECTS) #$(FILES:.ml=.cmo) - $(OCAMLLD) $(OCAMLLD_FLAGS) -o $@ $(ORDERED_OBJECTS) - -.PHONY: test -# The "OCAMLRUNPARAM=-b" is so as to cause ocamlrun to print a backtrace -# when an exception is not caught. -test: typer - OCAMLRUNPARAM=-b ./typer test.typer - -depend: - $(OCAMLDEP) $(FILES) > .depend - --include .depend
===================================== Makefile ===================================== --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ + +TEST_FILES := $(wildcard ./tests/*_test.ml) + +all: typer debug tests + +typer: + ocamlbuild src/main.byte + mv _build/src/main.byte _build/typer # move and rename executable + +debug: + ocamlbuild tests/prelexer_debug.byte -I src # debug print + mv _build/tests/prelexer_debug.byte _build/prelexer_debug + ocamlbuild tests/lexer_debug.byte -I src # debug print + mv _build/tests/lexer_debug.byte _build/lexer_debug + +tests: + # Build tests + $(foreach test, $(TEST_FILES), ocamlbuild $(subst ./,,$(subst .ml,.byte,$(test))) -I src;) + + # Run tests + ocamlbuild tests/utest_main.byte + ./_build/tests/utest_main.byte + +# Make language doc +doc-tex: + texi2pdf ./doc/manual.texi --pdf --build=clean + +# Make implementation doc +doc-ocaml: + ocamldoc + +.PHONY: typer +.PHONY: debug +.PHONY: tests
===================================== README.md ===================================== --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ + +Typer +===== + +# How to build Typer + +## Requirement + +* Ocaml 4.01 + +## Build + +By default ocamlbuild creates a '_build' folder which holds all the compiled files. + +* make typer: build typer interpreter 'typer' +* make debug: build typer with debug info 'debug' +* make tests: run interpreter's tests '/.tests/utest_main.byte' + +# Directory layout + +* src/ interpreter's source +* doc/ interpreter's doc files +* sample/ typer code sample for testing purposes +* tests/ ocaml test files + +# Emacs files + + /typer-mode.el + + \ No newline at end of file
===================================== manual.texi → doc/manual.texi ===================================== --- a/manual.texi +++ b/doc/manual.texi
===================================== samples/lexer_test.typer ===================================== --- /dev/null +++ b/samples/lexer_test.typer @@ -0,0 +1,39 @@ +%% This file check if typer recognize correctly tokens + +%% builtin types +%% ---------------- + +%% String +a = "The answer is 42"; + +%% Integer +b = 11; + +%% Float +c = 3.14; + +%% Something +C = 3.14.14; + + +%% Case + +case (a,b) + | (Foo,Foo) => 3.14 + | (Bar,Bar) => 3.15 +;; + + +%% Stuff +%% ---------------- + +%% Epsilon + +%% Block + + +%% Node +%% -> Composed expression + +%% Symbol +%% --> Everything else
===================================== samples/pexp_test.typer ===================================== --- /dev/null +++ b/samples/pexp_test.typer @@ -0,0 +1,50 @@ +%% +%% Proto lambda-expressions, half-way between Sexp and Lexp. +%% + +%% ppat +%% ----------------- + +%% Ppatany + +%% Ppatvar + +%% Ppatcons + + +%% pexp +%% ----------------- + +%% Pimm +%% + +%% Pvar +%% + +%% Phastype +%% + +%% Pmetavar +%% + +%% Plet +%% + +%% Parrow +%% + +%% Plambda +%% + +%% Pcall +%% + +%% Pinductive +%% + +%% Pcons +%% + +%% Pcase +%% +
===================================== samples/pretoken_test.typer ===================================== --- /dev/null +++ b/samples/pretoken_test.typer @@ -0,0 +1,15 @@ +%% This file check if typer recognize correctly pretokens + +%% Preblock +%% --> hum, hum + + +%% Prestring +%% --> String variable +b = "The answer is 42"; + + +%% Pretoken +%% --> Everything else + +a = 3; \ No newline at end of file
===================================== samples/token_test.typer ===================================== --- /dev/null +++ b/samples/token_test.typer @@ -0,0 +1,28 @@ +%% This file check if typer recognize correctly tokens + +%% builtin types +%% ---------------- + +%% String +a = "The answer is 42"; + +%% Integer +b = 11; + +%% Float +c = 3.14; + + +%% Stuff +%% ---------------- + +%% Epsilon + +%% Block + + +%% Node +%% -> Composed expression + +%% Symbol +%% --> Everything else
===================================== elaborate.ml → src/elaborate.ml ===================================== --- a/elaborate.ml +++ b/src/elaborate.ml
===================================== src/fmt.ml ===================================== --- /dev/null +++ b/src/fmt.ml @@ -0,0 +1,49 @@ +(* + * Kiwi Compiler + * + * Pierre Delaunay + * + * --------------------------------------------------------------------------- + * + * + *) + + +(****************************************************************************** + * Print helper + * + * Declare new print function which align printed values. + * + *****************************************************************************) + +(* Compute the number of character needed to print an integer*) +let str_size_int value = + (int_of_float (log10 (float value))) + 1 +;; + +(* print n char 'c' *) +let rec make_line c n = + print_string c; + if n >= 1 then (make_line c (n - 1)); +;; + +(* print an integer right-aligned *) +let ralign_print_int value nb = + make_line " " (nb - (str_size_int value)); + print_int value; +;; + +let lalign_print_int value nb = + print_int value; + make_line " " (nb - (str_size_int value)); +;; + +let ralign_print_string str nb = + make_line " " (nb - String.length str); + print_string str; +;; + +let lalign_print_string str nb = + print_string str; + make_line " " (nb - String.length str); +;;
===================================== javascript.ml → src/javascript.ml ===================================== --- a/javascript.ml +++ b/src/javascript.ml
===================================== lexer.ml → src/lexer.ml ===================================== --- a/lexer.ml +++ b/src/lexer.ml
===================================== lexp.ml → src/lexp.ml ===================================== --- a/lexp.ml +++ b/src/lexp.ml
===================================== main.ml → src/main.ml ===================================== --- a/main.ml +++ b/src/main.ml
===================================== myers.ml → src/myers.ml ===================================== --- a/myers.ml +++ b/src/myers.ml
===================================== pervasive.typer → src/pervasive.typer ===================================== --- a/pervasive.typer +++ b/src/pervasive.typer
===================================== pexp.ml → src/pexp.ml ===================================== --- a/pexp.ml +++ b/src/pexp.ml
===================================== prelexer.ml → src/prelexer.ml ===================================== --- a/prelexer.ml +++ b/src/prelexer.ml
===================================== sexp.ml → src/sexp.ml ===================================== --- a/sexp.ml +++ b/src/sexp.ml
===================================== test.typer → src/test.typer ===================================== --- a/test.typer +++ b/src/test.typer
===================================== ulexp.ml → src/ulexp.ml ===================================== --- a/ulexp.ml +++ b/src/ulexp.ml
===================================== unify.ml → src/unify.ml ===================================== --- a/unify.ml +++ b/src/unify.ml
===================================== util.ml → src/util.ml ===================================== --- a/util.ml +++ b/src/util.ml
===================================== tests/debug.ml ===================================== --- /dev/null +++ b/tests/debug.ml @@ -0,0 +1,139 @@ +(* + * Typer Compiler + * + * --------------------------------------------------------------------------- + * + * Copyright (C) 2011-2016 Free Software Foundation, Inc. + * + * Author: Pierre Delaunay pierre.delaunay@hec.ca + * Keywords: languages, lisp, dependent types. + * + * This file is part of Typer. + * + * Typer is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Typer 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 GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see http://www.gnu.org/licenses/. + * + * --------------------------------------------------------------------------- + * + * Description: + * Provide helper functions to print out + * extracted token + * extracted expression + * + * --------------------------------------------------------------------------- *) + +(* removes some warnings *) +open Util + +(* print debug info *) +let print_loc (loc : Util.location) = + print_string loc.file; + print_string ": ln "; + Fmt.ralign_print_int loc.line 3; + print_string ", cl "; + Fmt.ralign_print_int loc.column 3; +;; + + +(*open Token +open Token + +(* Print token with debug info *) +let print_token tok = + (* Shortcut *) + let lalign str = Fmt.lalign_print_string str 20 in + + (* When we need to print only the name *) + let quick_print name loc = + lalign name; + print_string "["; print_loc loc; print_string "] "; + print_string "\n" in + + let long_print name loc elem = + lalign name; + print_string "["; print_loc loc; print_string "] "; + print_string "'"; + print_string elem; + print_string "'\n" in + + let print_kwd name loc ch = + lalign name; + print_string "["; print_loc loc; print_string "] "; + print_char ch; + print_string "\n" in + + let print_float name loc ch = + lalign name; + print_string "["; print_loc loc; print_string "] "; + print_float ch; + print_string "\n" in + + let print_integer name loc ch = + lalign name; + print_string "["; print_loc loc; print_string "] "; + print_int ch; + print_string "\n" in + + (* Print tokens *) + match tok with + | Token.Arw(loc, str) -> long_print "Arw" loc str; + | Token.Assign(loc, str) -> long_print "Assign" loc str; + | Token.Colon(loc, str) -> long_print "Colon" loc str; + | Token.Lambda(loc) -> quick_print "Lambda" loc; + | Token.Case(loc) -> quick_print "Case" loc; + | Token.Inductive(loc) -> quick_print "Inductive" loc; + | Token.Let(loc) -> quick_print "Let" loc; + | Token.In(loc) -> quick_print "In" loc; + | Token.Ident(loc, str) -> long_print "Identifier" loc str; + | Token.Kwd(loc, ch) -> print_kwd "Kwd" loc ch; + | Token.Float(loc, value) -> print_float "Float" loc value; + | Token.Integer(loc, value) -> print_integer "Integer" loc value; + | Token.String(loc, str) -> long_print "String" loc str; +;; + +(* Lexer print + *--------------------------------------------------*) + +(* Print the list of token *) +let debug_lex file_name = + + let file_stream = open_in file_name in + + (* Create a stream of tokens *) + let lex_stream = Lexer.lex file_name (Stream.of_channel file_stream) in + + (* Print each tokens *) + Stream.iter (fun tok -> print_token tok) lex_stream; +;; + +(* Parser print + *--------------------------------------------------(**) +let debug_parser file_name = + + let file_stream = open_in file_name in + + (* Create a stream of tokens *) + let lex_stream = Lexer.lex file_name (Stream.of_channel file_stream) in + + (* Parse token's stream *) + Toplevel.main_loop lex_stream +;; **) + + +let main () = + debug_lex "./typer_test/lexer_test.typer"; (**) + + (*debug_parser "kiwi_code/lexer_test.kwi";**) +;; + +main ();*)
===================================== tests/dummy1_test.ml ===================================== --- /dev/null +++ b/tests/dummy1_test.ml @@ -0,0 +1,13 @@ + +open Util +open Prelexer +open Debug + +let main () = + + let file_name = (Sys.argv.(1) ^ "/samples/lexer_test.typer") in + prelex_file file_name +;; + +main () +;; \ No newline at end of file
===================================== tests/dummy2_test.ml ===================================== --- /dev/null +++ b/tests/dummy2_test.ml @@ -0,0 +1,13 @@ + +open Util +open Prelexer +open Debug + +let main () = + + let file_name = (Sys.argv.(1) ^ "/samples/lexer_test.typer") in + prelex_file file_name +;; + +main () +;; \ No newline at end of file
===================================== tests/dummy_test.ml ===================================== --- /dev/null +++ b/tests/dummy_test.ml @@ -0,0 +1,16 @@ + +open Util +open Prelexer +open Debug + +let main () = + + print_endline Sys.argv.(0); + print_endline Sys.argv.(1); + + let file_name = (Sys.argv.(1) ^ "/samples/lexer_test.typer") in + prelex_file file_name +;; + +main () +;; \ No newline at end of file
===================================== tests/lexer_debug.ml ===================================== --- /dev/null +++ b/tests/lexer_debug.ml @@ -0,0 +1,131 @@ +(* + * Typer Compiler + * + * --------------------------------------------------------------------------- + * + * Copyright (C) 2011-2016 Free Software Foundation, Inc. + * + * Author: Pierre Delaunay pierre.delaunay@hec.ca + * Keywords: languages, lisp, dependent types. + * + * This file is part of Typer. + * + * Typer is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Typer 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 GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see http://www.gnu.org/licenses/. + * + * --------------------------------------------------------------------------- + * + * Description: + * print out read Sexp (Syntactic expression) + * i.e lexer's tokens + * + * --------------------------------------------------------------------------- *) + +open Util +open Prelexer +open Sexp +open Lexer + +let default_stt = + let stt = Array.create 256 false + in stt.(Char.code ';') <- true; + stt.(Char.code ',') <- true; + stt.(Char.code '(') <- true; + stt.(Char.code ')') <- true; + stt + + +let rec debug_sexp_print sexp = + let print_loc = Debug.print_loc in + match sexp with + | Epsilon + -> print_string "Epsilon()\n" (* "ε" *) + + | Block(loc, pts, _) + -> print_string "Block: \t{"; + print_string "["; print_loc loc; print_string "]\t"; + pretokens_print pts; + print_string " }" + + | Symbol(loc, name) + -> print_string "Symbol: \t"; + print_string "["; print_loc loc; print_string "]\t"; + print_string name + + | String(loc, str) + -> print_string "String: \t"; + print_string "["; print_loc loc; print_string "]\t"; + print_string """; print_string str; print_string """ + + | Integer(loc, n) + -> print_string "Integer: \t"; + print_string "["; print_loc loc; print_string "]\t"; + print_int n + + | Float(loc, x) + -> print_string "Float: \t"; + print_string "["; print_loc loc; print_string "]\t"; + print_float x + + | Node(f, args) + -> print_string "Node: \t"; + print_string "(";sexp_print f; + List.iter (fun sexp -> print_string " "; sexp_print sexp) + args; + print_string ")" +;; + +let debug_sexp_print_all tokens = + List.iter (fun pt -> + print_string " "; + debug_sexp_print pt; + print_string "\n"; + ) + tokens +;; + +let main () = + (* + * print tokens/sexp of the file given as first arg + * + ********************************************************) + + let file = Sys.argv.(1) in + print_string file; + print_string "\n"; + + (* Todo read file from prog args *) + (* get pretokens*) + let pretoks = prelex_file file in + + (* get tokens *) + let toks = lex default_stt pretoks in + + (* print tokens *) + debug_sexp_print_all toks +;; + +main ();; + +(* Command Line * ) +let command = + Command.basic + ~summary:"Print Compiler Debug Info" + ~readme:(fun () -> "More detailed information") + Command.Spec.(empty +> anon ("filename" %: string)) + main + +let () = + Command.run ~version:"1.0" ~build_info:"RWO" command * *) + +(*(main Sys.argv.(1));;*)
===================================== tests/prelexer_debug.ml ===================================== --- /dev/null +++ b/tests/prelexer_debug.ml @@ -0,0 +1,73 @@ +(* + * Typer Compiler + * + * --------------------------------------------------------------------------- + * + * Copyright (C) 2011-2016 Free Software Foundation, Inc. + * + * Author: Pierre Delaunay pierre.delaunay@hec.ca + * Keywords: languages, lisp, dependent types. + * + * This file is part of Typer. + * + * Typer is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Typer 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 GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see http://www.gnu.org/licenses/. + * + * --------------------------------------------------------------------------- + * + * Description: + * print out read pretoken + * + * --------------------------------------------------------------------------- *) + +open Util +open Prelexer +open Debug + +(* TODO: add a Prestring and a Preblock example into the test.typer file *) +let rec debug_pretokens_print pretokens = + List.iter (fun pt -> + print_string " "; + match pt with + | Preblock(loc, pts,_) + -> print_string "Preblock:\t"; + print_string "["; print_loc loc; print_string "]\t"; + print_string "{"; + pretokens_print pts; + print_string " }" + + | Pretoken(loc, str) + -> print_string "Pretoken:\t"; + print_string "["; print_loc loc; print_string "]\t"; + print_string str; + print_string "\n" + + | Prestring(loc, str) + -> print_string "Prestring:\t"; + print_string "["; print_loc loc; print_string "]\t"; + print_string """; + print_string str; + print_string ""\n"; + ) + pretokens + +let main () = + let file = Sys.argv.(1) in + print_string file; + print_string "\n"; + + let arr = prelex_file file in + debug_pretokens_print arr +;; + +main ();
===================================== tests/primary_debug.ml ===================================== --- /dev/null +++ b/tests/primary_debug.ml @@ -0,0 +1,133 @@ +(* + * Typer Compiler + * + * --------------------------------------------------------------------------- + * + * Copyright (C) 2011-2016 Free Software Foundation, Inc. + * + * Author: Pierre Delaunay pierre.delaunay@hec.ca + * Keywords: languages, lisp, dependent types. + * + * This file is part of Typer. + * + * Typer is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Typer 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 GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see http://www.gnu.org/licenses/. + * + * --------------------------------------------------------------------------- + * + * Description: + * print out read pexp (primary expression) + * + * --------------------------------------------------------------------------- *) + + +let rec debug_pexp_print pexp = + match pexp with + | Pimm(exp) + -> + | Pvar(p) + -> + | Phastype(l, exp2, exp1) + -> +;; + +let debug_pexp_print_all pexp = + List.iter (fun pt -> + print_string " "; + debug_pexp_print pt; + print_string "\n"; + ) + pexp +;; + +(* Language config *) + +let default_stt = + let stt = Array.create 256 false + in stt.(Char.code ';') <- true; + stt.(Char.code ',') <- true; + stt.(Char.code '(') <- true; + stt.(Char.code ')') <- true; + stt +;; + +let default_grammar : grammar + = List.fold_left (fun g (n, ll, rl) -> SMap.add n (ll, rl) g) + SMap.empty + [("^", Some 171, Some 159); + ("/", Some 148, Some 160); + ("-", Some 92, Some 110); + ("+", Some 93, Some 111); + ("!=", Some 94, Some 75); + (">=", Some 95, Some 76); + ("<=", Some 96, Some 77); + (">", Some 97, Some 78); + ("<", Some 98, Some 79); + ("&&", Some 64, Some 81); + ("||", Some 39, Some 51); + (",", Some 26, Some 26); + ("then", Some 1, Some 0); + ("=", Some 99, Some 80); + ("type", None, Some 27); + (";", Some 15, Some 15); + ("*", Some 137, Some 137); + (":", Some 173, Some 115); + ("]", Some 3, None); + ("->", Some 126, Some 114); + ("=>", Some 126, Some 113); + ("≡>", Some 126, Some 112); + ("in", Some 2, Some 53); + ("else", Some 0, Some 52); + ("|", Some 40, Some 40); + (")", Some 4, None); + ("[", None, Some 3); + ("case", None, Some 28); + ("lambda", None, Some 126); + ("letrec", None, Some 2); + ("let", None, Some 2); + ("if", None, Some 1); + ("(", None, Some 4); + ] +;; + +let main filename () = + + (* Todo read file from prog args *) + (* get pretokens*) + let pretoks = prelex_file filename in + + (* get sexp/tokens *) + let toks = lex default_stt pretoks in + + (* get pexp *) + let pxp = sexp_parse_all grm toks limit in + + (* print pxp *) + debug_pexp_print_all pxp +;; + +(* Command Line *) +open Core.Std + +let command = + Command.basic + ~summary:"Print Compiler Debug Info" + ~readme:(fun () -> "More detailed information") + Command.Spec.(empty +> anon ("filename" %: string)) + main + +let () = + Command.run ~version:"1.0" ~build_info:"RWO" command + + +
===================================== tests/utest_main.ml ===================================== --- /dev/null +++ b/tests/utest_main.ml @@ -0,0 +1,92 @@ +(* + * Typer Compiler + * + * --------------------------------------------------------------------------- + * + * Copyright (C) 2011-2016 Free Software Foundation, Inc. + * + * Author: Pierre Delaunay pierre.delaunay@hec.ca + * Keywords: languages, lisp, dependent types. + * + * This file is part of Typer. + * + * Typer is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Typer 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 GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see http://www.gnu.org/licenses/. + * + * --------------------------------------------------------------------------- + * + * Description: + * Basic utest program run all tests + * + * --------------------------------------------------------------------------- *) + + +let cut_name str = + String.sub str 0 (String.length str - 10) +;; + +(* search *_test.byte executable en run them + Usage: + ./utest_main tests_folder root_folder *) +let main () = + let arg_n = Array.length Sys.argv in + + (* read where tests files are*) + let folder = (if arg_n > 1 then Sys.argv.(1) else "./_build/tests/") in + + print_string " \n"; + print_string " Running Unit Tests \n"; + print_string " \n"; + (*print_string ("[ ] Test folder: " ^ folder ^ "\n"); *) + + (* get tests files *) + let files = Sys.readdir folder in + let files_n = Array.length files in + + let exit_code = ref 0 in + let failed_test = ref 0 in + let tests_n = ref 0 in + let root_folder = (if arg_n > 2 then Sys.argv.(2) else "./") in (* /_build/tests/ *) + + for i = 0 to files_n - 1 do + (* Check if file is a test => if it is run it *) + (if Filename.check_suffix files.(i) "_test.byte" then begin + + tests_n := !tests_n + 1; + + print_string " " ; + print_int !tests_n; + print_endline (") " ^ (cut_name files.(i))); + print_endline "[RUN ]"; + + exit_code := Sys.command (folder ^ files.(i) ^ " " ^ root_folder); + + if !exit_code <> 0 then begin + print_string "[ FAIL]\n" ; + print_endline " =========== TEST FAILURE ==========="; + failed_test := !failed_test + 1; + end + else + print_string "[ OK]\n" ; + end) + done; + + print_string "\n\n\n"; + print_endline " =========== Test Summary ===========\n"; + print_string " Test Ran : "; print_int !tests_n; + print_string "\n Test Failed : "; print_int !failed_test; + print_string "\n Test Passed : "; print_int (!tests_n - !failed_test); + print_endline "\n =========== Test Summary ===========\n"; +;; + +main ();
View it on GitLab: https://gitlab.com/monnier/typer/compare/a547bdb886d2cdaf6ed20561726b85ba7ba...