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.

72 lines
2.7 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, error_survival].
  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. init_per_testcase(error_survival, Config) ->
  19. application:load(rebar),
  20. DataDir = ?config(data_dir, Config),
  21. PrivDir = ?config(priv_dir, Config),
  22. Name = rebar_test_utils:create_random_name("error_survival"),
  23. AppsDir = filename:join([PrivDir, rebar_test_utils:create_random_name(Name)]),
  24. ec_file:copy(filename:join([DataDir, "bad"]), AppsDir, [recursive]),
  25. Verbosity = rebar3:log_level(),
  26. rebar_log:init(command_line, Verbosity),
  27. State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
  28. ,{root_dir, AppsDir}]),
  29. [{apps, AppsDir}, {state, State}, {name, Name} | Config].
  30. end_per_testcase(_, Config) ->
  31. Config.
  32. multiapp(Config) ->
  33. %% With an empty config (no `dir'), links are being processed
  34. RebarConfig = [],
  35. rebar_test_utils:run_and_check(Config, RebarConfig, ["edoc"], {ok, []}),
  36. %% validate that all doc entries are generated and links work
  37. AppsDir = ?config(apps, Config),
  38. ct:pal("AppsDir: ~s", [AppsDir]),
  39. ?assert(file_content_matches(
  40. filename:join([AppsDir, "apps", "bar1", "doc", "bar1.html"]),
  41. "barer1")),
  42. ?assert(file_content_matches(
  43. filename:join([AppsDir, "apps", "bar2", "doc", "bar2.html"]),
  44. "barer2")),
  45. %% Links are in place for types
  46. ?assert(file_content_matches(
  47. filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]),
  48. "barer1")),
  49. ?assert(file_content_matches(
  50. filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]),
  51. "apps/bar1/doc/bar1.html")).
  52. error_survival(Config) ->
  53. RebarConfig = [],
  54. rebar_test_utils:run_and_check(
  55. Config, RebarConfig, ["edoc"],
  56. {error,{rebar_prv_edoc,{app_failed,"bar2"}}}
  57. ),
  58. ok.
  59. file_content_matches(Path, Regex) ->
  60. case file:read_file(Path) of
  61. {ok, Bin} ->
  62. nomatch =/= re:run(Bin, Regex);
  63. {error, Reason} ->
  64. Reason
  65. end.