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.

84 line
2.6 KiB

  1. -module(rebar_escriptize_SUITE).
  2. -export([suite/0,
  3. init_per_suite/1,
  4. end_per_suite/1,
  5. init_per_testcase/2,
  6. all/0,
  7. escriptize_with_name/1,
  8. escriptize_with_bad_name/1,
  9. build_and_clean_app/1,
  10. escriptize_with_ebin_subdir/1]).
  11. -include_lib("common_test/include/ct.hrl").
  12. -include_lib("eunit/include/eunit.hrl").
  13. -include_lib("kernel/include/file.hrl").
  14. suite() ->
  15. [].
  16. init_per_suite(Config) ->
  17. Config.
  18. end_per_suite(_Config) ->
  19. ok.
  20. init_per_testcase(_, Config) ->
  21. rebar_test_utils:init_rebar_state(Config).
  22. all() ->
  23. [
  24. build_and_clean_app,
  25. escriptize_with_name,
  26. escriptize_with_bad_name,
  27. escriptize_with_ebin_subdir
  28. ].
  29. %% Test escriptize builds and runs the app's escript
  30. build_and_clean_app(Config) ->
  31. AppDir = ?config(apps, Config),
  32. Name = rebar_test_utils:create_random_name("app1_"),
  33. Vsn = rebar_test_utils:create_random_vsn(),
  34. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  35. rebar_test_utils:run_and_check(Config, [], ["escriptize"],
  36. {ok, [{app, Name, valid}]}).
  37. escriptize_with_name(Config) ->
  38. AppDir = ?config(apps, Config),
  39. Name = rebar_test_utils:create_random_name("app1_"),
  40. Vsn = rebar_test_utils:create_random_vsn(),
  41. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  42. rebar_test_utils:run_and_check(Config, [{escript_main_app, Name}], ["escriptize"],
  43. {ok, [{app, Name, valid}]}).
  44. escriptize_with_bad_name(Config) ->
  45. AppDir = ?config(apps, Config),
  46. Name = rebar_test_utils:create_random_name("app1_"),
  47. Vsn = rebar_test_utils:create_random_vsn(),
  48. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  49. rebar_test_utils:run_and_check(Config, [{escript_main_app, boogers}], ["escriptize"],
  50. {error,{rebar_prv_escriptize, {bad_name, boogers}}}).
  51. escriptize_with_ebin_subdir(Config) ->
  52. AppDir = ?config(apps, Config),
  53. Name = rebar_test_utils:create_random_name("app1_"),
  54. Vsn = rebar_test_utils:create_random_vsn(),
  55. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  56. filelib:ensure_dir(filename:join([AppDir, "ebin", "subdir", "subdirfile"])),
  57. %% To work, this test must run from the AppDir itself. To avoid breaking
  58. %% other tests, be careful with cwd
  59. Cwd = file:get_cwd(),
  60. try
  61. file:set_cwd(AppDir),
  62. {ok, _} = rebar3:run(rebar_state:new(?config(state,Config), [], AppDir),
  63. ["escriptize"])
  64. after
  65. file:set_cwd(Cwd) % reset always
  66. end,
  67. ok.