Skip to content

Commit

Permalink
Merge pull request #296 from zmstone/0703-cli-print-array-and-map-sum…
Browse files Browse the repository at this point in the history
…mary

0703 cli print array and map summary
  • Loading branch information
zmstone authored Jul 3, 2024
2 parents 76171b8 + 2413738 commit edff64c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/hocon_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ log_env_override(Var, Path, Value) ->
case Value of
V when is_binary(V) -> V;
V when is_map(V) -> "{...}";
[] -> "[]";
[_ | _] -> "[...]";
V -> io_lib:format("~0p", [V])
end,
?STDOUT("~s [~s]: ~s", [Var, Path, ValueStr]).
Expand Down
39 changes: 28 additions & 11 deletions test/hocon_cli_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,32 @@ now_time_test() ->
end).

generate_with_env_logging_test() ->
Envs = [
{"ZZZ_FOO", "{min: 1, max: 2}"},
{"ZZZ_FOO__MIN", "42"},
{"ZZZ_FOO__MAX", "43"},
{"ZZZ_FOO__NUMBERS", "[1,2]"},
{"HOCON_ENV_OVERRIDE_PREFIX", "ZZZ_"}
],
Expects = [
<<"ZZZ_FOO [foo]: {...}">>,
<<"ZZZ_FOO__MAX [foo.max]: 43">>,
<<"ZZZ_FOO__MIN [foo.min]: 42">>,
<<"ZZZ_FOO__NUMBERS [foo.numbers]: [...]">>
],
test_generate_with_env_logging(Envs, Expects).

generate_with_env_logging_empty_array_test() ->
Envs = [
{"ZZZ_FOO__NUMBERS", "[]"},
{"HOCON_ENV_OVERRIDE_PREFIX", "ZZZ_"}
],
Expects = [
<<"ZZZ_FOO__NUMBERS [foo.numbers]: []">>
],
test_generate_with_env_logging(Envs, Expects).

test_generate_with_env_logging(Envs, Expects) ->
?CAPTURING(begin
Time = now_time(),
with_envs(
Expand All @@ -139,20 +165,11 @@ generate_with_env_logging_test() ->
"generate"
]
],
[
{"ZZZ_FOO", "{min: 1, max: 2}"},
{"ZZZ_FOO__MIN", "42"},
{"ZZZ_FOO__MAX", "43"},
{"HOCON_ENV_OVERRIDE_PREFIX", "ZZZ_"}
]
Envs
),
{ok, Stdout} = cuttlefish_test_group_leader:get_output(),
?assertEqual(
[
<<"ZZZ_FOO [foo]: {...}">>,
<<"ZZZ_FOO__MAX [foo.max]: 43">>,
<<"ZZZ_FOO__MIN [foo.min]: 42">>
],
Expects,
lists:sort(
binary:split(
iolist_to_binary(Stdout),
Expand Down

0 comments on commit edff64c

Please sign in to comment.