Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

113 rindas
3.5 KiB

  1. -module(rebar_namespace_SUITE).
  2. -compile(export_all).
  3. -include_lib("common_test/include/ct.hrl").
  4. -include_lib("eunit/include/eunit.hrl").
  5. all() -> [implicit_compile, default_compile, do_compile,
  6. as_default_compile, as_do_compile,
  7. notfound, do_notfound, default_notfound, ns_notfound, ns_found,
  8. as_ns_invalid].
  9. init_per_testcase(Case, Config0) ->
  10. Config = rebar_test_utils:init_rebar_state(Config0),
  11. AppDir = ?config(apps, Config),
  12. Name = rebar_test_utils:create_random_name("app1_"++atom_to_list(Case)),
  13. Vsn = rebar_test_utils:create_random_vsn(),
  14. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  15. [{name, Name} | Config].
  16. end_per_testcase(_, Config) ->
  17. Config.
  18. implicit_compile(Config) ->
  19. Name = ?config(name, Config),
  20. rebar_test_utils:run_and_check(Config, [],
  21. ["compile"],
  22. {ok, [{app, Name}]}).
  23. default_compile(Config) ->
  24. Name = ?config(name, Config),
  25. rebar_test_utils:run_and_check(Config, [],
  26. ["default","compile"],
  27. {ok, [{app, Name}]}).
  28. do_compile(Config) ->
  29. Name = ?config(name, Config),
  30. rebar_test_utils:run_and_check(Config, [],
  31. ["do", "compile"],
  32. {ok, [{app, Name}]}).
  33. as_default_compile(Config) ->
  34. Name = ?config(name, Config),
  35. rebar_test_utils:run_and_check(Config, [],
  36. ["as", "prod", "default", "compile"],
  37. {ok, [{app, Name}]}).
  38. as_do_compile(Config) ->
  39. Name = ?config(name, Config),
  40. rebar_test_utils:run_and_check(Config, [],
  41. ["as", "prod", "do", "compile"],
  42. {ok, [{app, Name}]}).
  43. notfound(Config) ->
  44. Command = ["fakecommand"],
  45. rebar_test_utils:run_and_check(
  46. Config, [], Command,
  47. {error, io_lib:format("Command ~p not found", [fakecommand])}
  48. ).
  49. do_notfound(Config) ->
  50. Command = ["do", "fakecommand"],
  51. rebar_test_utils:run_and_check(
  52. Config, [], Command,
  53. {error, io_lib:format("Command ~p not found", [fakecommand])}
  54. ).
  55. default_notfound(Config) ->
  56. Command = ["default", "fakecommand"],
  57. rebar_test_utils:run_and_check(
  58. Config, [], Command,
  59. {error, io_lib:format("Command ~p not found", [fakecommand])}
  60. ).
  61. ns_notfound(Config) ->
  62. Command = ["ns", "fakecommand"],
  63. rebar_test_utils:run_and_check(
  64. add_fake_ns_provider(Config), [], Command,
  65. {error, io_lib:format("Command ~p not found in namespace ~p",
  66. [fakecommand, ns])}
  67. ).
  68. ns_found(Config) ->
  69. Command = ["ns", "fake_provider"],
  70. rebar_test_utils:run_and_check(
  71. add_fake_ns_provider(Config), [], Command,
  72. {ok, []}
  73. ).
  74. as_ns_invalid(Config) ->
  75. %% The as namespace is not valid
  76. Command = ["as", "profile", "as", "task"],
  77. rebar_test_utils:run_and_check(
  78. add_fake_ns_provider(Config), [], Command,
  79. {error, "Namespace 'as' is forbidden"}
  80. ).
  81. %%% Helpers %%%
  82. add_fake_ns_provider(Config) ->
  83. State = ?config(state, Config),
  84. State1 = rebar_state:add_provider(
  85. State,
  86. providers:create(
  87. [{name, fake_provider},
  88. {module, ?MODULE},
  89. {namespace, ns},
  90. {deps, []},
  91. {opts, []}]
  92. )
  93. ),
  94. [{state, State1} | Config].
  95. %% callback for the test suite.
  96. do(State) -> {ok, State}.