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.

52 line
1.9 KiB

  1. -module(rebar_edoc_SUITE).
  2. -include_lib("common_test/include/ct.hrl").
  3. -include_lib("eunit/include/eunit.hrl").
  4. -compile(export_all).
  5. all() -> [multiapp].
  6. init_per_testcase(multiapp, Config) ->
  7. application:load(rebar),
  8. DataDir = ?config(data_dir, Config),
  9. PrivDir = ?config(priv_dir, Config),
  10. Name = rebar_test_utils:create_random_name("multiapp"),
  11. AppsDir = filename:join([PrivDir, rebar_test_utils:create_random_name(Name)]),
  12. ec_file:copy(filename:join([DataDir, "foo"]), AppsDir, [recursive]),
  13. Verbosity = rebar3:log_level(),
  14. rebar_log:init(command_line, Verbosity),
  15. State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
  16. ,{root_dir, AppsDir}]),
  17. [{apps, AppsDir}, {state, State}, {name, Name} | Config].
  18. end_per_testcase(_, Config) ->
  19. Config.
  20. multiapp(Config) ->
  21. %% With an empty config (no `dir'), links are being processed
  22. RebarConfig = [],
  23. rebar_test_utils:run_and_check(Config, RebarConfig, ["edoc"], {ok, []}),
  24. %% validate that all doc entries are generated and links work
  25. AppsDir = ?config(apps, Config),
  26. ct:pal("AppsDir: ~s", [AppsDir]),
  27. ?assert(file_content_matches(
  28. filename:join([AppsDir, "apps", "bar1", "doc", "bar1.html"]),
  29. "barer1")),
  30. ?assert(file_content_matches(
  31. filename:join([AppsDir, "apps", "bar2", "doc", "bar2.html"]),
  32. "barer2")),
  33. %% Links are in place for types
  34. ?assert(file_content_matches(
  35. filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]),
  36. "barer1")),
  37. ?assert(file_content_matches(
  38. filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]),
  39. "apps/bar1/doc/bar1.html")).
  40. file_content_matches(Path, Regex) ->
  41. case file:read_file(Path) of
  42. {ok, Bin} ->
  43. nomatch =/= re:run(Bin, Regex);
  44. {error, Reason} ->
  45. Reason
  46. end.