Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

105 Zeilen
3.5 KiB

  1. %%% This suite can't run tests for built-in templates because
  2. %%% they require being escriptize and we currently don't support
  3. %%% this in here!
  4. -module(rebar_new_SUITE).
  5. -compile(export_all).
  6. -include_lib("common_test/include/ct.hrl").
  7. -include_lib("eunit/include/eunit.hrl").
  8. all() -> [app_git_user, app_hg_user, app_with_fallbacks].
  9. init_per_testcase(Case, Config0) ->
  10. Config = rebar_test_utils:init_rebar_state(Config0),
  11. Name = rebar_test_utils:create_random_name(atom_to_list(Case)),
  12. Data = ?config(data_dir, Config),
  13. mock_home_dir(Data),
  14. mock_empty_escript_templates(),
  15. [{name, Name} | Config].
  16. end_per_testcase(_, Config) ->
  17. meck:unload(),
  18. Config.
  19. mock_home_dir(Path) ->
  20. meck:new(rebar_dir, [passthrough]),
  21. meck:expect(rebar_dir, template_dir, fun(_) -> Path end).
  22. mock_empty_escript_templates() ->
  23. %% Can't find escript templates unless we run
  24. %% from the escript, which obviously crashes these here tests.
  25. meck:new(rebar_utils, [passthrough]),
  26. meck:expect(rebar_utils, escript_foldl, fun(_,_,_) -> {ok, []} end).
  27. app_git_user(Config) ->
  28. meck:expect(rebar_utils, sh, fun("git config --global user.name", _) -> {ok, "gitname"};
  29. ("git config --global user.email", _) -> {ok, "git@email.com"}
  30. end),
  31. Name = ?config(name, Config),
  32. rebar_test_utils:run_and_check(
  33. Config, [],
  34. ["new", "test_app", Name, "author_name=some_name"],
  35. {ok, []}
  36. ),
  37. validate_files(
  38. Config, Name,
  39. [{"LICENSE", ["some_name", "git@email.com"]},
  40. {"README.md", [Name]},
  41. {".gitignore", []},
  42. {"rebar.config", []},
  43. {filename:join(["src", Name++".app.src"]), [Name]},
  44. {filename:join(["src", Name++"_sup.erl"]), [Name]},
  45. {filename:join(["src", Name++"_app.erl"]), [Name]}
  46. ]).
  47. app_with_fallbacks(Config) ->
  48. meck:expect(rebar_utils, sh, fun(_, _) -> {error, fallback} end),
  49. Name = ?config(name, Config),
  50. rebar_test_utils:run_and_check(
  51. Config, [],
  52. ["new", "test_app", Name],
  53. {ok, []}
  54. ),
  55. validate_files(
  56. Config, Name,
  57. [{"LICENSE", ["Anonymous", "anonymous@example.org"]},
  58. {"README.md", [Name]},
  59. {".gitignore", []},
  60. {"rebar.config", []},
  61. {filename:join(["src", Name++".app.src"]), [Name]},
  62. {filename:join(["src", Name++"_sup.erl"]), [Name]},
  63. {filename:join(["src", Name++"_app.erl"]), [Name]}
  64. ]).
  65. app_hg_user(Config) ->
  66. meck:expect(rebar_utils, sh, fun("hg showconfig ui.username", _) -> {ok, "hgname <hg@email.com>"};
  67. (_, _) -> {error, fallback}
  68. end),
  69. Name = ?config(name, Config),
  70. rebar_test_utils:run_and_check(
  71. Config, [],
  72. ["new", "test_app", Name],
  73. {ok, []}
  74. ),
  75. validate_files(
  76. Config, Name,
  77. [{"LICENSE", ["hgname", "hg@email.com"]},
  78. {"README.md", [Name]},
  79. {".gitignore", []},
  80. {"rebar.config", []},
  81. {filename:join(["src", Name++".app.src"]), [Name]},
  82. {filename:join(["src", Name++"_sup.erl"]), [Name]},
  83. {filename:join(["src", Name++"_app.erl"]), [Name]}
  84. ]).
  85. validate_files(_Config, Name, Checks) ->
  86. [begin
  87. Path = filename:join([Name, File]),
  88. {ok, Bin} = file:read_file(Path),
  89. [{match, _} = re:run(Bin, Pattern, [multiline,global])
  90. || Pattern <- Patterns]
  91. end || {File, Patterns} <- Checks],
  92. ok.