Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

2210 rader
86 KiB

10 år sedan
support for hex v2, multiple repository fetching, private organizations (#1884) * update to hex_core for hex-v2 repo support (#1865) * update to hex_core for hex-v2 repo support This patch adds only single repo hex-v2 support through hex_core. Packages no longer filtered out by buildtool metadata and the package index is updated per-package instead of fetched as one large ets dump. * tell travis to also build hex_core branch * support list of repos for hex packages (#1866) * support list of repos for hex packages repos are defined under the hex key in rebar configs. They can be defined at the top level of a project or globally, but not in profiles and the repos configured in dependencies are also ignored. Searching for packages involves first checking for a match in the local repo index cache, in the order repos are defined. If not found each repo is checked through the hex api for any known versions of the package and the first repo with a version that fits the constraint is used. * add {repos, replace, []} for overriding the global & default repos * add hex auth handling for repos (#1874) auth token are kept in a hex.config file that is modified by the rebar3 hex plugin. Repo names that have a : separating a parent and child are considered organizations. The parent repo's auth will be included with the child. So an organization named hexpm:rebar3_test will include any hexpm auth tokens found in the rebar3_test organization's configuration. * move packages to top level of of hexpm cache dir (#1876) * move packages to top level of of hexpm cache dir * append organization name to parent's repo_url when parsing repos * only eval config scripts and apply overrides once per app (#1879) * only eval config scripts and apply overrides once per app * move new resource behaviour to rebar_resource_v2 and keep v1 * cleanup use of rebar_resource module and unused functions * cleanup error messages and unused code * when discovering apps support mix packages as unbuilt apps (#1882) * use hex_core tarball unpacking support in pkg resource (#1883) * use hex_core tarball unpacking support in pkg resource * ignore etag if package doesn't exist and delete if checksum fails * add back tests for bad package checksums * improve bad registry checksum error message
6 år sedan
10 år sedan
support for hex v2, multiple repository fetching, private organizations (#1884) * update to hex_core for hex-v2 repo support (#1865) * update to hex_core for hex-v2 repo support This patch adds only single repo hex-v2 support through hex_core. Packages no longer filtered out by buildtool metadata and the package index is updated per-package instead of fetched as one large ets dump. * tell travis to also build hex_core branch * support list of repos for hex packages (#1866) * support list of repos for hex packages repos are defined under the hex key in rebar configs. They can be defined at the top level of a project or globally, but not in profiles and the repos configured in dependencies are also ignored. Searching for packages involves first checking for a match in the local repo index cache, in the order repos are defined. If not found each repo is checked through the hex api for any known versions of the package and the first repo with a version that fits the constraint is used. * add {repos, replace, []} for overriding the global & default repos * add hex auth handling for repos (#1874) auth token are kept in a hex.config file that is modified by the rebar3 hex plugin. Repo names that have a : separating a parent and child are considered organizations. The parent repo's auth will be included with the child. So an organization named hexpm:rebar3_test will include any hexpm auth tokens found in the rebar3_test organization's configuration. * move packages to top level of of hexpm cache dir (#1876) * move packages to top level of of hexpm cache dir * append organization name to parent's repo_url when parsing repos * only eval config scripts and apply overrides once per app (#1879) * only eval config scripts and apply overrides once per app * move new resource behaviour to rebar_resource_v2 and keep v1 * cleanup use of rebar_resource module and unused functions * cleanup error messages and unused code * when discovering apps support mix packages as unbuilt apps (#1882) * use hex_core tarball unpacking support in pkg resource (#1883) * use hex_core tarball unpacking support in pkg resource * ignore etag if package doesn't exist and delete if checksum fails * add back tests for bad package checksums * improve bad registry checksum error message
6 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
support for hex v2, multiple repository fetching, private organizations (#1884) * update to hex_core for hex-v2 repo support (#1865) * update to hex_core for hex-v2 repo support This patch adds only single repo hex-v2 support through hex_core. Packages no longer filtered out by buildtool metadata and the package index is updated per-package instead of fetched as one large ets dump. * tell travis to also build hex_core branch * support list of repos for hex packages (#1866) * support list of repos for hex packages repos are defined under the hex key in rebar configs. They can be defined at the top level of a project or globally, but not in profiles and the repos configured in dependencies are also ignored. Searching for packages involves first checking for a match in the local repo index cache, in the order repos are defined. If not found each repo is checked through the hex api for any known versions of the package and the first repo with a version that fits the constraint is used. * add {repos, replace, []} for overriding the global & default repos * add hex auth handling for repos (#1874) auth token are kept in a hex.config file that is modified by the rebar3 hex plugin. Repo names that have a : separating a parent and child are considered organizations. The parent repo's auth will be included with the child. So an organization named hexpm:rebar3_test will include any hexpm auth tokens found in the rebar3_test organization's configuration. * move packages to top level of of hexpm cache dir (#1876) * move packages to top level of of hexpm cache dir * append organization name to parent's repo_url when parsing repos * only eval config scripts and apply overrides once per app (#1879) * only eval config scripts and apply overrides once per app * move new resource behaviour to rebar_resource_v2 and keep v1 * cleanup use of rebar_resource module and unused functions * cleanup error messages and unused code * when discovering apps support mix packages as unbuilt apps (#1882) * use hex_core tarball unpacking support in pkg resource (#1883) * use hex_core tarball unpacking support in pkg resource * ignore etag if package doesn't exist and delete if checksum fails * add back tests for bad package checksums * improve bad registry checksum error message
6 år sedan
  1. -module(rebar_compile_SUITE).
  2. -compile(export_all).
  3. -include_lib("common_test/include/ct.hrl").
  4. -include_lib("eunit/include/eunit.hrl").
  5. -include_lib("kernel/include/file.hrl").
  6. suite() ->
  7. [].
  8. all() ->
  9. [{group, basic_app}, {group, release_apps},
  10. {group, checkout_apps}, {group, checkout_deps},
  11. {group, basic_srcdirs}, {group, release_srcdirs}, {group, unbalanced_srcdirs},
  12. {group, basic_extras}, {group, release_extras}, {group, unbalanced_extras},
  13. {group, root_extras},
  14. recompile_when_hrl_changes, recompile_when_included_hrl_changes,
  15. recompile_when_opts_included_hrl_changes,
  16. recompile_when_opts_change,
  17. dont_recompile_when_opts_dont_change, dont_recompile_yrl_or_xrl,
  18. delete_beam_if_source_deleted,
  19. deps_in_path, checkout_priority, highest_version_of_pkg_dep,
  20. parse_transform_test, erl_first_files_test, mib_test,
  21. umbrella_mib_first_test, only_default_transitive_deps, clean_all,
  22. profile_deps, deps_build_in_prod, only_deps,
  23. override_deps, override_add_deps, override_del_deps,
  24. override_opts, override_add_opts, override_del_opts,
  25. apply_overrides_exactly_once,
  26. profile_override_deps, profile_override_add_deps, profile_override_del_deps,
  27. profile_override_opts, profile_override_add_opts, profile_override_del_opts,
  28. include_file_relative_to_working_directory, include_file_in_src,
  29. include_file_relative_to_working_directory_test, include_file_in_src_test,
  30. include_file_in_src_test_multiapp,
  31. recompile_when_parse_transform_as_opt_changes,
  32. recompile_when_parse_transform_inline_changes,
  33. regex_filter_skip, regex_filter_regression,
  34. recursive, no_recursive,
  35. always_recompile_when_erl_compiler_options_set,
  36. dont_recompile_when_erl_compiler_options_env_does_not_change,
  37. recompile_when_erl_compiler_options_env_changes,
  38. rebar_config_os_var].
  39. groups() ->
  40. [{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]},
  41. {release_apps, [], [build_release_apps, paths_release_apps, clean_release_apps]},
  42. {checkout_apps, [], [build_checkout_apps, paths_checkout_apps]},
  43. {checkout_deps, [], [build_checkout_deps, paths_checkout_deps]},
  44. {basic_srcdirs, [], [build_basic_srcdirs, paths_basic_srcdirs]},
  45. {release_srcdirs, [], [build_release_srcdirs,
  46. paths_release_srcdirs]},
  47. {unbalanced_srcdirs, [], [build_unbalanced_srcdirs,
  48. paths_unbalanced_srcdirs]},
  49. {basic_extras, [], [build_basic_extra_dirs,
  50. paths_basic_extra_dirs,
  51. clean_basic_extra_dirs]},
  52. {release_extras, [], [build_release_extra_dirs,
  53. paths_release_extra_dirs,
  54. clean_release_extra_dirs]},
  55. {unbalanced_extras, [], [build_unbalanced_extra_dirs,
  56. paths_unbalanced_extra_dirs]},
  57. {root_extras, [], [build_extra_dirs_in_project_root,
  58. paths_extra_dirs_in_project_root,
  59. clean_extra_dirs_in_project_root]}].
  60. init_per_group(basic_app, Config) ->
  61. NewConfig = rebar_test_utils:init_rebar_state(Config, "basic_app_"),
  62. AppDir = ?config(apps, NewConfig),
  63. Name = rebar_test_utils:create_random_name("app1"),
  64. Vsn = rebar_test_utils:create_random_vsn(),
  65. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  66. [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
  67. init_per_group(release_apps, Config) ->
  68. NewConfig = rebar_test_utils:init_rebar_state(Config, "release_apps_"),
  69. AppDir = ?config(apps, NewConfig),
  70. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  71. Vsn1 = rebar_test_utils:create_random_vsn(),
  72. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name1]), Name1, Vsn1, [kernel, stdlib]),
  73. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  74. Vsn2 = rebar_test_utils:create_random_vsn(),
  75. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]),
  76. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  77. init_per_group(checkout_apps, Config) ->
  78. NewConfig = rebar_test_utils:init_rebar_state(Config, "checkout_apps_"),
  79. AppDir = ?config(apps, NewConfig),
  80. CheckoutsDir = ?config(checkouts, NewConfig),
  81. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  82. Vsn1 = rebar_test_utils:create_random_vsn(),
  83. rebar_test_utils:create_app(AppDir, Name1, Vsn1, [kernel, stdlib]),
  84. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  85. Vsn2 = rebar_test_utils:create_random_vsn(),
  86. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  87. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  88. init_per_group(checkout_deps, Config) ->
  89. NewConfig = rebar_test_utils:init_rebar_state(Config, "checkout_deps_"),
  90. AppDir = ?config(apps, NewConfig),
  91. CheckoutsDir = ?config(checkouts, NewConfig),
  92. DepsDir = filename:join([AppDir, "_build", "default", "lib"]),
  93. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  94. Vsn1 = rebar_test_utils:create_random_vsn(),
  95. rebar_test_utils:create_app(AppDir, Name1, Vsn1, [kernel, stdlib]),
  96. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  97. Vsn2 = rebar_test_utils:create_random_vsn(),
  98. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  99. rebar_test_utils:create_app(filename:join([DepsDir,Name2]), Name2, Vsn1, [kernel, stdlib]),
  100. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  101. init_per_group(Group, Config) when Group == basic_srcdirs; Group == basic_extras ->
  102. NewConfig = rebar_test_utils:init_rebar_state(Config, "basic_srcdirs_"),
  103. AppDir = ?config(apps, NewConfig),
  104. Name = rebar_test_utils:create_random_name("app1_"),
  105. Vsn = rebar_test_utils:create_random_vsn(),
  106. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  107. ExtraSrc = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name]),
  108. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  109. ok = file:write_file(filename:join([AppDir, "extra", io_lib:format("~ts_extra.erl", [Name])]),
  110. ExtraSrc),
  111. [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
  112. init_per_group(Group, Config) when Group == release_srcdirs; Group == release_extras ->
  113. NewConfig = rebar_test_utils:init_rebar_state(Config, "release_srcdirs_"),
  114. AppDir = ?config(apps, NewConfig),
  115. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  116. Vsn1 = rebar_test_utils:create_random_vsn(),
  117. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  118. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  119. Vsn2 = rebar_test_utils:create_random_vsn(),
  120. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  121. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  122. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  123. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  124. io_lib:format("~ts_extra.erl", [Name1])]),
  125. ExtraOne),
  126. ExtraTwo = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name2]),
  127. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name2, "extra", "dummy"])),
  128. ok = file:write_file(filename:join([AppDir, "apps", Name2, "extra",
  129. io_lib:format("~ts_extra.erl", [Name2])]),
  130. ExtraTwo),
  131. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  132. init_per_group(Group, Config) when Group == unbalanced_srcdirs; Group == unbalanced_extras ->
  133. NewConfig = rebar_test_utils:init_rebar_state(Config, "unbalanced_srcdirs_"),
  134. AppDir = ?config(apps, NewConfig),
  135. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  136. Vsn1 = rebar_test_utils:create_random_vsn(),
  137. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  138. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  139. Vsn2 = rebar_test_utils:create_random_vsn(),
  140. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  141. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  142. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  143. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  144. io_lib:format("~ts_extra.erl", [Name1])]),
  145. ExtraOne),
  146. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  147. init_per_group(root_extras, Config) ->
  148. NewConfig = rebar_test_utils:init_rebar_state(Config, "root_extras_"),
  149. AppDir = ?config(apps, NewConfig),
  150. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  151. Vsn1 = rebar_test_utils:create_random_vsn(),
  152. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  153. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  154. Vsn2 = rebar_test_utils:create_random_vsn(),
  155. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  156. Extra = <<"-module(extra).\n-export([ok/0]).\nok() -> ok.\n">>,
  157. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  158. ok = file:write_file(filename:join([AppDir, "extra", "extra.erl"]), Extra),
  159. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig].
  160. end_per_group(_Group, _Config) ->
  161. ok.
  162. init_per_suite(Config) ->
  163. Config.
  164. end_per_suite(_Config) ->
  165. ok.
  166. init_per_testcase(Test, Config) when
  167. Test == dont_recompile_when_erl_compiler_options_env_does_not_change
  168. orelse
  169. Test == recompile_when_erl_compiler_options_env_changes ->
  170. _ = code:ensure_loaded(os),
  171. UnSetEnv = erlang:function_exported(os, unsetenv, 1),
  172. _ = code:ensure_loaded(compile),
  173. EnvOpts = erlang:function_exported(compile, env_compiler_options, 0),
  174. case {UnSetEnv, EnvOpts} of
  175. {true, true} -> maybe_init_config(Config);
  176. _ -> {skip, "compile:env_compiler_options/0 unavailable"}
  177. end;
  178. init_per_testcase(always_recompile_when_erl_compiler_options_set, Config) ->
  179. _ = code:ensure_loaded(os),
  180. UnSetEnv = erlang:function_exported(os, unsetenv, 1),
  181. _ = code:ensure_loaded(compile),
  182. EnvOpts = erlang:function_exported(compile, env_compiler_options, 0),
  183. case {UnSetEnv, EnvOpts} of
  184. {true, true} -> {skip, "compile:env_compiler_options/0 available"};
  185. {true, false} -> maybe_init_config(Config);
  186. _ -> {skip, "os:unsetenv/1 unavailable"}
  187. end;
  188. init_per_testcase(_, Config) -> maybe_init_config(Config).
  189. maybe_init_config(Config) ->
  190. case ?config(apps, Config) of
  191. undefined -> rebar_test_utils:init_rebar_state(Config);
  192. _ -> Config
  193. end.
  194. end_per_testcase(_, _Config) ->
  195. catch meck:unload().
  196. %% test cases
  197. build_basic_app(Config) ->
  198. [Name] = ?config(app_names, Config),
  199. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}).
  200. build_release_apps(Config) ->
  201. [Name1, Name2] = ?config(app_names, Config),
  202. rebar_test_utils:run_and_check(
  203. Config, [], ["compile"],
  204. {ok, [{app, Name1}, {app, Name2}]}
  205. ).
  206. build_checkout_apps(Config) ->
  207. [Name1, Name2] = ?config(app_names, Config),
  208. rebar_test_utils:run_and_check(
  209. Config, [], ["compile"],
  210. {ok, [{app, Name1}, {checkout, Name2}]}
  211. ).
  212. build_checkout_deps(Config) ->
  213. AppDir = ?config(apps, Config),
  214. [Name1, Name2] = ?config(app_names, Config),
  215. [_, Vsn2] = ?config(vsns, Config),
  216. Deps = [{list_to_atom(Name2), Vsn2, {git, "", ""}}],
  217. {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, Deps}])),
  218. rebar_test_utils:run_and_check(
  219. Config, RebarConfig, ["compile"],
  220. {ok, [{app, Name1}, {checkout, Name2}]}
  221. ).
  222. build_basic_srcdirs(Config) ->
  223. AppDir = ?config(apps, Config),
  224. [Name] = ?config(app_names, Config),
  225. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  226. %% check a beam corresponding to the src in the extra src_dir exists
  227. ExtraBeam = filename:join([AppDir, "_build", "default", "lib", Name, "ebin",
  228. io_lib:format("~ts_extra.beam", [Name])]),
  229. %% check the extra src_dir was copied/linked into the _build dir
  230. ExtraDir = filename:join([AppDir, "_build", "default", "lib", Name, "extra"]),
  231. rebar_test_utils:run_and_check(
  232. Config, RebarConfig, ["compile"],
  233. {ok, [{app, Name}, {file, ExtraBeam}, {dir, ExtraDir}]}
  234. ).
  235. build_release_srcdirs(Config) ->
  236. AppDir = ?config(apps, Config),
  237. [Name1, Name2] = ?config(app_names, Config),
  238. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  239. %% check a beam corresponding to the src in the extra src_dir exists
  240. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  241. io_lib:format("~ts_extra.beam", [Name1])]),
  242. Extra2Beam = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin",
  243. io_lib:format("~ts_extra.beam", [Name2])]),
  244. %% check the extra src_dir was copied/linked into the _build dir
  245. Extra1Dir = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  246. Extra2Dir = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  247. rebar_test_utils:run_and_check(
  248. Config, RebarConfig, ["compile"],
  249. {ok, [{app, Name1}, {app, Name2},
  250. {file, Extra1Beam}, {file, Extra2Beam},
  251. {dir, Extra1Dir}, {dir, Extra2Dir}]}
  252. ).
  253. build_unbalanced_srcdirs(Config) ->
  254. AppDir = ?config(apps, Config),
  255. [Name1, Name2] = ?config(app_names, Config),
  256. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  257. %% check a beam corresponding to the src in the extra src_dir exists
  258. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  259. io_lib:format("~ts_extra.beam", [Name1])]),
  260. %% check the extra src_dir was copied/linked into the _build dir
  261. Extra1Dir = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  262. rebar_test_utils:run_and_check(
  263. Config, RebarConfig, ["compile"],
  264. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}, {dir, Extra1Dir}]}
  265. ),
  266. %% check no extra src_dir were copied/linked into the _build dir
  267. Extra2Dir = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  268. false = filelib:is_dir(Extra2Dir),
  269. %% check only expected beams are in the ebin dir
  270. {ok, Files} = rebar_utils:list_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"])),
  271. lists:all(fun(Beam) -> lists:member(Beam, [Name2 ++ ".app", "not_a_real_src_" ++ Name2 ++ ".beam"]) end,
  272. Files).
  273. build_basic_extra_dirs(Config) ->
  274. AppDir = ?config(apps, Config),
  275. [Name] = ?config(app_names, Config),
  276. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  277. %% check a beam corresponding to the src in the extra src_dir exists
  278. ExtraBeam = filename:join([AppDir, "_build", "default", "lib", Name, "extra",
  279. io_lib:format("~ts_extra.beam", [Name])]),
  280. rebar_test_utils:run_and_check(
  281. Config, RebarConfig, ["compile"],
  282. {ok, [{app, Name}, {file, ExtraBeam}]}
  283. ).
  284. build_release_extra_dirs(Config) ->
  285. AppDir = ?config(apps, Config),
  286. [Name1, Name2] = ?config(app_names, Config),
  287. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  288. %% check a beam corresponding to the src in the extra src_dir exists
  289. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  290. io_lib:format("~ts_extra.beam", [Name1])]),
  291. Extra2Beam = filename:join([AppDir, "_build", "default", "lib", Name2, "extra",
  292. io_lib:format("~ts_extra.beam", [Name2])]),
  293. rebar_test_utils:run_and_check(
  294. Config, RebarConfig, ["compile"],
  295. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}, {file, Extra2Beam}]}
  296. ).
  297. build_unbalanced_extra_dirs(Config) ->
  298. AppDir = ?config(apps, Config),
  299. [Name1, Name2] = ?config(app_names, Config),
  300. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  301. %% check a beam corresponding to the src in the extra src_dir exists
  302. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  303. io_lib:format("~ts_extra.beam", [Name1])]),
  304. rebar_test_utils:run_and_check(
  305. Config, RebarConfig, ["compile"],
  306. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}]}
  307. ),
  308. %% check no extra src_dir were copied/linked into the _build dir
  309. false = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "extra"])),
  310. %% check only expected beams are in the ebin dir
  311. {ok, Files} = rebar_utils:list_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"])),
  312. lists:all(fun(Beam) -> lists:member(Beam, [Name2 ++ ".app", "not_a_real_src_" ++ Name2 ++ ".beam"]) end,
  313. Files).
  314. build_extra_dirs_in_project_root(Config) ->
  315. AppDir = ?config(apps, Config),
  316. [Name1, Name2] = ?config(app_names, Config),
  317. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  318. %% check a beam corresponding to the src in the extra src_dir exists
  319. ExtraBeam = filename:join([AppDir, "_build", "default", "extras", "extra", "extra.beam"]),
  320. rebar_test_utils:run_and_check(
  321. Config, RebarConfig, ["compile"],
  322. {ok, [{app, Name1}, {app, Name2}, {file, ExtraBeam}]}
  323. ).
  324. paths_basic_app(Config) ->
  325. [Name] = ?config(app_names, Config),
  326. [Vsn] = ?config(vsns, Config),
  327. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  328. code:add_paths(rebar_state:code_paths(State, all_deps)),
  329. ok = application:load(list_to_atom(Name)),
  330. Loaded = application:loaded_applications(),
  331. {_, _, Vsn} = lists:keyfind(list_to_atom(Name), 1, Loaded).
  332. paths_release_apps(Config) ->
  333. [Name1, Name2] = ?config(app_names, Config),
  334. [Vsn1, Vsn2] = ?config(vsns, Config),
  335. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  336. code:add_paths(rebar_state:code_paths(State, all_deps)),
  337. ok = application:load(list_to_atom(Name1)),
  338. ok = application:load(list_to_atom(Name2)),
  339. Loaded = application:loaded_applications(),
  340. {_, _, Vsn1} = lists:keyfind(list_to_atom(Name1), 1, Loaded),
  341. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  342. paths_checkout_apps(Config) ->
  343. [Name1, _Name2] = ?config(app_names, Config),
  344. [Vsn1, _Vsn2] = ?config(vsns, Config),
  345. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  346. code:add_paths(rebar_state:code_paths(State, all_deps)),
  347. ok = application:load(list_to_atom(Name1)),
  348. Loaded = application:loaded_applications(),
  349. {_, _, Vsn1} = lists:keyfind(list_to_atom(Name1), 1, Loaded).
  350. paths_checkout_deps(Config) ->
  351. AppDir = ?config(apps, Config),
  352. [_Name1, Name2] = ?config(app_names, Config),
  353. [_Vsn1, Vsn2] = ?config(vsns, Config),
  354. %% rebar_test_utils:init_rebar_state/1,2 uses rebar_state:new/3 which
  355. %% maybe incorrectly sets deps to [] (based on `rebar.lock`) instead of
  356. %% to the checkapps
  357. %% until that is sorted out the lock file has to be removed before
  358. %% this test will pass
  359. file:delete(filename:join([AppDir, "rebar.lock"])),
  360. {ok, RebarConfig} = file:consult(filename:join([AppDir, "rebar.config"])),
  361. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  362. code:add_paths(rebar_state:code_paths(State, all_deps)),
  363. ok = application:load(list_to_atom(Name2)),
  364. Loaded = application:loaded_applications(),
  365. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  366. paths_basic_srcdirs(Config) ->
  367. AppDir = ?config(apps, Config),
  368. [Name] = ?config(app_names, Config),
  369. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  370. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  371. code:add_paths(rebar_state:code_paths(State, all_deps)),
  372. Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  373. {module, Mod} = code:ensure_loaded(Mod),
  374. Expect = filename:join([AppDir, "_build", "default", "lib", Name, "ebin",
  375. io_lib:format("~ts_extra.beam", [Name])]),
  376. Expect = code:which(Mod).
  377. paths_release_srcdirs(Config) ->
  378. AppDir = ?config(apps, Config),
  379. [Name1, Name2] = ?config(app_names, Config),
  380. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  381. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  382. code:add_paths(rebar_state:code_paths(State, all_deps)),
  383. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  384. {module, Mod1} = code:ensure_loaded(Mod1),
  385. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  386. {module, Mod2} = code:ensure_loaded(Mod2),
  387. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  388. io_lib:format("~ts_extra.beam", [Name1])]),
  389. ExpectOne = code:which(Mod1),
  390. ExpectTwo = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin",
  391. io_lib:format("~ts_extra.beam", [Name2])]),
  392. ExpectTwo = code:which(Mod2).
  393. paths_unbalanced_srcdirs(Config) ->
  394. AppDir = ?config(apps, Config),
  395. [Name1, Name2] = ?config(app_names, Config),
  396. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  397. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  398. code:add_paths(rebar_state:code_paths(State, all_deps)),
  399. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  400. {module, Mod1} = code:ensure_loaded(Mod1),
  401. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  402. {error, nofile} = code:ensure_loaded(Mod2),
  403. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  404. io_lib:format("~ts_extra.beam", [Name1])]),
  405. ExpectOne = code:which(Mod1).
  406. paths_basic_extra_dirs(Config) ->
  407. AppDir = ?config(apps, Config),
  408. [Name] = ?config(app_names, Config),
  409. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  410. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  411. code:add_paths(rebar_state:code_paths(State, all_deps)),
  412. Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  413. {module, Mod} = code:ensure_loaded(Mod),
  414. Expect = filename:join([AppDir, "_build", "default", "lib", Name, "extra",
  415. io_lib:format("~ts_extra.beam", [Name])]),
  416. Expect = code:which(Mod).
  417. paths_release_extra_dirs(Config) ->
  418. AppDir = ?config(apps, Config),
  419. [Name1, Name2] = ?config(app_names, Config),
  420. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  421. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  422. code:add_paths(rebar_state:code_paths(State, all_deps)),
  423. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  424. {module, Mod1} = code:ensure_loaded(Mod1),
  425. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  426. {module, Mod2} = code:ensure_loaded(Mod2),
  427. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  428. io_lib:format("~ts_extra.beam", [Name1])]),
  429. ExpectOne = code:which(Mod1),
  430. ExpectTwo = filename:join([AppDir, "_build", "default", "lib", Name2, "extra",
  431. io_lib:format("~ts_extra.beam", [Name2])]),
  432. ExpectTwo = code:which(Mod2).
  433. paths_unbalanced_extra_dirs(Config) ->
  434. AppDir = ?config(apps, Config),
  435. [Name1, Name2] = ?config(app_names, Config),
  436. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  437. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  438. code:add_paths(rebar_state:code_paths(State, all_deps)),
  439. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  440. {module, Mod1} = code:ensure_loaded(Mod1),
  441. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  442. {error, nofile} = code:ensure_loaded(Mod2),
  443. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  444. io_lib:format("~ts_extra.beam", [Name1])]),
  445. ExpectOne = code:which(Mod1).
  446. paths_extra_dirs_in_project_root(Config) ->
  447. AppDir = ?config(apps, Config),
  448. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  449. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  450. code:add_paths(rebar_state:code_paths(State, all_deps)),
  451. {module, extra} = code:ensure_loaded(extra),
  452. Expect = filename:join([AppDir, "_build", "default", "extras", "extra", "extra.beam"]),
  453. Expect = code:which(extra).
  454. clean_basic_app(Config) ->
  455. [Name] = ?config(app_names, Config),
  456. rebar_test_utils:run_and_check(Config, [], ["clean"], {ok, [{app, Name, invalid}]}).
  457. clean_release_apps(Config) ->
  458. [Name1, Name2] = ?config(app_names, Config),
  459. rebar_test_utils:run_and_check(Config, [], ["clean"],
  460. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}).
  461. clean_basic_extra_dirs(Config) ->
  462. AppDir = ?config(apps, Config),
  463. [Name] = ?config(app_names, Config),
  464. rebar_test_utils:run_and_check(Config, [], ["clean"], {ok, [{app, Name, invalid}]}),
  465. Beam = lists:flatten(io_lib:format("~ts_extra", [Name])),
  466. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name, "extras", Beam])).
  467. clean_release_extra_dirs(Config) ->
  468. AppDir = ?config(apps, Config),
  469. [Name1, Name2] = ?config(app_names, Config),
  470. rebar_test_utils:run_and_check(Config, [], ["clean"],
  471. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}),
  472. Beam1 = lists:flatten(io_lib:format("~ts_extra", [Name1])),
  473. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name1, "extras", Beam1])),
  474. Beam2 = lists:flatten(io_lib:format("~ts_extra", [Name2])),
  475. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name2, "extras", Beam2])).
  476. clean_extra_dirs_in_project_root(Config) ->
  477. AppDir = ?config(apps, Config),
  478. [Name1, Name2] = ?config(app_names, Config),
  479. rebar_test_utils:run_and_check(Config, [], ["clean"],
  480. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}),
  481. false = ec_file:exists(filename:join([AppDir, "_build", "default", "extras"])).
  482. recompile_when_hrl_changes(Config) ->
  483. AppDir = ?config(apps, Config),
  484. Name = rebar_test_utils:create_random_name("app1_"),
  485. Vsn = rebar_test_utils:create_random_vsn(),
  486. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  487. ExtraSrc = <<"-module(test_header_include).\n"
  488. "-export([main/0]).\n"
  489. "-include(\"test_header_include.hrl\").\n"
  490. "main() -> ?SOME_DEFINE.\n">>,
  491. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  492. HeaderFile = filename:join([AppDir, "src", "test_header_include.hrl"]),
  493. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  494. ok = file:write_file(HeaderFile, ExtraHeader),
  495. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  496. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  497. {ok, Files} = rebar_utils:list_dir(EbinDir),
  498. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  499. || F <- Files, filename:extension(F) == ".beam"],
  500. timer:sleep(1000),
  501. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  502. ok = file:write_file(HeaderFile, NewExtraHeader),
  503. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  504. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  505. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  506. || F <- NewFiles, filename:extension(F) == ".beam"],
  507. ?assert(ModTime =/= NewModTime).
  508. recompile_when_included_hrl_changes(Config) ->
  509. AppDir = ?config(apps, Config),
  510. Name = rebar_test_utils:create_random_name("app1_"),
  511. Vsn = rebar_test_utils:create_random_vsn(),
  512. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  513. ExtraSrc = <<"-module(test_header_include).\n"
  514. "-export([main/0]).\n"
  515. "-include(\"test_header_include.hrl\").\n"
  516. "main() -> ?SOME_DEFINE.\n">>,
  517. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  518. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  519. HeaderFile = filename:join([AppDir, "include", "test_header_include.hrl"]),
  520. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  521. ok = file:write_file(HeaderFile, ExtraHeader),
  522. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  523. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  524. {ok, Files} = rebar_utils:list_dir(EbinDir),
  525. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  526. || F <- Files, filename:extension(F) == ".beam"],
  527. timer:sleep(1000),
  528. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  529. ok = file:write_file(HeaderFile, NewExtraHeader),
  530. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  531. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  532. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  533. || F <- NewFiles, filename:extension(F) == ".beam"],
  534. ?assert(ModTime =/= NewModTime).
  535. recompile_when_opts_included_hrl_changes(Config) ->
  536. AppsDir = ?config(apps, Config),
  537. Name = rebar_test_utils:create_random_name("app1_"),
  538. Vsn = rebar_test_utils:create_random_vsn(),
  539. AppDir = filename:join([AppsDir, "apps", Name]),
  540. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  541. ExtraSrc = <<"-module(test_header_include).\n"
  542. "-export([main/0]).\n"
  543. "-include(\"test_header_include.hrl\").\n"
  544. "main() -> ?SOME_DEFINE.\n">>,
  545. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  546. ok = filelib:ensure_dir(filename:join([AppsDir, "include", "dummy"])),
  547. HeaderFile = filename:join([AppsDir, "include", "test_header_include.hrl"]),
  548. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  549. ok = file:write_file(HeaderFile, ExtraHeader),
  550. %% Using relative path from the project root
  551. RebarConfig = [{erl_opts, [{i, "include/"}]}],
  552. {ok,Cwd} = file:get_cwd(),
  553. ok = file:set_cwd(AppsDir),
  554. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  555. EbinDir = filename:join([AppsDir, "_build", "default", "lib", Name, "ebin"]),
  556. {ok, Files} = rebar_utils:list_dir(EbinDir),
  557. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  558. || F <- Files, filename:extension(F) == ".beam"],
  559. timer:sleep(1000),
  560. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  561. ok = file:write_file(HeaderFile, NewExtraHeader),
  562. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  563. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  564. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  565. || F <- NewFiles, filename:extension(F) == ".beam"],
  566. ok = file:set_cwd(Cwd),
  567. ?assert(ModTime =/= NewModTime).
  568. recompile_when_opts_change(Config) ->
  569. AppDir = ?config(apps, Config),
  570. Name = rebar_test_utils:create_random_name("app1_"),
  571. Vsn = rebar_test_utils:create_random_vsn(),
  572. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  573. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  574. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  575. {ok, Files} = rebar_utils:list_dir(EbinDir),
  576. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  577. || F <- Files, filename:extension(F) == ".beam"],
  578. timer:sleep(1000),
  579. rebar_test_utils:create_config(AppDir, [{erl_opts, [{d, some_define}]}]),
  580. rebar_test_utils:run_and_check(Config, [{erl_opts, [{d, some_define}]}], ["compile"], {ok, [{app, Name}]}),
  581. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  582. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  583. || F <- NewFiles, filename:extension(F) == ".beam"],
  584. ?assert(ModTime =/= NewModTime).
  585. dont_recompile_when_opts_dont_change(Config) ->
  586. AppDir = ?config(apps, Config),
  587. Name = rebar_test_utils:create_random_name("app1_"),
  588. Vsn = rebar_test_utils:create_random_vsn(),
  589. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  590. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  591. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  592. {ok, Files} = rebar_utils:list_dir(EbinDir),
  593. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  594. || F <- Files, filename:extension(F) == ".beam"],
  595. timer:sleep(1000),
  596. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  597. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  598. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  599. || F <- NewFiles, filename:extension(F) == ".beam"],
  600. ?assertEqual(ModTime, NewModTime).
  601. dont_recompile_yrl_or_xrl(Config) ->
  602. AppDir = ?config(apps, Config),
  603. Name = rebar_test_utils:create_random_name("app1_"),
  604. Vsn = rebar_test_utils:create_random_vsn(),
  605. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  606. Xrl = filename:join([AppDir, "src", "not_a_real_xrl_" ++ Name ++ ".xrl"]),
  607. ok = filelib:ensure_dir(Xrl),
  608. XrlBody =
  609. "Definitions."
  610. "\n\n"
  611. "D = [0-9]"
  612. "\n\n"
  613. "Rules."
  614. "\n\n"
  615. "{D}+ :"
  616. " {token,{integer,TokenLine,list_to_integer(TokenChars)}}."
  617. "\n\n"
  618. "{D}+\\.{D}+((E|e)(\\+|\\-)?{D}+)? :"
  619. " {token,{float,TokenLine,list_to_float(TokenChars)}}."
  620. "\n\n"
  621. "Erlang code.",
  622. ok = ec_file:write(Xrl, XrlBody),
  623. Yrl = filename:join([AppDir, "src", "not_a_real_yrl_" ++ Name ++ ".yrl"]),
  624. ok = filelib:ensure_dir(Yrl),
  625. YrlBody = ["Nonterminals E T F.\n"
  626. "Terminals '+' '*' '(' ')' number.\n"
  627. "Rootsymbol E.\n"
  628. "E -> E '+' T: {'$2', '$1', '$3'}.\n"
  629. "E -> T : '$1'.\n"
  630. "T -> T '*' F: {'$2', '$1', '$3'}.\n"
  631. "T -> F : '$1'.\n"
  632. "F -> '(' E ')' : '$2'.\n"
  633. "F -> number : '$1'.\n"],
  634. ok = ec_file:write(Yrl, YrlBody),
  635. XrlErl = filename:join([AppDir, "src", filename:basename(Xrl, ".xrl") ++ ".erl"]),
  636. YrlErl = filename:join([AppDir, "src", filename:basename(Yrl, ".yrl") ++ ".erl"]),
  637. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  638. XrlBeam = filename:join([EbinDir, filename:basename(Xrl, ".xrl") ++ ".beam"]),
  639. YrlBeam = filename:join([EbinDir, filename:basename(Yrl, ".yrl") ++ ".beam"]),
  640. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  641. XrlModTime = filelib:last_modified(XrlErl),
  642. YrlModTime = filelib:last_modified(YrlErl),
  643. XrlBeamModTime = filelib:last_modified(XrlBeam),
  644. YrlBeamModTime = filelib:last_modified(YrlBeam),
  645. timer:sleep(1000),
  646. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  647. NewXrlModTime = filelib:last_modified(XrlErl),
  648. NewYrlModTime = filelib:last_modified(YrlErl),
  649. NewXrlBeamModTime = filelib:last_modified(XrlBeam),
  650. NewYrlBeamModTime = filelib:last_modified(YrlBeam),
  651. ?assert(XrlBeamModTime == NewXrlBeamModTime),
  652. ?assert(YrlBeamModTime == NewYrlBeamModTime),
  653. ?assert(XrlModTime == NewXrlModTime),
  654. ?assert(YrlModTime == NewYrlModTime).
  655. delete_beam_if_source_deleted(Config) ->
  656. AppDir = ?config(apps, Config),
  657. Name = rebar_test_utils:create_random_name("app1_"),
  658. Vsn = rebar_test_utils:create_random_vsn(),
  659. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  660. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  661. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  662. _SrcDir = filename:join([AppDir, "_build", "default", "lib", Name, "src"]),
  663. ?assert(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))),
  664. file:delete(filename:join([AppDir, "src", "not_a_real_src_" ++ Name ++ ".erl"])),
  665. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  666. ?assertNot(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))).
  667. deps_in_path(Config) ->
  668. AppDir = ?config(apps, Config),
  669. StartPaths = code:get_path(),
  670. Name = rebar_test_utils:create_random_name("app1_"),
  671. Vsn = rebar_test_utils:create_random_vsn(),
  672. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  673. DepName = rebar_test_utils:create_random_name("dep1_"),
  674. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  675. mock_git_resource:mock([]),
  676. mock_pkg_resource:mock([
  677. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  678. ]),
  679. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  680. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  681. {list_to_atom(PkgName), Vsn}
  682. ]}]),
  683. {ok, RConf} = file:consult(RConfFile),
  684. %% Make sure apps we look for are not visible
  685. %% Hope not to find src name
  686. ?assertEqual([], [Path || Path <- code:get_path(),
  687. {match, _} <- [re:run(Path, DepName)]]),
  688. %% Hope not to find pkg name in there
  689. ?assertEqual([], [Path || Path <- code:get_path(),
  690. {match, _} <- [re:run(Path, PkgName)]]),
  691. %% Build things
  692. {ok, State} = rebar_test_utils:run_and_check(
  693. Config, RConf, ["compile"],
  694. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  695. ),
  696. code:add_paths(rebar_state:code_paths(State, all_deps)),
  697. %% Find src name in there
  698. ?assertNotEqual([], [Path || Path <- code:get_path(),
  699. {match, _} <- [re:run(Path, DepName)]]),
  700. %% find pkg name in there
  701. ?assertNotEqual([], [Path || Path <- code:get_path(),
  702. {match, _} <- [re:run(Path, PkgName)]]),
  703. true = code:set_path(lists:filter(fun(P) -> ec_file:exists(P) end, StartPaths)),
  704. %% Make sure apps we look for are not visible again
  705. %% Hope not to find src name
  706. ?assertEqual([], [Path || Path <- code:get_path(),
  707. {match, _} <- [re:run(Path, DepName)]]),
  708. %% Hope not to find pkg name in there
  709. ?assertEqual([], [Path || Path <- code:get_path(),
  710. {match, _} <- [re:run(Path, PkgName)]]),
  711. %% Rebuild
  712. {ok, State1} = rebar_test_utils:run_and_check(
  713. Config, RConf, ["compile"],
  714. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  715. ),
  716. %% Find src name in there
  717. code:add_paths(rebar_state:code_paths(State1, all_deps)),
  718. ?assertNotEqual([], [Path || Path <- code:get_path(),
  719. {match, _} <- [re:run(Path, DepName)]]),
  720. %% find pkg name in there
  721. ?assertNotEqual([], [Path || Path <- code:get_path(),
  722. {match, _} <- [re:run(Path, PkgName)]]).
  723. checkout_priority(Config) ->
  724. AppDir = ?config(apps, Config),
  725. CheckoutsDir = ?config(checkouts, Config),
  726. StartPaths = code:get_path(),
  727. Name = rebar_test_utils:create_random_name("app1_"),
  728. Vsn = rebar_test_utils:create_random_vsn(),
  729. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  730. DepName = rebar_test_utils:create_random_name("dep1_"),
  731. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  732. mock_git_resource:mock([]),
  733. mock_pkg_resource:mock([
  734. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  735. ]),
  736. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  737. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  738. {list_to_atom(PkgName), Vsn}
  739. ]}]),
  740. {ok, RConf} = file:consult(RConfFile),
  741. %% Build with deps.
  742. rebar_test_utils:run_and_check(
  743. Config, RConf, ["compile"],
  744. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  745. ),
  746. %% Build two checkout apps similar to dependencies to be fetched,
  747. %% but on a different version
  748. Vsn2 = rebar_test_utils:create_random_vsn(),
  749. rebar_test_utils:create_app(filename:join([CheckoutsDir,DepName]), DepName, Vsn2, [kernel, stdlib]),
  750. rebar_test_utils:create_app(filename:join([CheckoutsDir,PkgName]), PkgName, Vsn2, [kernel, stdlib]),
  751. %% Rebuild and make sure the checkout apps are in path
  752. code:set_path(StartPaths),
  753. {ok, State} = rebar_test_utils:run_and_check(
  754. Config, RConf, ["compile"],
  755. {ok, [{app, Name}, {checkout, DepName}, {checkout, PkgName}]}
  756. ),
  757. code:add_paths(rebar_state:code_paths(State, all_deps)),
  758. [DepPath] = [Path || Path <- code:get_path(),
  759. {match, _} <- [re:run(Path, DepName)]],
  760. [PkgPath] = [Path || Path <- code:get_path(),
  761. {match, _} <- [re:run(Path, PkgName)]],
  762. {ok, [DepApp]} = file:consult(filename:join([DepPath, DepName ++ ".app"])),
  763. {ok, [PkgApp]} = file:consult(filename:join([PkgPath, PkgName ++ ".app"])),
  764. {application, _, DepProps} = DepApp,
  765. {application, _, PkgProps} = PkgApp,
  766. ?assertEqual(Vsn2, proplists:get_value(vsn, DepProps)),
  767. ?assertEqual(Vsn2, proplists:get_value(vsn, PkgProps)).
  768. highest_version_of_pkg_dep(Config) ->
  769. AppDir = ?config(apps, Config),
  770. Name = rebar_test_utils:create_random_name("app1_"),
  771. Vsn = rebar_test_utils:create_random_vsn(),
  772. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  773. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  774. mock_git_resource:mock([]),
  775. mock_pkg_resource:mock([
  776. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  777. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  778. {{iolist_to_binary(PkgName), <<"0.1.3">>}, []},
  779. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}
  780. ]),
  781. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [list_to_atom(PkgName)]}]),
  782. {ok, RConf} = file:consult(RConfFile),
  783. %% Build with deps.
  784. rebar_test_utils:run_and_check(
  785. Config, RConf, ["compile"],
  786. {ok, [{app, Name}, {dep, PkgName, <<"0.1.3">>}]}
  787. ).
  788. parse_transform_test(Config) ->
  789. AppDir = ?config(apps, Config),
  790. RebarConfig = [{erl_opts, [{parse_transform, pascal}]}],
  791. Name = rebar_test_utils:create_random_name("app1_"),
  792. Vsn = rebar_test_utils:create_random_vsn(),
  793. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  794. ExtraSrc = <<"-module(pascal). "
  795. "-export([parse_transform/2]). "
  796. "parse_transform(Forms, _Options) -> "
  797. "Forms.">>,
  798. ok = file:write_file(filename:join([AppDir, "src", "pascal.erl"]), ExtraSrc),
  799. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  800. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  801. true = filelib:is_file(filename:join([EbinDir, "pascal.beam"])).
  802. erl_first_files_test(Config) ->
  803. AppDir = ?config(apps, Config),
  804. RebarConfig = [{erl_opts, [{parse_transform, mark_time}]},
  805. {erl_first_files, ["src/mark_time.erl",
  806. "src/b.erl",
  807. "src/d.erl",
  808. "src/a.erl"]}],
  809. Name = rebar_test_utils:create_random_name("app1_"),
  810. Vsn = rebar_test_utils:create_random_vsn(),
  811. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  812. rebar_test_utils:write_src_file(AppDir, "a.erl"),
  813. rebar_test_utils:write_src_file(AppDir, "b.erl"),
  814. rebar_test_utils:write_src_file(AppDir, "d.erl"),
  815. rebar_test_utils:write_src_file(AppDir, "e.erl"),
  816. ExtraSrc = <<"-module(mark_time). "
  817. "-export([parse_transform/2]). "
  818. "parse_transform([Form={attribute,_,module,Mod}|Forms], Options) -> "
  819. " [Form, {attribute,1,number, os:timestamp()} | Forms];"
  820. "parse_transform([Form|Forms], Options) -> "
  821. " [Form | parse_transform(Forms, Options)].">>,
  822. ok = file:write_file(filename:join([AppDir, "src", "mark_time.erl"]), ExtraSrc),
  823. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  824. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  825. true = filelib:is_file(filename:join([EbinDir, "mark_time.beam"])),
  826. code:load_abs(filename:join([EbinDir, "a"])),
  827. code:load_abs(filename:join([EbinDir, "b"])),
  828. code:load_abs(filename:join([EbinDir, "d"])),
  829. code:load_abs(filename:join([EbinDir, "e"])),
  830. A = proplists:get_value(number, a:module_info(attributes)),
  831. B = proplists:get_value(number, b:module_info(attributes)),
  832. D = proplists:get_value(number, d:module_info(attributes)),
  833. E = proplists:get_value(number, e:module_info(attributes)),
  834. ?assertEqual([B,D,A,E], lists:sort([A,B,D,E])).
  835. mib_test(Config) ->
  836. AppDir = ?config(apps, Config),
  837. RebarConfig = [{mib_first_files, ["mibs/SIMPLE-MIB.mib"]}],
  838. Name = rebar_test_utils:create_random_name("app1_"),
  839. Vsn = rebar_test_utils:create_random_vsn(),
  840. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  841. MibsSrc = <<"-- SIMPLE-MIB.\n"
  842. "-- This is just a simple MIB used for testing!\n"
  843. "--\n"
  844. "SIMPLE-MIB DEFINITIONS ::= BEGIN\n"
  845. "IMPORTS\n"
  846. " MODULE-IDENTITY, enterprises\n"
  847. " FROM SNMPv2-SMI;\n"
  848. "\n"
  849. "ericsson MODULE-IDENTITY\n"
  850. " LAST-UPDATED\n"
  851. " \"201403060000Z\"\n"
  852. " ORGANIZATION\n"
  853. " \"rebar\"\n"
  854. " CONTACT-INFO\n"
  855. " \"rebar <rebar@example.com>\n"
  856. " or\n"
  857. " whoever is currently responsible for the SIMPLE\n"
  858. " enterprise MIB tree branch (enterprises.999).\"\n"
  859. " DESCRIPTION\n"
  860. " \"This very small module is made available\n"
  861. " for mib-compilation testing.\"\n"
  862. " ::= { enterprises 999 }\n"
  863. "END\n">>,
  864. ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])),
  865. ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc),
  866. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  867. %% check a bin corresponding to the mib in the mibs dir exists in priv/mibs
  868. PrivMibsDir = filename:join([AppDir, "_build", "default", "lib", Name, "priv", "mibs"]),
  869. true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
  870. %% check a hrl corresponding to the mib in the mibs dir exists in include
  871. true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
  872. %% check the mibs dir was linked into the _build dir
  873. true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "mibs"])).
  874. umbrella_mib_first_test(Config) ->
  875. AppsDir = ?config(apps, Config),
  876. Name = rebar_test_utils:create_random_name("app1_"),
  877. Vsn = rebar_test_utils:create_random_vsn(),
  878. AppDir = filename:join([AppsDir, "apps", Name]),
  879. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  880. MibsSrc = <<"-- SIMPLE-MIB.\n"
  881. "-- This is just a simple MIB used for testing!\n"
  882. "--\n"
  883. "SIMPLE-MIB DEFINITIONS ::= BEGIN\n"
  884. "IMPORTS\n"
  885. " MODULE-IDENTITY, enterprises\n"
  886. " FROM SNMPv2-SMI;\n"
  887. "\n"
  888. "ericsson MODULE-IDENTITY\n"
  889. " LAST-UPDATED\n"
  890. " \"201403060000Z\"\n"
  891. " ORGANIZATION\n"
  892. " \"rebar\"\n"
  893. " CONTACT-INFO\n"
  894. " \"rebar <rebar@example.com>\n"
  895. " or\n"
  896. " whoever is currently responsible for the SIMPLE\n"
  897. " enterprise MIB tree branch (enterprises.999).\"\n"
  898. " DESCRIPTION\n"
  899. " \"This very small module is made available\n"
  900. " for mib-compilation testing.\"\n"
  901. " ::= { enterprises 999 }\n"
  902. "END\n">>,
  903. ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])),
  904. ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc),
  905. RebarConfig = [{mib_first_files, ["mibs/SIMPLE-MIB.mib"]}],
  906. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  907. %% check a bin corresponding to the mib in the mibs dir exists in priv/mibs
  908. PrivMibsDir = filename:join([AppsDir, "_build", "default", "lib", Name, "priv", "mibs"]),
  909. true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
  910. %% check a hrl corresponding to the mib in the mibs dir exists in include
  911. true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
  912. %% check the mibs dir was linked into the _build dir
  913. true = filelib:is_dir(filename:join([AppsDir, "_build", "default", "lib", Name, "mibs"])).
  914. only_default_transitive_deps(Config) ->
  915. AppDir = ?config(apps, Config),
  916. Name = rebar_test_utils:create_random_name("app1_"),
  917. Vsn = rebar_test_utils:create_random_vsn(),
  918. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  919. GitDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}]),
  920. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  921. {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
  922. mock_git_resource:mock([{deps, SrcDeps},
  923. {config, [{profiles, [{test, [{deps, [list_to_atom(PkgName)]}]}]}]}]),
  924. mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
  925. Deps = rebar_test_utils:top_level_deps(GitDeps),
  926. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
  927. {ok, RConf} = file:consult(RConfFile),
  928. %% Build with deps.
  929. rebar_test_utils:run_and_check(
  930. Config, RConf, ["as", "test", "compile"],
  931. {ok, [{app, Name}, {dep, "a", <<"1.0.0">>}, {dep_not_exist, PkgName}]}
  932. ).
  933. clean_all(Config) ->
  934. AppDir = ?config(apps, Config),
  935. Name = rebar_test_utils:create_random_name("app1_"),
  936. Vsn = rebar_test_utils:create_random_vsn(),
  937. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  938. DepName = rebar_test_utils:create_random_name("dep1_"),
  939. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  940. mock_git_resource:mock([]),
  941. mock_pkg_resource:mock([
  942. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  943. ]),
  944. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  945. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  946. {list_to_atom(PkgName), Vsn}
  947. ]}]),
  948. {ok, RConf} = file:consult(RConfFile),
  949. %% Build things
  950. rebar_test_utils:run_and_check(
  951. Config, RConf, ["compile"],
  952. {ok, [{app, Name}, {app, DepName}, {app, PkgName}]}
  953. ),
  954. %% Clean all
  955. rebar_test_utils:run_and_check(Config, [], ["clean", "--all"],
  956. {ok, [{app, Name, invalid},
  957. {app, DepName, invalid},
  958. {app, PkgName, invalid}]}).
  959. override_deps(Config) ->
  960. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  961. TopDeps = rebar_test_utils:top_level_deps(Deps),
  962. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  963. mock_git_resource:mock([{deps, SrcDeps}]),
  964. RebarConfig = [
  965. {deps, TopDeps},
  966. {overrides, [
  967. {override, some_dep, [
  968. {deps, []}
  969. ]}
  970. ]}
  971. ],
  972. rebar_test_utils:run_and_check(
  973. Config, RebarConfig, ["compile"],
  974. {ok, [{dep, "some_dep"},
  975. {dep_not_exist, "other_dep"}]}
  976. ).
  977. override_add_deps(Config) ->
  978. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  979. TopDeps = rebar_test_utils:top_level_deps(Deps),
  980. DepA = {dep_a, "0.0.1", {git, "http://site.com/dep_a.git", {tag, "0.0.1"}}},
  981. DepB = {dep_b, "0.0.1", {git, "http://site.com/dep_b.git", {tag, "0.0.1"}}},
  982. DepC = {dep_c, "0.0.1", {git, "http://site.com/dep_c.git", {tag, "0.0.1"}}},
  983. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  984. mock_git_resource:mock([{deps, [DepA, DepB, DepC | SrcDeps]}]),
  985. RebarConfig = [
  986. {deps, TopDeps},
  987. {overrides, [
  988. {add, some_dep, [
  989. {deps, [DepA, DepB]}
  990. ]},
  991. {add, [
  992. {deps, [DepC]}
  993. ]}
  994. ]}
  995. ],
  996. rebar_test_utils:run_and_check(
  997. Config, RebarConfig, ["compile"],
  998. {ok, [{dep, "some_dep"},
  999. {dep, "other_dep"},
  1000. {dep, "dep_a"},
  1001. {dep, "dep_b"},
  1002. {dep, "dep_c"}]}
  1003. ).
  1004. override_del_deps(Config) ->
  1005. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"dep_a", "0.0.1", []},
  1006. {"dep_b", "0.0.1", []},
  1007. {"dep_c", "0.0.1", []}]},
  1008. {"other_dep", "0.0.1", [{"dep_c", "0.0.1", []},
  1009. {"dep_d", "0.0.1", []}]}]),
  1010. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1011. DepA = {dep_a, "0.0.1", {git, "https://example.org/user/dep_a.git", {tag, "0.0.1"}}},
  1012. DepB = {dep_b, "0.0.1", {git, "https://example.org/user/dep_b.git", {tag, "0.0.1"}}},
  1013. DepC = {dep_c, "0.0.1", {git, "https://example.org/user/dep_c.git", {tag, "0.0.1"}}},
  1014. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1015. mock_git_resource:mock([{deps, SrcDeps}]),
  1016. RebarConfig = [
  1017. {deps, TopDeps},
  1018. {overrides, [
  1019. {del, some_dep, [
  1020. {deps, [DepA, DepB]}
  1021. ]},
  1022. {del, [
  1023. {deps, [DepC]}
  1024. ]}
  1025. ]}
  1026. ],
  1027. rebar_test_utils:run_and_check(
  1028. Config, RebarConfig, ["compile"],
  1029. {ok, [{dep, "some_dep"},
  1030. {dep, "other_dep"},
  1031. {dep_not_exist, "dep_a"},
  1032. {dep_not_exist, "dep_b"},
  1033. {dep_not_exist, "dep_c"},
  1034. {dep, "dep_d"}]}
  1035. ).
  1036. override_opts(Config) ->
  1037. AppDir = ?config(apps, Config),
  1038. Name = rebar_test_utils:create_random_name("app1_"),
  1039. Vsn = rebar_test_utils:create_random_vsn(),
  1040. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1041. RebarConfig = [
  1042. {erl_opts, [
  1043. compressed,
  1044. warn_missing_spec
  1045. ]},
  1046. {overrides, [
  1047. {override, [
  1048. {erl_opts, [compressed]}
  1049. ]}
  1050. ]}
  1051. ],
  1052. rebar_test_utils:create_config(AppDir, RebarConfig),
  1053. rebar_test_utils:run_and_check(
  1054. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1055. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1056. code:add_patha(Path),
  1057. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1058. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1059. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1060. %% test for fix of https://github.com/erlang/rebar3/issues/1801
  1061. %% only apply overrides once
  1062. %% verify by having an override add the macro TEST to the dep some_dep
  1063. %% building under `ct` will fail if the `add` is applied more than once
  1064. apply_overrides_exactly_once(Config) ->
  1065. AppDir = ?config(apps, Config),
  1066. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1067. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1068. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1069. mock_git_resource:mock([{deps, SrcDeps}]),
  1070. Name = rebar_test_utils:create_random_name("app1_"),
  1071. Vsn = rebar_test_utils:create_random_vsn(),
  1072. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1073. RebarConfig = [{deps, TopDeps},
  1074. {overrides, [
  1075. {add, some_dep, [
  1076. {erl_opts, [{d, 'TEST'}]}
  1077. ]}
  1078. ]}],
  1079. rebar_test_utils:create_config(AppDir, RebarConfig),
  1080. rebar_test_utils:run_and_check(
  1081. Config, RebarConfig, ["ct", "--compile_only"], {ok, [{app, Name}, {dep, "some_dep"}], "test"}).
  1082. override_add_opts(Config) ->
  1083. AppDir = ?config(apps, Config),
  1084. Name = rebar_test_utils:create_random_name("app1_"),
  1085. Vsn = rebar_test_utils:create_random_vsn(),
  1086. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1087. RebarConfig = [
  1088. {erl_opts, [
  1089. warn_missing_spec
  1090. ]},
  1091. {overrides, [
  1092. {add, [
  1093. {erl_opts, [compressed]}
  1094. ]}
  1095. ]}
  1096. ],
  1097. rebar_test_utils:create_config(AppDir, RebarConfig),
  1098. rebar_test_utils:run_and_check(
  1099. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1100. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1101. code:add_patha(Path),
  1102. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1103. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1104. true = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1105. override_del_opts(Config) ->
  1106. AppDir = ?config(apps, Config),
  1107. Name = rebar_test_utils:create_random_name("app1_"),
  1108. Vsn = rebar_test_utils:create_random_vsn(),
  1109. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1110. RebarConfig = [
  1111. {erl_opts, [
  1112. compressed,
  1113. warn_missing_spec
  1114. ]},
  1115. {overrides, [
  1116. {del, [
  1117. {erl_opts, [warn_missing_spec]}
  1118. ]}
  1119. ]}
  1120. ],
  1121. rebar_test_utils:create_config(AppDir, RebarConfig),
  1122. rebar_test_utils:run_and_check(
  1123. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1124. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1125. code:add_patha(Path),
  1126. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1127. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1128. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1129. profile_override_deps(Config) ->
  1130. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1131. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1132. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1133. mock_git_resource:mock([{deps, SrcDeps}]),
  1134. RebarConfig = [
  1135. {deps, TopDeps},
  1136. {profiles, [
  1137. {a, [
  1138. {overrides, [
  1139. {override, some_dep, [
  1140. {deps, []}
  1141. ]}
  1142. ]}
  1143. ]}
  1144. ]}],
  1145. rebar_test_utils:run_and_check(
  1146. Config, RebarConfig, ["as", "a", "compile"],
  1147. {ok, [{dep, "some_dep"},
  1148. {dep_not_exist, "other_dep"}]}
  1149. ).
  1150. profile_override_add_deps(Config) ->
  1151. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1152. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1153. DepA = {dep_a, "0.0.1", {git, "http://site.com/dep_a.git", {tag, "0.0.1"}}},
  1154. DepB = {dep_b, "0.0.1", {git, "http://site.com/dep_b.git", {tag, "0.0.1"}}},
  1155. DepC = {dep_c, "0.0.1", {git, "http://site.com/dep_c.git", {tag, "0.0.1"}}},
  1156. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1157. mock_git_resource:mock([{deps, [DepA, DepB, DepC | SrcDeps]}]),
  1158. RebarConfig = [
  1159. {deps, TopDeps},
  1160. {profiles, [
  1161. {a, [
  1162. {overrides, [
  1163. {add, some_dep, [
  1164. {deps, [DepA, DepB]}
  1165. ]},
  1166. {add, [
  1167. {deps, [DepC]}
  1168. ]}
  1169. ]}
  1170. ]}
  1171. ]}
  1172. ],
  1173. rebar_test_utils:run_and_check(
  1174. Config, RebarConfig, ["as", "a", "compile"],
  1175. {ok, [{dep, "some_dep"},
  1176. {dep, "other_dep"},
  1177. {dep, "dep_a"},
  1178. {dep, "dep_b"},
  1179. {dep, "dep_c"}]}
  1180. ).
  1181. profile_override_del_deps(Config) ->
  1182. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"dep_a", "0.0.1", []},
  1183. {"dep_b", "0.0.1", []},
  1184. {"dep_c", "0.0.1", []}]},
  1185. {"other_dep", "0.0.1", [{"dep_c", "0.0.1", []},
  1186. {"dep_d", "0.0.1", []}]}]),
  1187. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1188. DepA = {dep_a, "0.0.1", {git, "https://example.org/user/dep_a.git", {tag, "0.0.1"}}},
  1189. DepB = {dep_b, "0.0.1", {git, "https://example.org/user/dep_b.git", {tag, "0.0.1"}}},
  1190. DepC = {dep_c, "0.0.1", {git, "https://example.org/user/dep_c.git", {tag, "0.0.1"}}},
  1191. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1192. mock_git_resource:mock([{deps, SrcDeps}]),
  1193. RebarConfig = [
  1194. {deps, TopDeps},
  1195. {profiles, [
  1196. {a, [
  1197. {overrides, [
  1198. {del, some_dep, [
  1199. {deps, [DepA, DepB]}
  1200. ]},
  1201. {del, [
  1202. {deps, [DepC]}
  1203. ]}
  1204. ]}
  1205. ]}
  1206. ]}
  1207. ],
  1208. rebar_test_utils:run_and_check(
  1209. Config, RebarConfig, ["as", "a", "compile"],
  1210. {ok, [{dep, "some_dep"},
  1211. {dep, "other_dep"},
  1212. {dep_not_exist, "dep_a"},
  1213. {dep_not_exist, "dep_b"},
  1214. {dep_not_exist, "dep_c"},
  1215. {dep, "dep_d"}]}
  1216. ).
  1217. profile_override_opts(Config) ->
  1218. AppDir = ?config(apps, Config),
  1219. Name = rebar_test_utils:create_random_name("app1_"),
  1220. Vsn = rebar_test_utils:create_random_vsn(),
  1221. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1222. RebarConfig = [
  1223. {erl_opts, [
  1224. compressed,
  1225. warn_missing_spec
  1226. ]},
  1227. {profiles, [
  1228. {a, [
  1229. {overrides, [
  1230. {override, [
  1231. {erl_opts, [compressed]}
  1232. ]}
  1233. ]}
  1234. ]}
  1235. ]}
  1236. ],
  1237. rebar_test_utils:create_config(AppDir, RebarConfig),
  1238. rebar_test_utils:run_and_check(
  1239. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1240. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1241. code:add_patha(Path),
  1242. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1243. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1244. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1245. profile_override_add_opts(Config) ->
  1246. AppDir = ?config(apps, Config),
  1247. Name = rebar_test_utils:create_random_name("app1_"),
  1248. Vsn = rebar_test_utils:create_random_vsn(),
  1249. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1250. RebarConfig = [
  1251. {erl_opts, [
  1252. warn_missing_spec
  1253. ]},
  1254. {profiles, [
  1255. {a, [
  1256. {overrides, [
  1257. {add, [
  1258. {erl_opts, [compressed]}
  1259. ]}
  1260. ]}
  1261. ]}
  1262. ]}
  1263. ],
  1264. rebar_test_utils:create_config(AppDir, RebarConfig),
  1265. rebar_test_utils:run_and_check(
  1266. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1267. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1268. code:add_patha(Path),
  1269. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1270. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1271. true = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1272. profile_override_del_opts(Config) ->
  1273. AppDir = ?config(apps, Config),
  1274. Name = rebar_test_utils:create_random_name("app1_"),
  1275. Vsn = rebar_test_utils:create_random_vsn(),
  1276. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1277. RebarConfig = [
  1278. {erl_opts, [
  1279. compressed,
  1280. warn_missing_spec
  1281. ]},
  1282. {profiles, [
  1283. {a, [
  1284. {overrides, [
  1285. {del, [
  1286. {erl_opts, [warn_missing_spec]}
  1287. ]}
  1288. ]}
  1289. ]}
  1290. ]}
  1291. ],
  1292. rebar_test_utils:create_config(AppDir, RebarConfig),
  1293. rebar_test_utils:run_and_check(
  1294. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1295. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1296. code:add_patha(Path),
  1297. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1298. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1299. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1300. profile_deps(Config) ->
  1301. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1302. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1303. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1304. mock_git_resource:mock([{deps, SrcDeps}]),
  1305. RebarConfig = [
  1306. {deps, TopDeps},
  1307. {profiles, [{a, []}]}],
  1308. rebar_test_utils:run_and_check(
  1309. Config, RebarConfig, ["as", "a", "compile"],
  1310. {ok, [{dep, "some_dep"},{dep, "other_dep"}]}
  1311. ).
  1312. only_deps(Config) ->
  1313. AppDir = ?config(apps, Config),
  1314. Name = rebar_test_utils:create_random_name("app1_"),
  1315. Vsn = rebar_test_utils:create_random_vsn(),
  1316. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1317. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1318. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1319. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1320. mock_git_resource:mock([{deps, SrcDeps}]),
  1321. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
  1322. {ok, RConf} = file:consult(RConfFile),
  1323. rebar_test_utils:run_and_check(
  1324. Config, RConf, ["compile", "--deps_only"],
  1325. {ok, [{app_not_exist, Name}, {dep, "some_dep"},{dep, "other_dep"}]}
  1326. ).
  1327. %% verify a deps prod profile is used
  1328. %% tested by checking prod hooks run and outputs to default profile dir for dep
  1329. %% and prod deps are installed for dep
  1330. deps_build_in_prod(Config) ->
  1331. AppDir = ?config(apps, Config),
  1332. Name = rebar_test_utils:create_random_name("app1_"),
  1333. Vsn = rebar_test_utils:create_random_vsn(),
  1334. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1335. GitDeps = rebar_test_utils:expand_deps(git, [{"asdf", "1.0.0", []}]),
  1336. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  1337. {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
  1338. mock_git_resource:mock([{deps, SrcDeps},
  1339. {config, [{profiles, [{prod, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]},
  1340. {deps, [list_to_atom(PkgName)]}]}]}]}]),
  1341. mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
  1342. Deps = rebar_test_utils:top_level_deps(GitDeps),
  1343. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
  1344. {ok, RConf} = file:consult(RConfFile),
  1345. %% Build with deps.
  1346. rebar_test_utils:run_and_check(
  1347. Config, RConf, ["compile"],
  1348. {ok, [{app, Name}, {dep, "asdf", <<"1.0.0">>}, {dep, PkgName},
  1349. {file, filename:join([AppDir, "_build", "default", "lib", "asdf", "randomfile"])}]}
  1350. ).
  1351. %% verify that the proper include path is defined
  1352. %% according the erlang doc which states:
  1353. %% If the filename File is absolute (possibly after variable substitution),
  1354. %% the include file with that name is included. Otherwise, the specified file
  1355. %% is searched for in the following directories, and in this order:
  1356. %% * The current working directory
  1357. %% * The directory where the module is being compiled
  1358. %% * The directories given by the include option
  1359. include_file_relative_to_working_directory(Config) ->
  1360. AppDir = ?config(apps, Config),
  1361. Name = rebar_test_utils:create_random_name("app1_"),
  1362. Vsn = rebar_test_utils:create_random_vsn(),
  1363. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1364. Src = <<"-module(test).\n"
  1365. "\n"
  1366. "-include(\"include/test.hrl\").\n"
  1367. "\n"
  1368. "test() -> ?TEST_MACRO.\n"
  1369. "\n">>,
  1370. Include = <<"-define(TEST_MACRO, test).\n">>,
  1371. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1372. ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src),
  1373. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  1374. ok = file:write_file(filename:join([AppDir, "include", "test.hrl"]), Include),
  1375. RebarConfig = [],
  1376. rebar_test_utils:run_and_check(Config, RebarConfig,
  1377. ["compile"],
  1378. {ok, [{app, Name}]}).
  1379. include_file_in_src(Config) ->
  1380. AppDir = ?config(apps, Config),
  1381. Name = rebar_test_utils:create_random_name("app1_"),
  1382. Vsn = rebar_test_utils:create_random_vsn(),
  1383. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1384. Src = <<"-module(test).\n"
  1385. "\n"
  1386. "-include(\"test.hrl\").\n"
  1387. "\n"
  1388. "test() -> ?TEST_MACRO.\n"
  1389. "\n">>,
  1390. Include = <<"-define(TEST_MACRO, test).\n">>,
  1391. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1392. ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src),
  1393. ok = file:write_file(filename:join([AppDir, "src", "test.hrl"]), Include),
  1394. RebarConfig = [],
  1395. rebar_test_utils:run_and_check(Config, RebarConfig,
  1396. ["compile"],
  1397. {ok, [{app, Name}]}).
  1398. %% verify that the proper include path is defined
  1399. %% according the erlang doc which states:
  1400. %% If the filename File is absolute (possibly after variable substitution),
  1401. %% the include file with that name is included. Otherwise, the specified file
  1402. %% is searched for in the following directories, and in this order:
  1403. %% * The current working directory
  1404. %% * The directory where the module is being compiled
  1405. %% * The directories given by the include option
  1406. %%
  1407. %% This test ensures that things keep working when additional directories
  1408. %% are used for apps, such as the test/ directory within the test profile.
  1409. include_file_relative_to_working_directory_test(Config) ->
  1410. AppDir = ?config(apps, Config),
  1411. Name = rebar_test_utils:create_random_name("app1_"),
  1412. Vsn = rebar_test_utils:create_random_vsn(),
  1413. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1414. Src = <<"-module(test).\n"
  1415. "\n"
  1416. "-include(\"include/test.hrl\").\n"
  1417. "\n"
  1418. "test() -> ?TEST_MACRO.\n"
  1419. "\n">>,
  1420. Include = <<"-define(TEST_MACRO, test).\n">>,
  1421. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1422. ok = filelib:ensure_dir(filename:join([AppDir, "test", "dummy"])),
  1423. ok = file:write_file(filename:join([AppDir, "test", "test.erl"]), Src),
  1424. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  1425. ok = file:write_file(filename:join([AppDir, "include", "test.hrl"]), Include),
  1426. RebarConfig = [],
  1427. rebar_test_utils:run_and_check(Config, RebarConfig,
  1428. ["as", "test", "compile"],
  1429. {ok, [{app, Name}]}).
  1430. %% Same as `include_file_in_src/1' but using the `test/' directory
  1431. %% within the test profile.
  1432. include_file_in_src_test(Config) ->
  1433. AppDir = ?config(apps, Config),
  1434. Name = rebar_test_utils:create_random_name("app1_"),
  1435. Vsn = rebar_test_utils:create_random_vsn(),
  1436. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1437. Src = <<"-module(test).\n"
  1438. "\n"
  1439. "-include(\"test.hrl\").\n"
  1440. "\n"
  1441. "test() -> ?TEST_MACRO.\n"
  1442. "\n">>,
  1443. Include = <<"-define(TEST_MACRO, test).\n">>,
  1444. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1445. ok = filelib:ensure_dir(filename:join([AppDir, "test", "dummy"])),
  1446. ok = file:write_file(filename:join([AppDir, "test", "test.erl"]), Src),
  1447. ok = file:write_file(filename:join([AppDir, "src", "test.hrl"]), Include),
  1448. RebarConfig = [],
  1449. rebar_test_utils:run_and_check(Config, RebarConfig,
  1450. ["as", "test", "compile"],
  1451. {ok, [{app, Name}]}).
  1452. %% Same as `include_file_in_src_test/1' but using multiple top-level
  1453. %% apps as dependencies.
  1454. include_file_in_src_test_multiapp(Config) ->
  1455. Name1 = rebar_test_utils:create_random_name("app2_"),
  1456. Name2 = rebar_test_utils:create_random_name("app1_"),
  1457. AppDir1 = filename:join([?config(apps, Config), "lib", Name1]),
  1458. AppDir2 = filename:join([?config(apps, Config), "lib", Name2]),
  1459. Vsn = rebar_test_utils:create_random_vsn(),
  1460. rebar_test_utils:create_app(AppDir1, Name1, Vsn, [kernel, stdlib, list_to_atom(Name2)]),
  1461. rebar_test_utils:create_app(AppDir2, Name2, Vsn, [kernel, stdlib]),
  1462. Src = "-module(test).\n"
  1463. "\n"
  1464. "-include_lib(\"" ++ Name2 ++ "/include/test.hrl\").\n"
  1465. "\n"
  1466. "test() -> ?TEST_MACRO.\n"
  1467. "\n",
  1468. Include = <<"-define(TEST_MACRO, test).\n">>,
  1469. ok = filelib:ensure_dir(filename:join([AppDir1, "src", "dummy"])),
  1470. ok = filelib:ensure_dir(filename:join([AppDir1, "test", "dummy"])),
  1471. ok = filelib:ensure_dir(filename:join([AppDir2, "src", "dummy"])),
  1472. ok = filelib:ensure_dir(filename:join([AppDir2, "include", "dummy"])),
  1473. ok = file:write_file(filename:join([AppDir1, "test", "test.erl"]), Src),
  1474. ok = file:write_file(filename:join([AppDir2, "include", "test.hrl"]), Include),
  1475. RebarConfig = [],
  1476. rebar_test_utils:run_and_check(Config, RebarConfig,
  1477. ["as", "test", "compile"],
  1478. {ok, [{app, Name1}]}),
  1479. ok.
  1480. %% this test sets the env var, compiles, records the file last modified timestamp,
  1481. %% recompiles and compares the file last modified timestamp to ensure it hasn't
  1482. %% changed. this test should run on 19.x+
  1483. dont_recompile_when_erl_compiler_options_env_does_not_change(Config) ->
  1484. %% save existing env to restore after test
  1485. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1486. AppDir = ?config(apps, Config),
  1487. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1488. Vsn = rebar_test_utils:create_random_vsn(),
  1489. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1490. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1491. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1492. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1493. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1494. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1495. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1496. || F <- Files, filename:extension(F) == ".beam"],
  1497. timer:sleep(1000),
  1498. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1499. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1500. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1501. || F <- NewFiles, filename:extension(F) == ".beam"],
  1502. ?assert(ModTime == NewModTime),
  1503. %% restore existing env
  1504. case ExistingEnv of
  1505. false -> ok;
  1506. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1507. end.
  1508. %% this test compiles, records the file last modified timestamp, sets the env
  1509. %% var, recompiles and compares the file last modified timestamp to ensure it
  1510. %% has changed. this test should run on 19.x+
  1511. recompile_when_erl_compiler_options_env_changes(Config) ->
  1512. %% save existing env to restore after test
  1513. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1514. AppDir = ?config(apps, Config),
  1515. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1516. Vsn = rebar_test_utils:create_random_vsn(),
  1517. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1518. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1519. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1520. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1521. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1522. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1523. || F <- Files, filename:extension(F) == ".beam"],
  1524. timer:sleep(1000),
  1525. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1526. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1527. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1528. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1529. || F <- NewFiles, filename:extension(F) == ".beam"],
  1530. ?assert(ModTime =/= NewModTime),
  1531. %% restore existing env
  1532. case ExistingEnv of
  1533. false -> ok;
  1534. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1535. end.
  1536. rebar_config_os_var(Config) ->
  1537. AppDir = ?config(apps, Config),
  1538. Name = rebar_test_utils:create_random_name("rebar_config_os_var_"),
  1539. Vsn = rebar_test_utils:create_random_vsn(),
  1540. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1541. rebar_test_utils:create_config(AppDir, [{erl_opts, []}]),
  1542. AltConfig = filename:join(AppDir, "test.rebar.config"),
  1543. file:write_file(AltConfig, "{erl_opts, [compressed]}."),
  1544. true = os:putenv("REBAR_CONFIG", AltConfig),
  1545. rebar_test_utils:run_and_check(Config, ["compile"], {ok, [{app, Name}]}),
  1546. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1547. code:add_patha(Path),
  1548. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1549. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1550. ok.
  1551. %% this test sets the env var, compiles, records the file last modified
  1552. %% timestamp, recompiles and compares the file last modified timestamp to
  1553. %% ensure it has changed. this test should run on 18.x
  1554. always_recompile_when_erl_compiler_options_set(Config) ->
  1555. %% save existing env to restore after test
  1556. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1557. AppDir = ?config(apps, Config),
  1558. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1559. Vsn = rebar_test_utils:create_random_vsn(),
  1560. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1561. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1562. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1563. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1564. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1565. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1566. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1567. || F <- Files, filename:extension(F) == ".beam"],
  1568. timer:sleep(1000),
  1569. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1570. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1571. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1572. || F <- NewFiles, filename:extension(F) == ".beam"],
  1573. ?assert(ModTime =/= NewModTime),
  1574. %% restore existing env
  1575. case ExistingEnv of
  1576. false -> ok;
  1577. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1578. end.
  1579. recompile_when_parse_transform_inline_changes(Config) ->
  1580. AppDir = ?config(apps, Config),
  1581. Name = rebar_test_utils:create_random_name("parse_transform_inline_"),
  1582. Vsn = rebar_test_utils:create_random_vsn(),
  1583. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1584. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1585. ModSrc = <<"-module(example).\n"
  1586. "-export([foo/2]).\n"
  1587. "-compile([{parse_transform, example_parse_transform}]).\n"
  1588. "foo(_, _) -> ok.">>,
  1589. ok = file:write_file(filename:join([AppDir, "src", "example.erl"]),
  1590. ModSrc),
  1591. ParseTransform = <<"-module(example_parse_transform).\n"
  1592. "-export([parse_transform/2]).\n"
  1593. "parse_transform(AST, _) -> AST.\n">>,
  1594. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1595. ParseTransform),
  1596. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1597. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1598. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1599. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1600. || F <- Files, filename:basename(F, ".beam") == "example"],
  1601. timer:sleep(1000),
  1602. NewParseTransform = <<"-module(example_parse_transform).\n"
  1603. "-export([parse_transform/2]).\n"
  1604. "parse_transform(AST, _) -> identity(AST).\n"
  1605. "identity(AST) -> AST.\n">>,
  1606. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1607. NewParseTransform),
  1608. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1609. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1610. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1611. || F <- NewFiles, filename:basename(F, ".beam") == "example"],
  1612. ?assert(ModTime =/= NewModTime).
  1613. recompile_when_parse_transform_as_opt_changes(Config) ->
  1614. AppDir = ?config(apps, Config),
  1615. Name = rebar_test_utils:create_random_name("parse_transform_opt_"),
  1616. Vsn = rebar_test_utils:create_random_vsn(),
  1617. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1618. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1619. ModSrc = <<"-module(example).\n"
  1620. "-export([foo/2]).\n"
  1621. "foo(_, _) -> ok.">>,
  1622. ok = file:write_file(filename:join([AppDir, "src", "example.erl"]),
  1623. ModSrc),
  1624. ParseTransform = <<"-module(example_parse_transform).\n"
  1625. "-export([parse_transform/2]).\n"
  1626. "parse_transform(AST, _) -> AST.">>,
  1627. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1628. ParseTransform),
  1629. RebarConfig = [{erl_opts, [{parse_transform, example_parse_transform}]}],
  1630. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1631. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1632. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1633. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1634. || F <- Files, filename:basename(F, ".beam") == "example"],
  1635. timer:sleep(1000),
  1636. NewParseTransform = <<"-module(example_parse_transform).\n"
  1637. "-export([parse_transform/2]).\n"
  1638. "parse_transform(AST, _) -> identity(AST).\n"
  1639. "identity(AST) -> AST.">>,
  1640. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1641. NewParseTransform),
  1642. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1643. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1644. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1645. || F <- NewFiles, filename:basename(F, ".beam") == "example"],
  1646. ?assert(ModTime =/= NewModTime).
  1647. recursive(Config) ->
  1648. AppDir = ?config(apps, Config),
  1649. Name = rebar_test_utils:create_random_name("app1_"),
  1650. Vsn = rebar_test_utils:create_random_vsn(),
  1651. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1652. rebar_test_utils:write_src_file(filename:join(AppDir,src),"rec.erl"),
  1653. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1654. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1655. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1656. ?assert(lists:member("rec.beam",Files)).
  1657. no_recursive(Config) ->
  1658. AppDir = ?config(apps, Config),
  1659. Name = rebar_test_utils:create_random_name("app1_"),
  1660. Vsn = rebar_test_utils:create_random_vsn(),
  1661. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1662. rebar_test_utils:write_src_file(filename:join(AppDir,src),"rec.erl"),
  1663. RebarConfig1 = [{erlc_compiler,[{recursive,false}]}],
  1664. rebar_test_utils:run_and_check(Config, RebarConfig1, ["compile"],
  1665. {ok, [{app, Name}]}),
  1666. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1667. {ok, Files1} = rebar_utils:list_dir(EbinDir),
  1668. ?assert(false==lists:member("rec.beam",Files1)),
  1669. RebarConfig2 = [{src_dirs,[{"src",[{recursive,false}]}]}],
  1670. rebar_test_utils:run_and_check(Config, RebarConfig2, ["compile"],
  1671. {ok, [{app, Name}]}),
  1672. {ok, Files2} = rebar_utils:list_dir(EbinDir),
  1673. ?assert(false==lists:member("rec.beam",Files2)),
  1674. ok.
  1675. regex_filter_skip(Config) ->
  1676. AppDir = ?config(apps, Config),
  1677. Name = rebar_test_utils:create_random_name("regex_skip"),
  1678. Vsn = rebar_test_utils:create_random_vsn(),
  1679. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1680. rebar_test_utils:write_src_file(filename:join(AppDir,src),"._rec.erl"),
  1681. Expected = filename:join([AppDir, "_build", "default", "lib", Name, "ebin","._rec.beam"]),
  1682. RebarConfig = [],
  1683. try
  1684. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  1685. {ok, [{file, Expected}]}),
  1686. throw(should_not_be_found)
  1687. catch
  1688. %% the file was not found, as desired!
  1689. error:{assertion_failed,_} -> %% OTP =< 17
  1690. ok;
  1691. error:{assert,_} -> %% OTP >= 18
  1692. ok
  1693. end.
  1694. regex_filter_regression(Config) ->
  1695. AppDir = ?config(apps, Config),
  1696. Name = rebar_test_utils:create_random_name("regex_regression"),
  1697. Vsn = rebar_test_utils:create_random_vsn(),
  1698. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1699. rebar_test_utils:write_src_file(filename:join(AppDir,src),"r_f.erl"),
  1700. Expected = filename:join([AppDir, "_build", "default", "lib", Name, "ebin","r_f.beam"]),
  1701. RebarConfig = [],
  1702. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  1703. {ok, [{file, Expected}]}),
  1704. ok.