(* 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 temp_file =
  let name, ch = Filename.open_temp_file "data" ".txt" in
  output_string ch (String.make 1024 'a');
  close_out ch;
  name

let () =
  let ic = open_in_bin temp_file 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 temp_file in
  close_in ic;
  begin try
    seek_in ic (-1);
    ignore (input_byte ic);
    assert false;
  with
  | Sys_error _ -> ()
  end
