Skip to content

Commit 4e0727f

Browse files
committed
Suppress the welcome message in tests
1 parent ac11172 commit 4e0727f

File tree

8 files changed

+48
-42
lines changed

8 files changed

+48
-42
lines changed

arrayjit/lib/utils.ml

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -112,52 +112,66 @@ let filename_of_parts = function
112112
| root :: rest -> List.fold rest ~init:root ~f:Stdlib.Filename.concat
113113

114114
let config_file_args =
115+
let suppress_welcome_message () =
116+
Option.value_map ~default:false ~f:Bool.of_string
117+
@@ read_cmdline_or_env_var "suppress_welcome_message"
118+
in
115119
match read_cmdline_or_env_var "no_config_file" with
116-
| None | Some "false" -> (
120+
| None | Some "false" ->
117121
let read = Stdio.In_channel.read_lines in
118122
let fname, config_lines =
119123
let rev_dirs = List.rev @@ filename_parts @@ Stdlib.Sys.getcwd () in
120124
let rec find_up = function
121125
| [] ->
122-
Stdio.printf
123-
"\nWelcome to OCANNL! No ocannl_config file found along current path.\n%!";
126+
if not (suppress_welcome_message ()) then
127+
Stdio.printf
128+
"\nWelcome to OCANNL! No ocannl_config file found along current path.\n%!";
124129
("", [])
125130
| _ :: tl as rev_dirs -> (
126131
let fname = filename_of_parts (List.rev @@ ("ocannl_config" :: rev_dirs)) in
127132
try (fname, read fname) with Sys_error _ -> find_up tl)
128133
in
129134
find_up rev_dirs
130135
in
131-
if String.length fname > 0 then
132-
Stdio.printf "\nWelcome to OCANNL! Reading configuration defaults from %s.\n%!" fname;
133-
config_lines
134-
|> List.filter ~f:(fun l ->
135-
not (String.is_prefix ~prefix:"~~" l || String.is_prefix ~prefix:"#" l))
136-
|> List.map ~f:(String.split ~on:'=')
137-
|> List.filter_map ~f:(function
138-
| [] -> None
139-
| [ s ] when String.is_empty s -> None
140-
| key :: [ v ] ->
141-
let key =
142-
String.(
143-
lowercase @@ strip ~drop:(fun c -> equal_char '-' c || equal_char ' ' c) key)
144-
in
145-
let key =
146-
if String.is_prefix key ~prefix:"ocannl" then
147-
String.drop_prefix key 6 |> String.strip ~drop:(equal_char '_')
148-
else key
149-
in
150-
str_nonempty ~f:(pair key) v
151-
| l ->
152-
failwith @@ "OCANNL: invalid syntax in the config file " ^ fname
153-
^ ", should have a single '=' on each non-empty line, found: " ^ String.concat l)
154-
|> Hashtbl.of_alist (module String)
155-
|> function
156-
| `Ok h -> h
157-
| `Duplicate_key key ->
158-
failwith @@ "OCANNL: duplicate key in config file " ^ fname ^ ": " ^ key)
136+
let result =
137+
config_lines
138+
|> List.filter ~f:(fun l ->
139+
not (String.is_prefix ~prefix:"~~" l || String.is_prefix ~prefix:"#" l))
140+
|> List.map ~f:(String.split ~on:'=')
141+
|> List.filter_map ~f:(function
142+
| [] -> None
143+
| [ s ] when String.is_empty s -> None
144+
| key :: [ v ] ->
145+
let key =
146+
String.(
147+
lowercase @@ strip ~drop:(fun c -> equal_char '-' c || equal_char ' ' c) key)
148+
in
149+
let key =
150+
if String.is_prefix key ~prefix:"ocannl" then
151+
String.drop_prefix key 6 |> String.strip ~drop:(equal_char '_')
152+
else key
153+
in
154+
str_nonempty ~f:(pair key) v
155+
| l ->
156+
failwith @@ "OCANNL: invalid syntax in the config file " ^ fname
157+
^ ", should have a single '=' on each non-empty line, found: " ^ String.concat l)
158+
|> Hashtbl.of_alist (module String)
159+
|> function
160+
| `Ok h -> h
161+
| `Duplicate_key key ->
162+
failwith @@ "OCANNL: duplicate key in config file " ^ fname ^ ": " ^ key
163+
in
164+
if
165+
String.length fname > 0
166+
&& (not (suppress_welcome_message ()))
167+
&& not
168+
(Option.value_map ~default:false ~f:Bool.of_string
169+
@@ Hashtbl.find result "suppress_welcome_message")
170+
then Stdio.printf "\nWelcome to OCANNL! Reading configuration defaults from %s.\n%!" fname;
171+
result
159172
| Some _ ->
160-
Stdio.printf "\nWelcome to OCANNL! Configuration defaults file is disabled.\n%!";
173+
if not (suppress_welcome_message ()) then
174+
Stdio.printf "\nWelcome to OCANNL! Configuration defaults file is disabled.\n%!";
161175
Hashtbl.create (module String)
162176

163177
(** Retrieves [arg_name] argument from the command line or from an environment variable, returns

arrayjit/test/ocannl_config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
suppress_welcome_message=true
12
randomness_lib=for_tests
23
log_main_domain_to_stdout=true
34
backend=multicore_cc

arrayjit/test/test_numerical_types.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
Welcome to OCANNL! Reading configuration defaults from /Users/lukstafi/ocannl/_build/default/arrayjit/test/ocannl_config.
31
Retrieving commandline, environment, or config file variable ocannl_log_level
42
Found 0, in the config file
53
Testing BFloat16 conversions:

test/config/ocannl_config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
suppress_welcome_message=true
12
randomness_lib=for_tests
23
log_main_domain_to_stdout=true
34
backend=multicore_cc

test/einsum/einsum_trivia_exec.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
Welcome to OCANNL! Reading configuration defaults from /Users/lukstafi/ocannl/_build/default/test/einsum/ocannl_config.
31
Retrieving commandline, environment, or config file variable ocannl_log_level
42
Found 0, in the config file
53
HERE: test/einsum/einsum_trivia_exec.ml:31:21

test/einsum/moons_demo_variant.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
Welcome to OCANNL! Reading configuration defaults from /Users/lukstafi/ocannl/_build/default/test/einsum/ocannl_config.
31
Retrieving commandline, environment, or config file variable ocannl_log_level
42
Found 0, in the config file
53
Tnode: collecting accessible arrays...

test/einsum/test_conv_syntax.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
Welcome to OCANNL! Reading configuration defaults from /Users/lukstafi/ocannl/_build/default/test/einsum/ocannl_config.
31
Retrieving commandline, environment, or config file variable ocannl_log_level
42
Found 0, in the config file
53
Testing conv syntax parsing...

test/einsum/test_print_style.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
Welcome to OCANNL! Reading configuration defaults from /Users/lukstafi/ocannl/_build/default/test/einsum/ocannl_config.
31
Retrieving commandline, environment, or config file variable ocannl_log_level
42
Found 0, in the config file
53
Testing print_style functionality:

0 commit comments

Comments
 (0)