This repository has been archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testPointeurs.ml
86 lines (68 loc) · 2.7 KB
/
testPointeurs.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
open Compilateur
open Exceptions
(* Changer le chemin d'accès du jar. *)
let runtamcmde = "java -jar ../../runtam.jar"
(* let runtamcmde = "java -jar /mnt/n7fs/.../tools/runtam/runtam.jar" *)
(* Execute the TAM code obtained from the rat file and return the ouptut of this code *)
let runtamcode cmde ratfile =
let tamcode = compiler ratfile in
let (tamfile, chan) = Filename.open_temp_file "test" ".tam" in
output_string chan tamcode;
close_out chan;
let ic = Unix.open_process_in (cmde ^ " " ^ tamfile) in
let printed = input_line ic in
close_in ic;
Sys.remove tamfile; (* à commenter si on veut étudier le code TAM. *)
String.trim printed
(* Compile and run ratfile, then print its output *)
let runtam ratfile =
print_string (runtamcode runtamcmde ratfile)
exception ErreurNonDetectee
let%expect_test "test-definition-bool" =
runtam "../../fichiersRat/test-pointeurs/test-definition-bool.rat";
[%expect{| false |}]
let%expect_test "test-definition-int" =
runtam "../../fichiersRat/test-pointeurs/test-definition-int.rat";
[%expect{| 5 |}]
let%expect_test "test-definition-rat" =
runtam "../../fichiersRat/test-pointeurs/test-definition-rat.rat";
[%expect{| [5/2] |}]
let%expect_test "test-definition-null" =
runtam "../../fichiersRat/test-pointeurs/test-definition-null.rat";
[%expect{| 0 |}]
let%expect_test "test-mauvaise-definition" =
try let _ = runtam "../../fichiersRat/test-pointeurs/test-mauvaise-definition.rat"
in raise ErreurNonDetectee
with
| TypeInattendu _ -> ();
[%expect{| |}]
let%expect_test "test-acces-statique" =
runtam "../../fichiersRat/test-pointeurs/test-acces-statique.rat";
[%expect{| 5 |}]
let%expect_test "test-mauvaise-deref" =
try let _ = runtam "../../fichiersRat/test-pointeurs/test-mauvaise-deref.rat"
in raise ErreurNonDetectee
with
| DereferenceNonPointeur _ -> ();
[%expect{| |}]
let%expect_test "test-pointeur-pointeur" =
runtam "../../fichiersRat/test-pointeurs/test-pointeur-pointeur.rat";
[%expect{| 5 |}]
let%expect_test "test-acces-dynamique" =
runtam "../../fichiersRat/test-pointeurs/test-acces-dynamique.rat";
[%expect{| 7 |}]
let%expect_test "test-param-fonction" =
runtam "../../fichiersRat/test-pointeurs/test-param-fonction.rat";
[%expect{| true10 |}]
let%expect_test "test-new" =
runtam "../../fichiersRat/test-pointeurs/test-new.rat";
[%expect{| 10 |}]
let%expect_test "test-new-int" =
runtam "../../fichiersRat/test-pointeurs/test-new-int.rat";
[%expect{| 777 |}]
let%expect_test "test-new-rat" =
runtam "../../fichiersRat/test-pointeurs/test-new-rat.rat";
[%expect{| [1/2][1/2][1/2][1/2] |}]
let%expect_test "exemple" =
runtam "../../fichiersRat/test-pointeurs/exemple.rat";
[%expect{| 3 |}]