Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

98 строки
2.8 KiB

11 лет назад
  1. -module(erlc_rt).
  2. -export([files/0,
  3. run/1]).
  4. -include_lib("eunit/include/eunit.hrl").
  5. -define(MODULES,
  6. [first_xrl,
  7. first_yrl,
  8. foo,
  9. foo_app,
  10. foo_sup,
  11. foo_test_worker,
  12. foo_worker,
  13. 'SIMPLE-ASN']).
  14. -define(BEAM_FILES,
  15. ["first_xrl.beam",
  16. "first_yrl.beam",
  17. "foo.beam",
  18. "foo_app.beam",
  19. "foo_sup.beam",
  20. "foo_test_worker.beam",
  21. "foo_worker.beam",
  22. "SIMPLE-ASN.beam"]).
  23. files() ->
  24. [
  25. {copy, "../../rebar", "rebar"},
  26. {copy, "rebar.config", "rebar.config"},
  27. {copy, "rebar-no_debug_info.config", "rebar-no_debug_info.config"},
  28. {copy, "include", "include"},
  29. {copy, "extra-include", "extra-include"},
  30. {copy, "src", "src"},
  31. {copy, "extra-src", "extra-src"},
  32. {copy, "mibs", "mibs"},
  33. {copy, "asn1", "asn1"},
  34. {create, "ebin/foo.app", app(foo, ?MODULES)}
  35. ].
  36. run(_Dir) ->
  37. ?assertMatch({ok, _}, retest_sh:run("./rebar compile", [])),
  38. ok = check_beams(true),
  39. ok = check_debug_info(true),
  40. MibResult = filename:join(["priv", "mibs", "SIMPLE-MIB.bin"]),
  41. ?assertMatch(true, filelib:is_regular(MibResult)),
  42. ?assertMatch({ok, _}, retest_sh:run("./rebar clean", [])),
  43. ok = check_beams(false),
  44. ?assertMatch(false, filelib:is_regular(MibResult)),
  45. ?assertMatch(
  46. {ok, _},
  47. retest_sh:run("./rebar -C rebar-no_debug_info.config compile", [])),
  48. ok = check_beams(true),
  49. ok = check_debug_info(false),
  50. ?assertMatch(true, filelib:is_regular(MibResult)),
  51. ok.
  52. check_beams(Exist) ->
  53. check_files(Exist, fun filelib:is_regular/1).
  54. check_debug_info(HasDebugInfo) ->
  55. check_files(HasDebugInfo, fun has_debug_info/1).
  56. check_files(Expected, Check) ->
  57. lists:foreach(
  58. fun(F) ->
  59. File = filename:join("ebin", F),
  60. ?assertEqual(Expected, Check(File))
  61. end,
  62. ?BEAM_FILES).
  63. %% NOTE: Copied from dialyzer_utils:get_abstract_code_from_beam/1 and
  64. %% modified for local use. We could have called the function directly,
  65. %% but dialyzer_utils is not an official API to rely on.
  66. has_debug_info(File) ->
  67. case beam_lib:chunks(File, [abstract_code]) of
  68. {ok, {_Mod, List}} ->
  69. case lists:keyfind(abstract_code, 1, List) of
  70. {abstract_code, {raw_abstract_v1, _Abstr}} ->
  71. true;
  72. _ ->
  73. false
  74. end;
  75. _ ->
  76. false
  77. end.
  78. %%
  79. %% Generate the contents of a simple .app file
  80. %%
  81. app(Name, Modules) ->
  82. App = {application, Name,
  83. [{description, atom_to_list(Name)},
  84. {vsn, "1"},
  85. {modules, Modules},
  86. {registered, []},
  87. {applications, [kernel, stdlib]}]},
  88. io_lib:format("~p.\n", [App]).