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

586 lines
23 KiB

  1. -module(rebar_profiles_SUITE).
  2. -export([init_per_suite/1,
  3. end_per_suite/1,
  4. init_per_testcase/2,
  5. end_per_testcase/2,
  6. all/0,
  7. profile_new_key/1,
  8. profile_merge_keys/1,
  9. profile_merge_umbrella_keys/1,
  10. explicit_profile_deduplicate_deps/1,
  11. implicit_profile_deduplicate_deps/1,
  12. all_deps_code_paths/1,
  13. profile_merges/1,
  14. same_profile_deduplication/1,
  15. stack_deduplication/1,
  16. add_to_profile/1,
  17. add_to_existing_profile/1,
  18. profiles_remain_applied_with_config_present/1,
  19. deduplicated_paths/1,
  20. test_profile_applied_at_completion/1,
  21. test_profile_applied_before_compile/1,
  22. test_profile_applied_before_eunit/1,
  23. test_profile_applied_to_apps/1,
  24. test_profile_erl_opts_order_1/1,
  25. test_profile_erl_opts_order_2/1,
  26. test_profile_erl_opts_order_3/1,
  27. test_profile_erl_opts_order_4/1,
  28. test_profile_erl_opts_order_5/1,
  29. first_files_exception/1]).
  30. -include_lib("common_test/include/ct.hrl").
  31. -include_lib("eunit/include/eunit.hrl").
  32. -include_lib("kernel/include/file.hrl").
  33. all() ->
  34. [profile_new_key, profile_merge_keys, profile_merge_umbrella_keys,
  35. all_deps_code_paths, profile_merges,
  36. explicit_profile_deduplicate_deps, implicit_profile_deduplicate_deps,
  37. same_profile_deduplication, stack_deduplication,
  38. add_to_profile, add_to_existing_profile,
  39. profiles_remain_applied_with_config_present,
  40. deduplicated_paths,
  41. test_profile_applied_at_completion,
  42. test_profile_applied_before_compile,
  43. test_profile_applied_before_eunit,
  44. test_profile_applied_to_apps,
  45. test_profile_erl_opts_order_1,
  46. test_profile_erl_opts_order_2,
  47. test_profile_erl_opts_order_3,
  48. test_profile_erl_opts_order_4,
  49. test_profile_erl_opts_order_5,
  50. first_files_exception].
  51. init_per_suite(Config) ->
  52. application:start(meck),
  53. Config.
  54. end_per_suite(_Config) ->
  55. application:stop(meck).
  56. init_per_testcase(_, Config) ->
  57. rebar_test_utils:init_rebar_state(Config, "profiles_").
  58. end_per_testcase(_, Config) ->
  59. meck:unload(),
  60. Config.
  61. profile_new_key(Config) ->
  62. AppDir = ?config(apps, Config),
  63. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  64. ,{"b", "1.0.0", []}]),
  65. {SrcDeps, []} = rebar_test_utils:flat_deps(AllDeps),
  66. mock_git_resource:mock([{deps, SrcDeps}]),
  67. Name = rebar_test_utils:create_random_name("profile_new_key_"),
  68. Vsn = rebar_test_utils:create_random_vsn(),
  69. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  70. Deps = rebar_test_utils:top_level_deps(
  71. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  72. ,{"b", "1.0.0", []}])),
  73. ct:pal("Deps ~p", [Deps]),
  74. RebarConfig = [{profiles,
  75. [{ct,
  76. [{deps, Deps}]}]}],
  77. rebar_test_utils:run_and_check(Config, RebarConfig,
  78. ["as", "ct", "compile"], {ok, [{app, Name}
  79. ,{dep, "a", "1.0.0"}
  80. ,{dep, "b", "1.0.0"}]}).
  81. profile_merge_keys(Config) ->
  82. AppDir = ?config(apps, Config),
  83. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  84. ,{"b", "1.0.0", []}
  85. ,{"b", "2.0.0", []}]),
  86. {SrcDeps, []} = rebar_test_utils:flat_deps(AllDeps),
  87. mock_git_resource:mock([{deps, SrcDeps}]),
  88. Name = rebar_test_utils:create_random_name("profile_new_key_"),
  89. Vsn = rebar_test_utils:create_random_vsn(),
  90. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  91. Deps = rebar_test_utils:top_level_deps(
  92. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  93. ,{"b", "1.0.0", []}])),
  94. ProfileDeps = rebar_test_utils:top_level_deps(
  95. rebar_test_utils:expand_deps(git, [{"b", "2.0.0", []}])),
  96. RebarConfig = [{deps, Deps},
  97. {profiles,
  98. [{ct,
  99. [{deps, ProfileDeps}]}]}],
  100. rebar_test_utils:run_and_check(Config, RebarConfig,
  101. ["as", "ct", "compile"], {ok, [{app, Name}
  102. ,{dep, "a", "1.0.0"}
  103. ,{dep, "b", "2.0.0"}]}).
  104. profile_merge_umbrella_keys(Config) ->
  105. AppDir = ?config(apps, Config),
  106. ct:pal("Path: ~s", [AppDir]),
  107. Name = rebar_test_utils:create_random_name("profile_merge_umbrella_keys"),
  108. Vsn = rebar_test_utils:create_random_vsn(),
  109. SubAppDir = filename:join([AppDir, "apps", Name]),
  110. RebarConfig = [{vals, [{a,1},{b,1}]},
  111. {profiles,
  112. [{ct,
  113. [{vals, [{a,1},{b,2}]}]}]}],
  114. SubRebarConfig = [{vals, []},
  115. {profiles, [{ct, [{vals, [{c,1}]}]}]}],
  116. rebar_test_utils:create_app(SubAppDir, Name, Vsn, [kernel, stdlib]),
  117. rebar_test_utils:create_config(SubAppDir, SubRebarConfig),
  118. {ok, RebarConfigRead} = file:consult(rebar_test_utils:create_config(AppDir, RebarConfig)),
  119. {ok, State} = rebar_test_utils:run_and_check(
  120. Config, RebarConfigRead, ["as", "ct", "compile"], return
  121. ),
  122. [ProjectApp] = rebar_state:project_apps(State),
  123. ?assertEqual(Name, binary_to_list(rebar_app_info:name(ProjectApp))),
  124. Opts = rebar_app_info:opts(ProjectApp),
  125. ?assertEqual([{a,1},{b,2},{b,1},{c,1}], dict:fetch(vals, Opts)),
  126. ok.
  127. explicit_profile_deduplicate_deps(Config) ->
  128. AppDir = ?config(apps, Config),
  129. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  130. ,{"a", "2.0.0", []}
  131. ,{"b", "1.0.0", []}
  132. ,{"b", "2.0.0", []}]),
  133. {SrcDeps, []} = rebar_test_utils:flat_deps(AllDeps),
  134. mock_git_resource:mock([{deps, SrcDeps}]),
  135. Name = rebar_test_utils:create_random_name("explicit_profile_deduplicate_deps_"),
  136. Vsn = rebar_test_utils:create_random_vsn(),
  137. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  138. FooDeps = rebar_test_utils:top_level_deps(
  139. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []},
  140. {"b", "2.0.0", []}])),
  141. BarDeps = rebar_test_utils:top_level_deps(
  142. rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])),
  143. RebarConfig = [{profiles,
  144. [{foo,
  145. [{deps, FooDeps}]},
  146. {bar,
  147. [{deps, BarDeps}]}]}],
  148. rebar_test_utils:run_and_check(Config, RebarConfig,
  149. ["as", "bar,foo,bar", "compile"], {ok, [{app, Name}
  150. ,{dep, "a", "1.0.0"}
  151. ,{dep, "b", "1.0.0"}]}).
  152. implicit_profile_deduplicate_deps(Config) ->
  153. AppDir = ?config(apps, Config),
  154. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  155. ,{"a", "2.0.0", []}
  156. ,{"b", "1.0.0", []}
  157. ,{"b", "2.0.0", []}]),
  158. {SrcDeps, []} = rebar_test_utils:flat_deps(AllDeps),
  159. mock_git_resource:mock([{deps, SrcDeps}]),
  160. Name = rebar_test_utils:create_random_name("implicit_profile_deduplicate_deps_"),
  161. Vsn = rebar_test_utils:create_random_vsn(),
  162. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  163. TestDeps = rebar_test_utils:top_level_deps(
  164. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []},
  165. {"b", "2.0.0", []}])),
  166. ProfileDeps = rebar_test_utils:top_level_deps(
  167. rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])),
  168. RebarConfig = [{profiles,
  169. [{test,
  170. [{deps, TestDeps}]},
  171. {bar,
  172. [{deps, ProfileDeps}]}]}],
  173. rebar_test_utils:run_and_check(Config, RebarConfig,
  174. ["as", "test,bar", "eunit"], {ok, [{app, Name}
  175. ,{dep, "a", "1.0.0"}
  176. ,{dep, "b", "2.0.0"}]}).
  177. all_deps_code_paths(Config) ->
  178. AppDir = ?config(apps, Config),
  179. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  180. ,{"b", "2.0.0", []}]),
  181. {SrcDeps, []} = rebar_test_utils:flat_deps(AllDeps),
  182. mock_git_resource:mock([{deps, SrcDeps}]),
  183. Name = rebar_test_utils:create_random_name("all_deps_code_paths"),
  184. Vsn = rebar_test_utils:create_random_vsn(),
  185. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  186. Deps = rebar_test_utils:top_level_deps(
  187. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}])),
  188. ProfileDeps = rebar_test_utils:top_level_deps(
  189. rebar_test_utils:expand_deps(git, [{"b", "2.0.0", []}])),
  190. RebarConfig = [{deps, Deps},
  191. {profiles,
  192. [{all_deps_test,
  193. [{deps, ProfileDeps}]}]}],
  194. os:putenv("REBAR_PROFILE", "all_deps_test"),
  195. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig,
  196. ["compile"], {ok, [{app, Name}
  197. ,{dep, "a", "1.0.0"}
  198. ,{dep, "b", "2.0.0"}]}),
  199. os:putenv("REBAR_PROFILE", ""),
  200. Paths = rebar_state:code_paths(State, all_deps),
  201. Path = lists:reverse(["_build", "all_deps_test", "lib", "b", "ebin"]),
  202. ?assert(lists:any(fun(X) ->
  203. Path =:= lists:sublist(lists:reverse(filename:split(X)), 5)
  204. end, Paths)).
  205. profile_merges(_Config) ->
  206. RebarConfig = [{test1, [{key1, 1, 2}, key2]},
  207. {test2, "hello"},
  208. {test3, [key3]},
  209. {test4, "oldvalue"},
  210. {test5, [{key5, true}]},
  211. {test6, [{key6, false}]},
  212. {profiles,
  213. [{profile1,
  214. [{test1, [{key3, 5}, key1]}]},
  215. {profile2, [{test2, "goodbye"},
  216. {test3, []},
  217. {test4, []},
  218. {test5, [{key5, false}]},
  219. {test6, [{key6, true}]}
  220. ]}]}],
  221. State = rebar_state:new(RebarConfig),
  222. State1 = rebar_state:apply_profiles(State, [profile1, profile2]),
  223. %% Combine lists
  224. ?assertEqual(lists:sort([key1, key2, {key1, 1, 2}, {key3, 5}]),
  225. lists:sort(rebar_state:get(State1, test1))),
  226. %% Use new value for strings
  227. "goodbye" = rebar_state:get(State1, test2),
  228. %% Check that a newvalue of []/"" doesn't override non-string oldvalues
  229. [key3] = rebar_state:get(State1, test3),
  230. [] = rebar_state:get(State1, test4),
  231. [{key5, false}, {key5, true}] = rebar_state:get(State1, test5),
  232. [{key6, true}, {key6, false}] = rebar_state:get(State1, test6).
  233. same_profile_deduplication(_Config) ->
  234. RebarConfig = [{test1, [{key1, 1, 2}, key2]},
  235. {test2, [foo]},
  236. {test3, [key3]},
  237. {profiles,
  238. [{profile1,
  239. [{test1, [{key3, 5}, {key2, "hello"}]},
  240. {test2, [bar]},
  241. {test3, []}
  242. ]}]
  243. }],
  244. State = rebar_state:new(RebarConfig),
  245. State1 = rebar_state:apply_profiles(State, [profile1, profile1, profile1]),
  246. ?assertEqual([default, profile1], rebar_state:current_profiles(State1)),
  247. Test1 = rebar_state:get(State1, test1),
  248. %% Combine lists
  249. ?assertEqual(lists:sort([key2, {key1, 1, 2}, {key3, 5}, {key2, "hello"}]),
  250. lists:sort(Test1)),
  251. %% Key2 from profile1 overrides key2 from default profile
  252. ?assertEqual("hello", proplists:get_value(key2, Test1)),
  253. %% Check that a newvalue of []/"" doesn't override non-string oldvalues
  254. ?assertEqual([key3], rebar_state:get(State1, test3)),
  255. ?assertEqual([bar, foo], rebar_state:get(State1, test2)).
  256. stack_deduplication(_Config) ->
  257. RebarConfig = [
  258. {test_key, default},
  259. {test_list, [ {foo, default} ]},
  260. {profiles, [
  261. {a, [
  262. {test_key, a},
  263. {test_list, [ {foo, a} ]}
  264. ]},
  265. {b, [
  266. {test_key, b},
  267. {test_list, [ {foo, b} ]}
  268. ]},
  269. {c, [
  270. {test_key, c},
  271. {test_list, [ {foo, c} ]}
  272. ]},
  273. {d, [
  274. {test_key, d},
  275. {test_list, [ {foo, d} ]}
  276. ]},
  277. {e, [
  278. {test_key, e},
  279. {test_list, [ {foo, e} ]}
  280. ]}
  281. ]}
  282. ],
  283. State = rebar_state:new(RebarConfig),
  284. State1 = rebar_state:apply_profiles(State, [a, b, c, d, e, a, e, b]),
  285. ?assertEqual(b, rebar_state:get(State1, test_key)),
  286. TestList = rebar_state:get(State1, test_list),
  287. ?assertEqual(
  288. [{foo, b}, {foo, e}, {foo, a}, {foo, d}, {foo, c}, {foo, default} ],
  289. TestList
  290. ),
  291. ?assertEqual(b, proplists:get_value(foo, TestList)).
  292. add_to_profile(_Config) ->
  293. RebarConfig = [{foo, true}, {bar, false}],
  294. State = rebar_state:new(RebarConfig),
  295. State1 = rebar_state:add_to_profile(State, test, [{foo, false}]),
  296. State2 = rebar_state:apply_profiles(State1, test),
  297. Opts = rebar_state:opts(State2),
  298. lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar]).
  299. add_to_existing_profile(_Config) ->
  300. RebarConfig = [{foo, true}, {bar, false}, {profiles, [
  301. {test, [{foo, false}]}
  302. ]}],
  303. State = rebar_state:new(RebarConfig),
  304. State1 = rebar_state:add_to_profile(State, test, [{baz, false}]),
  305. State2 = rebar_state:apply_profiles(State1, test),
  306. Opts = rebar_state:opts(State2),
  307. lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar, baz]).
  308. profiles_remain_applied_with_config_present(Config) ->
  309. AppDir = ?config(apps, Config),
  310. Name = rebar_test_utils:create_random_name("profiles_remain_applied_"),
  311. Vsn = rebar_test_utils:create_random_vsn(),
  312. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  313. RebarConfig = [{erl_opts, []}, {profiles, [
  314. {not_ok, [{erl_opts, [{d, not_ok}]}]}
  315. ]}],
  316. rebar_test_utils:create_config(AppDir, RebarConfig),
  317. rebar_test_utils:run_and_check(Config, RebarConfig,
  318. ["as", "not_ok", "compile"], {ok, [{app, Name}]}),
  319. Path = filename:join([AppDir, "_build", "not_ok", "lib", Name, "ebin"]),
  320. code:add_patha(Path),
  321. Mod = list_to_atom("not_a_real_src_" ++ Name),
  322. true = lists:member({d, not_ok}, proplists:get_value(options, Mod:module_info(compile), [])).
  323. deduplicated_paths(Config) ->
  324. AppDir = ?config(apps, Config),
  325. Name = rebar_test_utils:create_random_name("deduplicated_paths_"),
  326. Vsn = rebar_test_utils:create_random_vsn(),
  327. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  328. RebarConfig = [],
  329. rebar_test_utils:create_config(AppDir, RebarConfig),
  330. rebar_test_utils:run_and_check(Config, RebarConfig,
  331. ["as", "a,b,c,d,e,a,e,b", "compile"],
  332. {ok, [{app, Name}]}),
  333. Path = filename:join([AppDir, "_build", "c+d+a+e+b", "lib", Name, "ebin"]),
  334. ?assert(filelib:is_dir(Path)).
  335. test_profile_applied_at_completion(Config) ->
  336. AppDir = ?config(apps, Config),
  337. Name = rebar_test_utils:create_random_name("test_profile_at_completion_"),
  338. Vsn = rebar_test_utils:create_random_vsn(),
  339. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  340. RebarConfig = [{erl_opts, [{d, some_define}]}],
  341. rebar_test_utils:create_config(AppDir, RebarConfig),
  342. {ok, State} = rebar_test_utils:run_and_check(Config,
  343. RebarConfig,
  344. ["eunit"],
  345. return),
  346. [App] = rebar_state:project_apps(State),
  347. ErlOpts = rebar_app_info:get(App, erl_opts),
  348. true = lists:member({d, 'TEST'}, ErlOpts).
  349. test_profile_applied_before_compile(Config) ->
  350. AppDir = ?config(apps, Config),
  351. Name = rebar_test_utils:create_random_name("test_profile_before_compile_"),
  352. Vsn = rebar_test_utils:create_random_vsn(),
  353. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  354. RebarConfig = [{erl_opts, [{d, some_define}]}],
  355. rebar_test_utils:create_config(AppDir, RebarConfig),
  356. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}),
  357. code:add_paths(rebar_state:code_paths(State, all_deps)),
  358. S = list_to_atom("not_a_real_src_" ++ Name),
  359. true = lists:member({d, 'TEST'}, proplists:get_value(options, S:module_info(compile), [])).
  360. test_profile_applied_before_eunit(Config) ->
  361. AppDir = ?config(apps, Config),
  362. Name = rebar_test_utils:create_random_name("test_profile_before_eunit_"),
  363. Vsn = rebar_test_utils:create_random_vsn(),
  364. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  365. RebarConfig = [{erl_opts, [{d, some_define}]}],
  366. rebar_test_utils:create_config(AppDir, RebarConfig),
  367. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}),
  368. code:add_paths(rebar_state:code_paths(State, all_deps)),
  369. T = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"),
  370. true = lists:member({d, 'TEST'}, proplists:get_value(options, T:module_info(compile), [])).
  371. test_profile_applied_to_apps(Config) ->
  372. AppDir = ?config(apps, Config),
  373. Name = rebar_test_utils:create_random_name("test_profile_applied_to_apps_"),
  374. Vsn = rebar_test_utils:create_random_vsn(),
  375. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  376. RebarConfig = [{erl_opts, [{d, some_define}]}],
  377. rebar_test_utils:create_config(AppDir, RebarConfig),
  378. {ok, State} = rebar_test_utils:run_and_check(Config,
  379. RebarConfig,
  380. ["eunit"],
  381. return),
  382. Apps = rebar_state:project_apps(State),
  383. lists:foreach(fun(App) ->
  384. Opts = rebar_app_info:opts(App),
  385. ErlOpts = dict:fetch(erl_opts, Opts),
  386. true = lists:member({d, 'TEST'}, ErlOpts)
  387. end, Apps).
  388. test_profile_erl_opts_order_1(Config) ->
  389. Opts = get_compiled_profile_erl_opts([default], Config),
  390. Opt = last_erl_opt(Opts, [warn_export_all, nowarn_export_all], undefined),
  391. undefined = Opt.
  392. test_profile_erl_opts_order_2(Config) ->
  393. Opts = get_compiled_profile_erl_opts([strict], Config),
  394. Opt = last_erl_opt(Opts, [warn_export_all, nowarn_export_all], undefined),
  395. warn_export_all = Opt.
  396. test_profile_erl_opts_order_3(Config) ->
  397. Opts = get_compiled_profile_erl_opts([loose], Config),
  398. Opt = last_erl_opt(Opts, [warn_export_all, nowarn_export_all], undefined),
  399. nowarn_export_all = Opt.
  400. test_profile_erl_opts_order_4(Config) ->
  401. Opts = get_compiled_profile_erl_opts([strict, loose], Config),
  402. Opt = last_erl_opt(Opts, [warn_export_all, nowarn_export_all], undefined),
  403. nowarn_export_all = Opt.
  404. test_profile_erl_opts_order_5(Config) ->
  405. Opts = get_compiled_profile_erl_opts([loose, strict], Config),
  406. Opt = last_erl_opt(Opts, [warn_export_all, nowarn_export_all], undefined),
  407. warn_export_all = Opt.
  408. first_files_exception(_Config) ->
  409. RebarConfig = [{erl_first_files, ["c","a","b"]},
  410. {mib_first_files, ["c","a","b"]},
  411. {other, ["c","a","b"]},
  412. {profiles,
  413. [{profile2, [{erl_first_files, ["a","e"]},
  414. {mib_first_files, ["a","e"]},
  415. {other, ["a","e"]}
  416. ]}]}],
  417. State = rebar_state:new(RebarConfig),
  418. State1 = rebar_state:apply_profiles(State, [profile2]),
  419. %% Combine lists
  420. ?assertEqual(["a","b","c","e"], rebar_state:get(State1, other)),
  421. %% there is no specific reason not to dedupe "a" here aside from "this is how it is"
  422. ?assertEqual(["c","a","b","a","e"], rebar_state:get(State1, erl_first_files)),
  423. ?assertEqual(["c","a","b","a","e"], rebar_state:get(State1, mib_first_files)),
  424. ok.
  425. get_compiled_profile_erl_opts(Profiles, Config) ->
  426. AppDir = ?config(apps, Config),
  427. PStrs = [atom_to_list(P) || P <- Profiles],
  428. Name = rebar_test_utils:create_random_name(
  429. lists:flatten(["erl_opts_order_" | [[S, $_] || S <- PStrs]])),
  430. Vsn = rebar_test_utils:create_random_vsn(),
  431. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  432. RebarConfig = [
  433. {erl_opts, [warnings_as_errors, {d, profile_default}]},
  434. {profiles, [
  435. {strict, [{erl_opts, [warn_export_all, {d, profile_strict}]}]},
  436. {loose, [{erl_opts, [nowarn_export_all, {d, profile_loose}]}]} ]}],
  437. rebar_test_utils:create_config(AppDir, RebarConfig),
  438. Command = case Profiles of
  439. [] ->
  440. ["compile"];
  441. [default] ->
  442. ["compile"];
  443. _ ->
  444. ["as", string:join(PStrs, ","), "compile"]
  445. end,
  446. {ok, State} = rebar_test_utils:run_and_check(
  447. Config, RebarConfig, Command, {ok, [{app, Name}]}),
  448. code:add_paths(rebar_state:code_paths(State, all_deps)),
  449. Mod = list_to_atom(Name),
  450. proplists:get_value(options, Mod:module_info(compile), []).
  451. % macro definitions get special handling
  452. last_erl_opt([{d, Macro} = Opt | Opts], Targets, Last) ->
  453. case lists:any(erl_opt_macro_match_fun(Macro), Targets) of
  454. true ->
  455. last_erl_opt(Opts, Targets, Opt);
  456. _ ->
  457. last_erl_opt(Opts, Targets, Last)
  458. end;
  459. last_erl_opt([{d, Macro, _} = Opt | Opts], Targets, Last) ->
  460. case lists:any(erl_opt_macro_match_fun(Macro), Targets) of
  461. true ->
  462. last_erl_opt(Opts, Targets, Opt);
  463. _ ->
  464. last_erl_opt(Opts, Targets, Last)
  465. end;
  466. last_erl_opt([Opt | Opts], Targets, Last) ->
  467. case lists:member(Opt, Targets) of
  468. true ->
  469. last_erl_opt(Opts, Targets, Opt);
  470. _ ->
  471. last_erl_opt(Opts, Targets, Last)
  472. end;
  473. last_erl_opt([], _, Last) ->
  474. Last.
  475. erl_opt_macro_match_fun(Macro) ->
  476. fun({d, M}) ->
  477. M == Macro;
  478. ({d, M, _}) ->
  479. M == Macro;
  480. (_) ->
  481. false
  482. end.