您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

165 行
6.3 KiB

  1. -module(rebar_alias_SUITE).
  2. -compile([export_all]).
  3. -include_lib("common_test/include/ct.hrl").
  4. -include_lib("eunit/include/eunit.hrl").
  5. init_per_suite(Config) -> Config.
  6. end_per_suite(_Config) -> ok.
  7. init_per_testcase(_, Config) ->
  8. rebar_test_utils:init_rebar_state(Config, "alias_").
  9. end_per_testcase(_, _Config) ->
  10. ok.
  11. all() -> [command, args, many, override_default, no_circular, release,
  12. check_namespaces, create_lib].
  13. command() ->
  14. [{doc, "Runs multiple regular commands as one alias"}].
  15. command(Config) ->
  16. AppDir = ?config(apps, Config),
  17. Name = rebar_test_utils:create_random_name("alias_command_"),
  18. Vsn = rebar_test_utils:create_random_vsn(),
  19. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  20. RebarConfig = [{alias, [{test, [compile, unlock]}]}],
  21. %% compile job ran
  22. rebar_test_utils:run_and_check(Config, RebarConfig,
  23. ["test"], {ok, [{app, Name}]}),
  24. %% unlock job also ran
  25. Lockfile = filename:join(?config(apps, Config), "rebar.lock"),
  26. ?assertNot(filelib:is_file(Lockfile)),
  27. ok.
  28. args() ->
  29. [{doc, "Runs multiple regular commands as one alias, some of "
  30. "which have default arguments"}].
  31. args(Config) ->
  32. AppDir = ?config(apps, Config),
  33. Name = rebar_test_utils:create_random_name("alias_args_"),
  34. Vsn = rebar_test_utils:create_random_vsn(),
  35. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  36. RebarConfig = [{alias, [{test, [{eunit,"-c"}, cover]}]}],
  37. %% test job ran (compiled and succeeded)
  38. rebar_test_utils:run_and_check(Config, RebarConfig,
  39. ["test"], {ok, [{app, Name}]}),
  40. %% cover job also ran, meaning eunit had coverage on, otherwise
  41. %% the index file is not generated.
  42. CoverFile = filename:join([?config(apps, Config),
  43. "_build", "test", "cover", "index.html"]),
  44. ?assert(filelib:is_file(CoverFile)),
  45. ok.
  46. many() ->
  47. [{doc, "Multiple aliases may be registered"}].
  48. many(Config) ->
  49. AppDir = ?config(apps, Config),
  50. Name = rebar_test_utils:create_random_name("alias_args_"),
  51. Vsn = rebar_test_utils:create_random_vsn(),
  52. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  53. RebarConfig = [{alias, [{test, [{eunit,"-c"}, cover]},
  54. {nolock, [compile, unlock]}]}],
  55. %% test job ran (compiled and succeeded)
  56. rebar_test_utils:run_and_check(Config, RebarConfig,
  57. ["test"], {ok, [{app, Name}]}),
  58. rebar_test_utils:run_and_check(Config, RebarConfig,
  59. ["nolock"], {ok, [{app, Name}]}),
  60. %% both jobs ran (see args/1 and command/1)
  61. CoverFile = filename:join([?config(apps, Config),
  62. "_build", "test", "cover", "index.html"]),
  63. ?assert(filelib:is_file(CoverFile)),
  64. Lockfile = filename:join(?config(apps, Config), "rebar.lock"),
  65. ?assertNot(filelib:is_file(Lockfile)),
  66. ok.
  67. override_default() ->
  68. [{doc, "An alias cannot take over a default provider"}].
  69. override_default(Config) ->
  70. AppDir = ?config(apps, Config),
  71. Name = rebar_test_utils:create_random_name("alias_override_"),
  72. Vsn = rebar_test_utils:create_random_vsn(),
  73. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  74. RebarConfig = [{alias, [{compile, [help]}]}],
  75. %% App compiles anyway
  76. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  77. {ok, [{app, Name}]}),
  78. ok.
  79. no_circular() ->
  80. [{doc, "An alias cannot define itself as itself"},
  81. {timetrap, 2000}].
  82. no_circular(Config) ->
  83. AppDir = ?config(apps, Config),
  84. Name = rebar_test_utils:create_random_name("alias_circular_"),
  85. Vsn = rebar_test_utils:create_random_vsn(),
  86. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  87. RebarConfig = [{alias, [{test, [help, {test,"-a"}, compile]}]}],
  88. %% Code does not deadlock forever and errors by not knowing
  89. %% the command
  90. rebar_test_utils:run_and_check(Config, RebarConfig, ["test"],
  91. {error, [$C,$o,$m,$m,$a,$n,$d,$ ,"test",$ ,$n,$o,$t,$ ,
  92. $f,$o,$u,$n,$d]}),
  93. ok.
  94. release() ->
  95. [{doc, "An alias for a release command"}].
  96. release(Config) ->
  97. AppDir = ?config(apps, Config),
  98. Name = rebar_test_utils:create_random_name("alias_release_"),
  99. Vsn = rebar_test_utils:create_random_vsn(),
  100. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  101. RebarConfig = [{relx,
  102. [{release, {skipped_release, Vsn}, []},
  103. {release, {the_release, Vsn}, [list_to_atom(Name)]},
  104. {lib_dirs, [AppDir]}]},
  105. {alias,
  106. [{the_rel1, [clean, {release, "-n the_release"}]},
  107. {the_rel2, [clean, {release, "--relname=the_release"}]}]}],
  108. rebar_test_utils:run_and_check(
  109. Config, RebarConfig,
  110. ["the_rel1"],
  111. {ok, [{release, the_release, Vsn, false}]}),
  112. rebar_test_utils:run_and_check(
  113. Config, RebarConfig,
  114. ["the_rel2"],
  115. {ok, [{release, the_release, Vsn, false}]}),
  116. ok.
  117. check_namespaces() ->
  118. [{doc, "Test calling commands with namespaces from rebar3"}].
  119. check_namespaces(Config) ->
  120. AppDir = ?config(apps, Config),
  121. Name = rebar_test_utils:create_random_name("alias_args_"),
  122. Vsn = rebar_test_utils:create_random_vsn(),
  123. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  124. RebarConfig = [{alias, [{test, [{eunit,"-c"}, {plugins, list}]}]}],
  125. rebar_test_utils:run_and_check(Config, RebarConfig,
  126. ["test"], {ok, [{app, Name}]}),
  127. ok.
  128. create_lib() ->
  129. [{doc, "Test calling commands with namespaces from rebar3"}].
  130. create_lib(Config) ->
  131. AppDir = ?config(apps, Config),
  132. Name = rebar_test_utils:create_random_name("create_lib_"),
  133. Vsn = rebar_test_utils:create_random_vsn(),
  134. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  135. RebarConfig = [{alias, [{test, [compile, {do, "new lib shouldexist"}]}]}],
  136. rebar_test_utils:run_and_check(Config, RebarConfig,
  137. ["test"], {ok, [{app, Name}]}),
  138. AppFile = filename:join(?config(apps, Config),
  139. "../../../../shouldexist/src/shouldexist.app.src"),
  140. ?assert(filelib:is_file(AppFile)),
  141. ok.