summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2009-01-10 15:21:02 +0100
committerGuillaume Seguin <guillaume@segu.in>2009-01-10 15:21:02 +0100
commit6e6aad66c8c4bff2d94c099b29ba5ae4f4e82896 (patch)
tree3b422fc4ebb859b0b49cd7ebf89eb74a8fe37088
parentcb167a0eef0ba31cc7e01046333291180887fd1e (diff)
downloadpetitcaml-6e6aad66c8c4bff2d94c099b29ba5ae4f4e82896.tar.gz
petitcaml-6e6aad66c8c4bff2d94c099b29ba5ae4f4e82896.tar.bz2
[petitcaml] Import unit tests
-rw-r--r--runtests.py49
-rw-r--r--tests/lexing/comment-fail.ml7
-rw-r--r--tests/lexing/comment.ml4
-rw-r--r--tests/lexing/strings-fail.ml8
-rw-r--r--tests/lexing/strings-fail2.ml7
-rw-r--r--tests/lexing/strings-fail3.ml7
-rw-r--r--tests/lexing/strings.ml6
-rw-r--r--tests/typing/base-fail.ml7
-rw-r--r--tests/typing/base-fail2.ml7
-rw-r--r--tests/typing/base-fail3.ml7
-rw-r--r--tests/typing/base-fail4.ml7
-rw-r--r--tests/typing/base-fail5.ml11
-rw-r--r--tests/typing/base-fail6.ml7
-rw-r--r--tests/typing/base.ml16
-rw-r--r--tests/typing/funcs-fail.ml9
-rw-r--r--tests/typing/funcs.ml9
-rw-r--r--tests/typing/lists-fail.ml9
-rw-r--r--tests/typing/lists-fail2.ml7
-rw-r--r--tests/typing/lists.ml11
-rw-r--r--tests/typing/match-fail.ml9
-rw-r--r--tests/typing/match-fail2.ml9
-rw-r--r--tests/typing/match.ml6
-rw-r--r--tests/typing/motif-fail.ml7
-rw-r--r--tests/typing/primitives.ml14
-rw-r--r--tests/typing/test.ml35
25 files changed, 275 insertions, 0 deletions
diff --git a/runtests.py b/runtests.py
new file mode 100644
index 0000000..eae5ea4
--- /dev/null
+++ b/runtests.py
@@ -0,0 +1,49 @@
+import glob
+import os
+import subprocess
+
+def bold(s):
+ return "\033[1;37m%s\033[0m" % s
+
+OK = "\033[1;32mOK\033[0m"
+NOTOK = "\033[1;31m!!\033[0m"
+
+def list_tests():
+ tests = []
+ for path in ("lexing", "parsing", "typing"):
+ tests += glob.glob("tests/%s/*.ml" % path)
+ return tests
+
+def run_test(test_file):
+ f = open(test_file)
+ lines = f.readlines()
+ f.close()
+ expected_return_code = int(lines[1][13])
+ if expected_return_code != 0:
+ expected_error = lines[3] + lines[4]
+ process = subprocess.Popen("./petit-caml %s" % test_file,
+ stderr = subprocess.PIPE,
+ shell = True)
+ return_code = process.wait()
+ if return_code != 0:
+ error = process.stderr.read()
+ status = OK if return_code == expected_return_code else NOTOK
+ if return_code != 0:
+ if status == OK:
+ if expected_error == error:
+ status = OK
+ else:
+ status = "%s\n%s\n%s\n%s" % (NOTOK, error.strip(),
+ bold("Expected :"),
+ expected_error.strip())
+ else:
+ status = "%s\n%s" % (NOTOK, error.strip())
+ print "%s : %s" % (bold(test_file), status)
+
+def run_tests():
+ tests = list_tests()
+ tests.sort()
+ map(run_test, tests)
+
+if __name__ == "__main__":
+ run_tests()
diff --git a/tests/lexing/comment-fail.ml b/tests/lexing/comment-fail.ml
new file mode 100644
index 0000000..c40191d
--- /dev/null
+++ b/tests/lexing/comment-fail.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/lexing/comment-fail.ml", line 8, characters 0-1:
+Erreur dans l'analyse lexicale : unterminated comment
+*)
+(* (* (* *) *)
diff --git a/tests/lexing/comment.ml b/tests/lexing/comment.ml
new file mode 100644
index 0000000..e7fa81c
--- /dev/null
+++ b/tests/lexing/comment.ml
@@ -0,0 +1,4 @@
+(*
+ return : 0
+*)
+(* thi (* s is a (* te *) s *) t *)
diff --git a/tests/lexing/strings-fail.ml b/tests/lexing/strings-fail.ml
new file mode 100644
index 0000000..9ee0c30
--- /dev/null
+++ b/tests/lexing/strings-fail.ml
@@ -0,0 +1,8 @@
+(*
+ return : 1
+ output :
+File "tests/lexing/strings-fail.ml", line 7, characters 13-14:
+Erreur dans l'analyse lexicale : illegal \n in string
+*)
+let _ = "test
+"
diff --git a/tests/lexing/strings-fail2.ml b/tests/lexing/strings-fail2.ml
new file mode 100644
index 0000000..41033b0
--- /dev/null
+++ b/tests/lexing/strings-fail2.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/lexing/strings-fail2.ml", line 7, characters 12-13:
+Erreur dans l'analyse lexicale : unterminated string
+*)
+let _ = "aaa
diff --git a/tests/lexing/strings-fail3.ml b/tests/lexing/strings-fail3.ml
new file mode 100644
index 0000000..3d06d79
--- /dev/null
+++ b/tests/lexing/strings-fail3.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/lexing/strings-fail3.ml", line 7, characters 12-13:
+Erreur dans l'analyse lexicale : illegal \ in string
+*)
+let _ = "aa \ aa"
diff --git a/tests/lexing/strings.ml b/tests/lexing/strings.ml
new file mode 100644
index 0000000..2c9dc31
--- /dev/null
+++ b/tests/lexing/strings.ml
@@ -0,0 +1,6 @@
+(*
+ return : 0
+*)
+let _ = "oui"
+let _ = "\\\\ \\ \\ \\non \"\n"
+let _ = "é test ç à y"
diff --git a/tests/typing/base-fail.ml b/tests/typing/base-fail.ml
new file mode 100644
index 0000000..a0427bc
--- /dev/null
+++ b/tests/typing/base-fail.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail.ml", line 7, characters 8-14:
+Erreur dans l'analyse sémantique : Cette expression a le type int * int mais est ici utilisée avec le type int
+*)
+let _ = (1, 2) + 3
diff --git a/tests/typing/base-fail2.ml b/tests/typing/base-fail2.ml
new file mode 100644
index 0000000..efb218d
--- /dev/null
+++ b/tests/typing/base-fail2.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail2.ml", line 7, characters 12-16:
+Erreur dans l'analyse sémantique : Cette expression a le type bool mais est ici utilisée avec le type int
+*)
+let _ = 1 + true
diff --git a/tests/typing/base-fail3.ml b/tests/typing/base-fail3.ml
new file mode 100644
index 0000000..702062f
--- /dev/null
+++ b/tests/typing/base-fail3.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail3.ml", line 7, characters 13-19:
+Erreur dans l'analyse sémantique : Cette expression a le type string mais est ici utilisée avec le type int
+*)
+let _ = 42 < "test"
diff --git a/tests/typing/base-fail4.ml b/tests/typing/base-fail4.ml
new file mode 100644
index 0000000..df6e045
--- /dev/null
+++ b/tests/typing/base-fail4.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail4.ml", line 7, characters 8-13:
+Erreur dans l'analyse sémantique : Cette expression a le type bool mais est ici utilisée avec le type int
+*)
+let _ = false = not true
diff --git a/tests/typing/base-fail5.ml b/tests/typing/base-fail5.ml
new file mode 100644
index 0000000..5373b65
--- /dev/null
+++ b/tests/typing/base-fail5.ml
@@ -0,0 +1,11 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail5.ml", line 11, characters 8-13:
+Erreur dans l'analyse sémantique : Cette expression a le type string mais est ici utilisée avec le type bool
+*)
+let _ =
+ if 42 > 21 then
+ true
+ else
+ "yay"
diff --git a/tests/typing/base-fail6.ml b/tests/typing/base-fail6.ml
new file mode 100644
index 0000000..44a58ca
--- /dev/null
+++ b/tests/typing/base-fail6.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail6.ml", line 7, characters 10-16:
+Erreur dans l'analyse sémantique : Cette expression a le type string mais est ici utilisée avec le type int
+*)
+let _ = - "test"
diff --git a/tests/typing/base.ml b/tests/typing/base.ml
new file mode 100644
index 0000000..069b4e3
--- /dev/null
+++ b/tests/typing/base.ml
@@ -0,0 +1,16 @@
+(*
+ return : 0
+*)
+let a = 42
+let b = a + 42
+let c = a - b
+let d = a * c
+let e = a / d
+let f = - a
+
+let t = true
+let f = not true
+let l = t && f
+let k = t || f
+let a = 1 < 2
+let b = 42 >= 42
diff --git a/tests/typing/funcs-fail.ml b/tests/typing/funcs-fail.ml
new file mode 100644
index 0000000..7b1fc42
--- /dev/null
+++ b/tests/typing/funcs-fail.ml
@@ -0,0 +1,9 @@
+(*
+ return : 1
+ output :
+File "tests/typing/funcs-fail.ml", line 9, characters 14-18:
+Erreur dans l'analyse sémantique : Identifiant invalide : fact
+*)
+let fact n =
+ if n <= 1 then 1
+ else n * (fact (n - 1))
diff --git a/tests/typing/funcs.ml b/tests/typing/funcs.ml
new file mode 100644
index 0000000..54910e5
--- /dev/null
+++ b/tests/typing/funcs.ml
@@ -0,0 +1,9 @@
+(*
+ return : 0
+*)
+let f x = x + 42
+let g = function x -> x + 42
+let rec fact n =
+ if n <= 1 then 1
+ else n * (fact (n - 1))
+let _ = fact 10
diff --git a/tests/typing/lists-fail.ml b/tests/typing/lists-fail.ml
new file mode 100644
index 0000000..08826d0
--- /dev/null
+++ b/tests/typing/lists-fail.ml
@@ -0,0 +1,9 @@
+(*
+ return : 1
+ output :
+File "tests/typing/lists-fail.ml", line 9, characters 9-10:
+Erreur dans l'analyse sémantique : Cette expression a le type int list mais est ici utilisée avec le type int
+*)
+let a = 42
+let b = a + 42
+let l1 = a::b
diff --git a/tests/typing/lists-fail2.ml b/tests/typing/lists-fail2.ml
new file mode 100644
index 0000000..0d99de5
--- /dev/null
+++ b/tests/typing/lists-fail2.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/lists-fail2.ml", line 7, characters 10-12:
+Erreur dans l'analyse sémantique : Cette expression a le type int mais est ici utilisée avec le type string
+*)
+let l2 = [42 ; "42"]
diff --git a/tests/typing/lists.ml b/tests/typing/lists.ml
new file mode 100644
index 0000000..60bca89
--- /dev/null
+++ b/tests/typing/lists.ml
@@ -0,0 +1,11 @@
+(*
+ return : 0
+*)
+let a = 42
+let b = a + 42
+let f x = x + 42
+let g = function x -> x + 42
+let i x y z = x + y + z + 42
+let j x y z = (x + y)::[z + 42]
+let l1 = a::b::(f a)::(g b)::[]
+let l2 = [a ; b ; (f a) ; (g b) ; (i a b (f a))]
diff --git a/tests/typing/match-fail.ml b/tests/typing/match-fail.ml
new file mode 100644
index 0000000..f3a6e6a
--- /dev/null
+++ b/tests/typing/match-fail.ml
@@ -0,0 +1,9 @@
+(*
+ return : 1
+ output :
+File "tests/typing/match-fail.ml", line 8, characters 4-39:
+Erreur dans l'analyse sémantique : Motif interdit dans le filtrage de la queue de liste
+*)
+let rec h l =
+ match l with
+ [] -> 0 | a::(c, d) -> a + h l2
diff --git a/tests/typing/match-fail2.ml b/tests/typing/match-fail2.ml
new file mode 100644
index 0000000..8477c03
--- /dev/null
+++ b/tests/typing/match-fail2.ml
@@ -0,0 +1,9 @@
+(*
+ return : 1
+ output :
+File "tests/typing/match-fail2.ml", line 9, characters 37-50:
+Erreur dans l'analyse sémantique : Cette expression a le type int mais est ici utilisée avec le type string
+*)
+let rec h l =
+ match l with
+ [] -> "blah" | (a, b)::l2 -> a + 42 + h l2
diff --git a/tests/typing/match.ml b/tests/typing/match.ml
new file mode 100644
index 0000000..b087dfd
--- /dev/null
+++ b/tests/typing/match.ml
@@ -0,0 +1,6 @@
+(*
+ return : 0
+*)
+let rec h l =
+ match l with
+ [] -> 0 | (a, b)::l2 -> a + h l2
diff --git a/tests/typing/motif-fail.ml b/tests/typing/motif-fail.ml
new file mode 100644
index 0000000..1fedbcd
--- /dev/null
+++ b/tests/typing/motif-fail.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/motif-fail.ml", line 7, characters 8-9:
+Erreur dans l'analyse sémantique : Variable t non unique dans ce motif
+*)
+let (t, t) = (1, 2)
diff --git a/tests/typing/primitives.ml b/tests/typing/primitives.ml
new file mode 100644
index 0000000..30ded6b
--- /dev/null
+++ b/tests/typing/primitives.ml
@@ -0,0 +1,14 @@
+(*
+ return : 0
+*)
+let s = "test"
+let i = 42
+let _ = print_string s
+let _ = print_newline ()
+let _ = print_int i
+let _ = print_newline ()
+let a = read_int ()
+let _ = print_int (a + i)
+let _ = print_newline ()
+let _ = print_string (read_line ())
+let _ = print_newline ()
diff --git a/tests/typing/test.ml b/tests/typing/test.ml
new file mode 100644
index 0000000..458f7c0
--- /dev/null
+++ b/tests/typing/test.ml
@@ -0,0 +1,35 @@
+(*
+ return : 0
+*)
+let a = 42
+let b = a + 42
+let f x = x + 42
+let g = function x -> x + 42
+let i x y z = x + y + z + 42
+let _ = f a
+let _ = g b
+let _ = a::b::[]
+let l1 = a::b::(f a)::(g b)::[]
+let l2 = [a ; b ; (f a) ; (g b) ; (i a b (f a))]
+let rec h l =
+ match l with
+ [] -> 0 | a::l2 -> a + h l2
+let k =
+ if a = 42
+ then
+ "oui"
+ else
+ "\\ \\ \\non \"\n"
+let _ =
+ let b x = x * 42
+ in
+ if b 42 = (42 * 42)
+ then
+ "omfg"
+ else
+ "o noes! essai é ç à"
+let rec fact n =
+ if n <= 1 then 1
+ else n * (fact (n - 1))
+let noixdine = "namour"
+let test = - 42