25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

135 satır
5.2 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, multiapp_macros, 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(multiapp_macros, 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("multiapp_macros"),
  23. AppsDir = filename:join([PrivDir, rebar_test_utils:create_random_name(Name)]),
  24. ec_file:copy(filename:join([DataDir, "foo"]), AppsDir, [recursive]),
  25. ok = ec_file:remove(filename:join([AppsDir, "apps", "foo"]), [recursive]),
  26. Verbosity = rebar3:log_level(),
  27. rebar_log:init(command_line, Verbosity),
  28. State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
  29. ,{root_dir, AppsDir}]),
  30. [{apps, AppsDir}, {state, State}, {name, Name} | Config];
  31. init_per_testcase(error_survival, Config) ->
  32. application:load(rebar),
  33. DataDir = ?config(data_dir, Config),
  34. PrivDir = ?config(priv_dir, Config),
  35. Name = rebar_test_utils:create_random_name("error_survival"),
  36. AppsDir = filename:join([PrivDir, rebar_test_utils:create_random_name(Name)]),
  37. ec_file:copy(filename:join([DataDir, "bad"]), AppsDir, [recursive]),
  38. Verbosity = rebar3:log_level(),
  39. rebar_log:init(command_line, Verbosity),
  40. State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
  41. ,{root_dir, AppsDir}]),
  42. [{apps, AppsDir}, {state, State}, {name, Name} | Config].
  43. end_per_testcase(_, Config) ->
  44. Config.
  45. multiapp(Config) ->
  46. %% With an empty config (no `dir'), links are being processed
  47. RebarConfig = [],
  48. rebar_test_utils:run_and_check(Config, RebarConfig, ["edoc"], {ok, []}),
  49. %% validate that all doc entries are generated and links work
  50. AppsDir = ?config(apps, Config),
  51. ct:pal("AppsDir: ~s", [AppsDir]),
  52. ?assert(file_content_matches(
  53. filename:join([AppsDir, "apps", "bar1", "doc", "bar1.html"]),
  54. "barer1")),
  55. ?assert(file_content_matches(
  56. filename:join([AppsDir, "apps", "bar2", "doc", "bar2.html"]),
  57. "barer2")),
  58. %% Links are in place for types
  59. ?assert(file_content_matches(
  60. filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]),
  61. "barer1")),
  62. ?assert(file_content_matches(
  63. filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]),
  64. "apps/bar1/doc/bar1.html")),
  65. %% Options such from rebar.config in the app themselves are
  66. %% respected
  67. ?assert(file_content_matches(
  68. filename:join([AppsDir, "apps", "foo", "doc", "overview-summary.html"]),
  69. "foo_custom_title"
  70. )),
  71. ok.
  72. multiapp_macros(Config) ->
  73. RebarConfig = [{edoc_opts, [
  74. preprocess,
  75. {macros, [{m1, x1}, {m2, x2}]},
  76. {def, [{d1, "1"}, {d2, "1"}]}
  77. ]}],
  78. AppConfig = {edoc_opts, [
  79. {preprocess, true},
  80. {macros, [{m2, f2}, {m3, f3}]},
  81. {def, [{d2, "2"}, {d3, "2"}]}
  82. ]},
  83. DebugModule = "
  84. -module(debug).
  85. -ifndef(m1). -define(m1,z1). -endif.
  86. -ifndef(m2). -define(m2,z2). -endif.
  87. -ifndef(m3). -define(m3,z3). -endif.
  88. -export([?m1 /0, ?m2 /0, ?m3 /0]).
  89. %% @doc
  90. %% d1:{@d1}
  91. %% d2:{@d2}
  92. %% d3:{@d3}
  93. %% @end
  94. ?m1 () -> ok.
  95. ?m2 () -> ok.
  96. ?m3 () -> ok.
  97. ",
  98. AppsDir = ?config(apps, Config),
  99. ct:pal("AppsDir: ~s", [AppsDir]),
  100. ok = file:write_file(filename:join([AppsDir, "apps", "bar1", "rebar.config"]),
  101. io_lib:format("~p.~n", [AppConfig])),
  102. ok = file:write_file(filename:join([AppsDir, "apps", "bar1", "src", "debug.erl"]),
  103. DebugModule),
  104. rebar_test_utils:run_and_check(Config, RebarConfig, ["edoc"], {ok, []}),
  105. DocFile = filename:join([AppsDir, "apps", "bar1", "doc", "debug.html"]),
  106. ?assert(file_content_matches(DocFile, "d1:1")), % config layered
  107. ?assert(file_content_matches(DocFile, "d2:2")),
  108. ?assert(file_content_matches(DocFile, "d3:2")),
  109. ?assert(file_content_matches(DocFile, "x1/0")), % elided in config drop
  110. ?assert(file_content_matches(DocFile, "f2/0")),
  111. ?assert(file_content_matches(DocFile, "f3/0")),
  112. ok.
  113. error_survival(Config) ->
  114. RebarConfig = [],
  115. rebar_test_utils:run_and_check(
  116. Config, RebarConfig, ["edoc"],
  117. {error,{rebar_prv_edoc,{app_failed,"bad_bar2"}}}
  118. ),
  119. ok.
  120. file_content_matches(Path, Regex) ->
  121. case file:read_file(Path) of
  122. {ok, Bin} ->
  123. nomatch =/= re:run(Bin, Regex);
  124. {error, Reason} ->
  125. Reason
  126. end.