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

93 行
3.0 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].
  8. init_per_testcase(Case, Config0) ->
  9. Config = rebar_test_utils:init_rebar_state(Config0),
  10. AppDir = ?config(apps, Config),
  11. Name = rebar_test_utils:create_random_name("app1_"++atom_to_list(Case)),
  12. Vsn = rebar_test_utils:create_random_vsn(),
  13. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  14. [{name, Name} | Config].
  15. end_per_testcase(_, Config) ->
  16. Config.
  17. implicit_compile(Config) ->
  18. Name = ?config(name, Config),
  19. rebar_test_utils:run_and_check(Config, [],
  20. ["compile"],
  21. {ok, [{app, Name}]}).
  22. default_compile(Config) ->
  23. Name = ?config(name, Config),
  24. rebar_test_utils:run_and_check(Config, [],
  25. ["default","compile"],
  26. {ok, [{app, Name}]}).
  27. do_compile(Config) ->
  28. Name = ?config(name, Config),
  29. rebar_test_utils:run_and_check(Config, [],
  30. ["do", "compile"],
  31. {ok, [{app, Name}]}).
  32. as_default_compile(Config) ->
  33. Name = ?config(name, Config),
  34. rebar_test_utils:run_and_check(Config, [],
  35. ["as", "prod", "default", "compile"],
  36. {ok, [{app, Name}]}).
  37. as_do_compile(Config) ->
  38. Name = ?config(name, Config),
  39. rebar_test_utils:run_and_check(Config, [],
  40. ["as", "prod", "do", "compile"],
  41. {ok, [{app, Name}]}).
  42. notfound(Config) ->
  43. Command = ["fakecommand"],
  44. rebar_test_utils:run_and_check(
  45. Config, [], Command,
  46. {error, io_lib:format("Command ~p not found", [fakecommand])}
  47. ).
  48. do_notfound(Config) ->
  49. Command = ["do", "fakecommand"],
  50. rebar_test_utils:run_and_check(
  51. Config, [], Command,
  52. {error, io_lib:format("Command ~p not found", [fakecommand])}
  53. ).
  54. default_notfound(Config) ->
  55. Command = ["default", "fakecommand"],
  56. rebar_test_utils:run_and_check(
  57. Config, [], Command,
  58. {error, io_lib:format("Command ~p not found", [fakecommand])}
  59. ).
  60. ns_notfound(Config) ->
  61. Command = ["ns", "fakecommand"],
  62. rebar_test_utils:run_and_check(
  63. add_fake_ns_provider(Config), [], Command,
  64. {error, io_lib:format("Command ~p not found in namespace ~p",
  65. [fakecommand, ns])}
  66. ).
  67. %%% Helpers %%%
  68. add_fake_ns_provider(Config) ->
  69. State = ?config(state, Config),
  70. State1 = rebar_state:add_provider(
  71. State,
  72. providers:create(
  73. [{name, fake_provider},
  74. {module, fake_provider},
  75. {namespace, ns},
  76. {deps, []},
  77. {opts, []}]
  78. )
  79. ),
  80. [{state, State1} | Config].