File: close_in.ml

package info (click to toggle)
js-of-ocaml 6.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,932 kB
  • sloc: ml: 135,957; javascript: 58,364; ansic: 437; makefile: 422; sh: 12; perl: 4
file content (32 lines) | stat: -rw-r--r-- 707 bytes parent folder | download
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
(* TEST *)

(* Test that inputting bytes from a closed in_channel triggers an exception *)

(* The number of bytes we'll rewind after closing; a value
   between 1 and IO_BUFFER_SIZE *)
let nb_bytes = 3

let () =
  let ic = open_in_bin (Filename.basename Sys.argv.(0)) in
  seek_in ic nb_bytes;
  close_in ic;
  assert (
    try
      seek_in ic 0;
      ignore (input_byte ic);
      false
    with
    | Sys_error _ -> true
    | _           -> false)

(* A variant of #11878, which #11965 failed to fix. *)
let () =
  let ic = open_in_bin (Filename.basename Sys.argv.(0)) in
  close_in ic;
  begin try
    seek_in ic (-1);
    ignore (input_byte ic);
    assert false;
  with
  | Sys_error _ -> ()
  end