summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2009-01-23 04:20:21 +0100
committerGuillaume Seguin <guillaume@segu.in>2009-01-23 04:20:21 +0100
commitfceca1a2201eae51a5897b69ace85b0c5b773ac2 (patch)
tree586bad205d65881d68be583706e92e342aaf7a13
parentd941809074955cc5e079ce48b202f24c1b3ed9c3 (diff)
downloadpetitcaml-fceca1a2201eae51a5897b69ace85b0c5b773ac2.tar.gz
petitcaml-fceca1a2201eae51a5897b69ace85b0c5b773ac2.tar.bz2
[petitcaml] Verify expected types in unit tests
-rw-r--r--runtests.py26
-rw-r--r--tests/typing/base.ml13
-rw-r--r--tests/typing/funcs-rec-2args.ml2
-rw-r--r--tests/typing/funcs.ml5
-rw-r--r--tests/typing/lists.ml9
-rw-r--r--tests/typing/match.ml2
-rw-r--r--tests/typing/primitives.ml12
-rw-r--r--tests/typing/test.ml17
8 files changed, 78 insertions, 8 deletions
diff --git a/runtests.py b/runtests.py
index 9e2abaa..2ffcffb 100644
--- a/runtests.py
+++ b/runtests.py
@@ -33,16 +33,19 @@ def run_test(test_file):
expected_error += lines[i]
i += 1
base_command = "./petit-caml %s" % test_file
+ test_output = False
test_assembly = False
if "lexing" in test_file or "parsing" in test_file:
command = base_command + " -parse-only"
elif "typing" in test_file:
- command = base_command + " -type-only"
+ test_output = True
+ command = base_command + " -type-only -print-decl-types"
else:
test_assembly = True
command = base_command
- process = subprocess.Popen("./petit-caml %s" % test_file,
+ process = subprocess.Popen(command,
stderr = subprocess.PIPE,
+ stdout = subprocess.PIPE,
shell = True)
return_code = process.wait()
if return_code != 0:
@@ -58,7 +61,19 @@ def run_test(test_file):
expected_error.strip())
else:
status = "%s\n%s" % (NOTOK, error.strip())
- if status == OK and test_assembly:
+ if return_code == 0 and (test_output or test_assembly):
+ i = 3
+ expected_output = ""
+ while not lines[i].startswith("*)"):
+ expected_output += lines[i]
+ i += 1
+ if status == OK and return_code == 0 and test_output:
+ output = process.stdout.read()
+ if output != expected_output:
+ status = "%s\n%s\n%s\n%s" % (NOTOK, output.strip(),
+ bold("Expected :"),
+ expected_output.strip())
+ if status == OK and return_code == 0 and test_assembly:
process = subprocess.Popen("spim %s" % test_file.replace(".ml", ".s"),
stderr = subprocess.PIPE,
stdout = subprocess.PIPE,
@@ -67,11 +82,6 @@ def run_test(test_file):
if return_code != 0:
error = process.stderr.read()
status = "%s\n%s" % (NOTOK, error.strip())
- i = 3
- expected_output = ""
- while not lines[i].startswith("*)"):
- expected_output += lines[i]
- i += 1
output = process.stdout.read()
output = output.replace(SPIM_COPYRIGHT_HEADER, "")
if output != expected_output:
diff --git a/tests/typing/base.ml b/tests/typing/base.ml
index 069b4e3..a12cacd 100644
--- a/tests/typing/base.ml
+++ b/tests/typing/base.ml
@@ -1,5 +1,18 @@
(*
return : 0
+ output :
+a : int
+b : int
+c : int
+d : int
+e : int
+f : int
+t : bool
+f : bool
+l : bool
+k : bool
+a : bool
+b : bool
*)
let a = 42
let b = a + 42
diff --git a/tests/typing/funcs-rec-2args.ml b/tests/typing/funcs-rec-2args.ml
index 39cd876..c0b2c3d 100644
--- a/tests/typing/funcs-rec-2args.ml
+++ b/tests/typing/funcs-rec-2args.ml
@@ -1,5 +1,7 @@
(*
return : 0
+ output :
+ack : int -> int -> int
*)
let rec ack m n =
if m = 0 then n + 1
diff --git a/tests/typing/funcs.ml b/tests/typing/funcs.ml
index 54910e5..5474d74 100644
--- a/tests/typing/funcs.ml
+++ b/tests/typing/funcs.ml
@@ -1,5 +1,10 @@
(*
return : 0
+ output :
+f : int -> int
+g : int -> int
+fact : int -> int
+_ : int
*)
let f x = x + 42
let g = function x -> x + 42
diff --git a/tests/typing/lists.ml b/tests/typing/lists.ml
index 60bca89..a61f464 100644
--- a/tests/typing/lists.ml
+++ b/tests/typing/lists.ml
@@ -1,5 +1,14 @@
(*
return : 0
+ output :
+a : int
+b : int
+f : int -> int
+g : int -> int
+i : int -> int -> int -> int
+j : int -> int -> int -> int list
+l1 : int list
+l2 : int list
*)
let a = 42
let b = a + 42
diff --git a/tests/typing/match.ml b/tests/typing/match.ml
index b087dfd..a279e78 100644
--- a/tests/typing/match.ml
+++ b/tests/typing/match.ml
@@ -1,5 +1,7 @@
(*
return : 0
+ output :
+h : int * 'a list -> int
*)
let rec h l =
match l with
diff --git a/tests/typing/primitives.ml b/tests/typing/primitives.ml
index 30ded6b..88eec89 100644
--- a/tests/typing/primitives.ml
+++ b/tests/typing/primitives.ml
@@ -1,5 +1,17 @@
(*
return : 0
+ output :
+s : string
+i : int
+_ : unit
+_ : unit
+_ : unit
+_ : unit
+a : int
+_ : unit
+_ : unit
+_ : unit
+_ : unit
*)
let s = "test"
let i = 42
diff --git a/tests/typing/test.ml b/tests/typing/test.ml
index 458f7c0..0dd0385 100644
--- a/tests/typing/test.ml
+++ b/tests/typing/test.ml
@@ -1,5 +1,22 @@
(*
return : 0
+ output :
+a : int
+b : int
+f : int -> int
+g : int -> int
+i : int -> int -> int -> int
+_ : int
+_ : int
+_ : int list
+l1 : int list
+l2 : int list
+h : int list -> int
+k : string
+_ : string
+fact : int -> int
+noixdine : string
+test : int
*)
let a = 42
let b = a + 42