Skip to content

Commit 727eb8a

Browse files
shymjmid
authored andcommitted
In_channel: Use a text file rather than a binary when possible
Look for a text file to use to test `In_channel` to ensure that `input_line` and `input_all` will yield smaller results
1 parent 1f8dade commit 727eb8a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/io/lin_tests_spec_io.ml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@
22
(* Tests of in and out channels *)
33
(* ********************************************************************** *)
44

5+
(* Try to find a text file rather than a binary to test In_channel, so
6+
that input_line makes more sense *)
7+
let in_file =
8+
let path0 = Filename.dirname Sys.executable_name
9+
and up p = Filename.concat p Filename.parent_dir_name
10+
and candidate p = Filename.concat p "dune" in
11+
let path1 = up path0 in
12+
let path2 = up path1 in
13+
let path3 = up path2 in
14+
let path4 = up path3 in
15+
let candidates = List.map candidate [ path0; path1; path2; path3; path4 ] in
16+
let existing = List.filter Sys.file_exists candidates in
17+
match existing with
18+
| [] -> Sys.executable_name
19+
| f :: _ -> f
20+
521
module ICConf : Lin.Spec = struct
622
type t = In_channel.t
723

8-
let init () = In_channel.open_bin Sys.executable_name
24+
let init () = In_channel.open_bin in_file
925
let cleanup = In_channel.close
1026

1127
open Lin

0 commit comments

Comments
 (0)