You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 line
1.9 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].
  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, home_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(Config) ->
  28. Name = ?config(name, Config),
  29. rebar_test_utils:run_and_check(
  30. Config, [],
  31. ["new", "test_app", Name, "author_name=some_name"],
  32. {ok, []}
  33. ),
  34. validate_files(
  35. Config, Name,
  36. [{"LICENSE", ["some_name", "anonymous@example.org"]},
  37. {"README.md", [Name]},
  38. {".gitignore", []},
  39. {"rebar.config", []},
  40. {filename:join(["src", Name++".app.src"]), [Name]},
  41. {filename:join(["src", Name++"_sup.erl"]), [Name]},
  42. {filename:join(["src", Name++"_app.erl"]), [Name]}
  43. ]).
  44. validate_files(_Config, Name, Checks) ->
  45. [begin
  46. Path = filename:join([Name, File]),
  47. {ok, Bin} = file:read_file(Path),
  48. [{match, _} = re:run(Bin, Pattern, [multiline,global])
  49. || Pattern <- Patterns]
  50. end || {File, Patterns} <- Checks],
  51. ok.