Skip to content

Commit 345974e

Browse files
committed
CWCompileAndRun (initial implementation)
1 parent 6b130ea commit 345974e

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Run `make .merlin` to create the `.merlin` file.
5151

5252
Test cases cannot be nested.
5353

54-
- `CWEndTest`.
54+
- `CWEndTest`
5555

5656
Ends a test case. This command is optional before `CWTest` and `CWEndGroup`.
5757

src/coq_cw.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
open Pp
22

33
let solution_file = "/workspace/Solution.v"
4+
let ocaml_compiler = "ocamlopt"
5+
let driver_file = "driver.ml"
46

57
let format_msg =
68
let re = Str.regexp_string "\n" in
@@ -134,3 +136,21 @@ let test_file_regex ?(fname = solution_file) match_flag regex =
134136
failed "Bad match";
135137
CErrors.user_err (str "Bad match")
136138
end
139+
140+
let run_system_command args =
141+
let cmd = String.concat " " args in
142+
Printf.printf "Running: %s" cmd;
143+
match Unix.system cmd with
144+
| Unix.WEXITED 0 -> passed "OK"
145+
| _ -> failed "Failed"
146+
147+
let write_file fname str =
148+
let oc = open_out fname in
149+
Printf.fprintf oc "%s" str;
150+
close_out oc
151+
152+
let compile_and_run files ?(options = "") driver_code =
153+
write_file driver_file driver_code;
154+
run_system_command ([ocaml_compiler; options] @ files @ [driver_file]);
155+
run_system_command ["./a.out"];
156+
passed "OK"

src/coq_cw.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ val test_file_size : ?fname:string -> int -> unit
66

77
val test_file_regex : ?fname:string -> bool -> string -> unit
88

9+
val compile_and_run : string list -> ?options:string -> string -> unit
10+
911
val begin_group : string -> string -> unit
1012

1113
val end_group : string -> unit

src/g_coq_cw.ml4

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,10 @@ VERNAC COMMAND EXTEND CWFileNegMatch CLASSIFIED AS QUERY
5454
| [ "CWFile" string_opt(fname) "Does" "Not" "Match" string(regex)] -> [
5555
Coq_cw.test_file_regex ?fname false regex
5656
]
57-
END
57+
END
58+
59+
VERNAC COMMAND EXTEND CWCompileAndRun CLASSIFIED AS SIDEFF
60+
| [ "CWCompileAndRun" string_list(files) "Options" string_opt(options) "Driver" string(driver) ] -> [
61+
Coq_cw.compile_and_run files ?options driver
62+
]
63+
END

0 commit comments

Comments
 (0)