You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
948 B

  1. -compile(export_all).
  2. msg(Fmt, Args) ->
  3. M1 = io_lib:format(Fmt, Args),
  4. M2 = re:replace(M1, <<"\r">>, <<"\\\\r">>, [global]),
  5. M3 = re:replace(M2, <<"\n">>, <<"\\\\n">>, [global]),
  6. M4 = re:replace(M3, <<"\t">>, <<"\\\\t">>, [global]),
  7. iolist_to_binary(M4).
  8. hex(Bin) when is_binary(Bin) ->
  9. H1 = [io_lib:format("16#~2.16.0B",[X]) || <<X:8>> <= Bin],
  10. H2 = string:join(H1, ", "),
  11. lists:flatten(io_lib:format("<<~s>>", [lists:flatten(H2)])).
  12. dec(V) ->
  13. jiffy:decode(V).
  14. enc(V) ->
  15. iolist_to_binary(jiffy:encode(V)).
  16. enc(V, Opts) ->
  17. iolist_to_binary(jiffy:encode(V, Opts)).
  18. %% rebar runs eunit with PWD as .eunit/
  19. %% rebar3 runs eunit with PWD as ./
  20. %% this adapts to the differences
  21. cases_path(Suffix) ->
  22. {ok, Cwd} = file:get_cwd(),
  23. Prefix = case filename:basename(Cwd) of
  24. ".eunit" -> "..";
  25. _ -> "."
  26. end,
  27. Path = "test/cases",
  28. filename:join([Prefix, Path, Suffix]).