Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

581 строка
25 KiB

10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
  1. -module(rebar_eunit_SUITE).
  2. -export([all/0, groups/0]).
  3. -export([init_per_suite/1, init_per_group/2, end_per_group/2]).
  4. -export([basic_app_compiles/1, basic_app_files/1]).
  5. -export([basic_app_exports/1, basic_app_testset/1]).
  6. -export([basic_app_eunit_macro/1]).
  7. -export([multi_app_compiles/1, multi_app_files/1]).
  8. -export([multi_app_exports/1, multi_app_testset/1]).
  9. -export([multi_app_eunit_macro/1]).
  10. -export([eunit_tests/1, eunit_opts/1, eunit_first_files/1]).
  11. -export([single_application_arg/1, multi_application_arg/1, missing_application_arg/1]).
  12. -export([single_module_arg/1, multi_module_arg/1, missing_module_arg/1]).
  13. -export([single_suite_arg/1, multi_suite_arg/1, missing_suite_arg/1]).
  14. -export([single_file_arg/1, multi_file_arg/1, missing_file_arg/1]).
  15. -export([single_dir_arg/1, multi_dir_arg/1, missing_dir_arg/1]).
  16. -export([multiple_arg_composition/1, multiple_arg_errors/1]).
  17. -export([misspecified_eunit_tests/1]).
  18. -export([misspecified_eunit_compile_opts/1]).
  19. -export([misspecified_eunit_first_files/1]).
  20. -include_lib("common_test/include/ct.hrl").
  21. -include_lib("eunit/include/eunit.hrl").
  22. -include_lib("kernel/include/file.hrl").
  23. all() ->
  24. [{group, basic_app}, {group, multi_app}, {group, cmd_line_args},
  25. misspecified_eunit_tests,
  26. misspecified_eunit_compile_opts,
  27. misspecified_eunit_first_files].
  28. groups() ->
  29. [{basic_app, [sequence], [basic_app_compiles, {group, basic_app_results}]},
  30. {basic_app_results, [], [basic_app_files,
  31. basic_app_exports,
  32. basic_app_testset,
  33. basic_app_eunit_macro]},
  34. {multi_app, [sequence], [multi_app_compiles, {group, multi_app_results}]},
  35. {multi_app_results, [], [multi_app_files,
  36. multi_app_exports,
  37. multi_app_testset,
  38. multi_app_eunit_macro]},
  39. {cmd_line_args, [], [eunit_tests, eunit_opts, eunit_first_files,
  40. single_application_arg, multi_application_arg, missing_application_arg,
  41. single_module_arg, multi_module_arg, missing_module_arg,
  42. single_suite_arg, multi_suite_arg, missing_suite_arg,
  43. single_file_arg, multi_file_arg, missing_file_arg,
  44. single_dir_arg, multi_dir_arg, missing_dir_arg,
  45. multiple_arg_composition, multiple_arg_errors]}].
  46. %% this just unzips the example apps used by tests to the priv dir for later use
  47. init_per_suite(Config) ->
  48. PrivDir = ?config(priv_dir, Config),
  49. DataDir = ?config(data_dir, Config),
  50. ok = ec_file:copy(filename:join([DataDir, "basic_app.zip"]), filename:join([PrivDir, "basic_app.zip"])),
  51. {ok, _} = zip:extract(filename:join([PrivDir, "basic_app.zip"]), [{cwd, PrivDir}]),
  52. ok = ec_file:copy(filename:join([DataDir, "multi_app.zip"]), filename:join([PrivDir, "multi_app.zip"])),
  53. {ok, _} = zip:extract(filename:join([PrivDir, "multi_app.zip"]), [{cwd, PrivDir}]),
  54. Config.
  55. init_per_group(basic_app, Config) ->
  56. GroupState = rebar_test_utils:init_rebar_state(Config, "basic_app_"),
  57. AppDir = ?config(apps, GroupState),
  58. PrivDir = ?config(priv_dir, GroupState),
  59. AppDirs = ["src", "include", "test"],
  60. lists:foreach(fun(F) -> ec_file:copy(filename:join([PrivDir, "basic_app", F]),
  61. filename:join([AppDir, F]),
  62. [recursive]) end, AppDirs),
  63. RebarConfig = [{erl_opts, [{d, config_define}]}, {eunit_compile_opts, [{d, eunit_compile_define}]}],
  64. {ok, State} = rebar_test_utils:run_and_check(GroupState, RebarConfig, ["as", "test", "lock"], return),
  65. [{result, State}|GroupState];
  66. init_per_group(multi_app, Config) ->
  67. GroupState = rebar_test_utils:init_rebar_state(Config, "multi_app_"),
  68. AppDir = ?config(apps, GroupState),
  69. PrivDir = ?config(priv_dir, GroupState),
  70. AppDirs = ["apps", "test"],
  71. lists:foreach(fun(F) -> ec_file:copy(filename:join([PrivDir, "multi_app", F]),
  72. filename:join([AppDir, F]),
  73. [recursive]) end, AppDirs),
  74. RebarConfig = [{erl_opts, [{d, config_define}]}, {eunit_compile_opts, [{d, eunit_compile_define}]}],
  75. {ok, State} = rebar_test_utils:run_and_check(GroupState, RebarConfig, ["as", "test", "lock"], return),
  76. [{result, State}|GroupState];
  77. init_per_group(cmd_line_args, Config) ->
  78. GroupState = rebar_test_utils:init_rebar_state(Config, "cmd_line_args_"),
  79. AppDir = ?config(apps, GroupState),
  80. PrivDir = ?config(priv_dir, GroupState),
  81. AppDirs = ["apps", "test"],
  82. lists:foreach(fun(F) -> ec_file:copy(filename:join([PrivDir, "multi_app", F]),
  83. filename:join([AppDir, F]),
  84. [recursive]) end, AppDirs),
  85. RebarConfig = [{erl_opts, [{d, config_define}]},
  86. {eunit_compile_opts, [{d, eunit_compile_define}]},
  87. %% test set not supported by cmd line args
  88. {eunit_tests, [{test, multi_app_bar, sanity_test},
  89. {test, multi_app_baz, sanity_test}]},
  90. {eunit_opts, [verbose]},
  91. {eunit_first_files, [filename:join(["apps", "multi_app_bar", "test", "multi_app_bar_tests_helper.erl"]),
  92. filename:join(["apps", "multi_app_baz", "test", "multi_app_baz_tests_helper.erl"])]}],
  93. {ok, State} = rebar_test_utils:run_and_check(GroupState, RebarConfig, ["eunit"], return),
  94. [{result, State}|GroupState];
  95. init_per_group(_, Config) -> Config.
  96. end_per_group(_, Config) -> Config.
  97. %% === tests for a single application at the root of a project ===
  98. %% check that project compiles properly
  99. basic_app_compiles(Config) ->
  100. AppDir = ?config(apps, Config),
  101. State = ?config(result, Config),
  102. {ok, _} = rebar_prv_eunit:do(State),
  103. rebar_test_utils:check_results(AppDir, [{app, "basic_app"}], "*").
  104. %% check that all files expected to be present are present
  105. basic_app_files(Config) ->
  106. AppDir = ?config(apps, Config),
  107. lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "lib", "basic_app", "ebin", F])) end,
  108. ["basic_app.app", "basic_app.beam"]),
  109. lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "lib", "basic_app", "test", F])) end,
  110. ["basic_app_tests.beam", "basic_app_tests_helper.beam"]).
  111. %% check that the correct tests are exported from modules for project
  112. %% note that this implies `TEST` is set correctly
  113. basic_app_exports(_Config) ->
  114. Tests = fun(Mod) ->
  115. begin
  116. Path = code:which(Mod),
  117. {ok, {Mod, [{exports, Ex}]}} = beam_lib:chunks(Path, [exports]),
  118. true = lists:member({sanity_test, 0}, Ex)
  119. end
  120. end,
  121. Helpers = fun(Mod) ->
  122. begin
  123. Path = code:which(Mod),
  124. {ok, {Mod, [{exports, Ex}]}} = beam_lib:chunks(Path, [exports]),
  125. true = lists:member({help, 0}, Ex)
  126. end
  127. end,
  128. lists:foreach(Tests, [basic_app, basic_app_tests]),
  129. lists:foreach(Helpers, [basic_app_tests_helper]).
  130. %% check that the correct tests are schedule to run for project
  131. basic_app_testset(Config) ->
  132. Result = ?config(result, Config),
  133. Set = {ok, [{application, basic_app},
  134. {module, basic_app_tests_helper}]},
  135. Set = rebar_prv_eunit:prepare_tests(Result).
  136. basic_app_eunit_macro(_Config) ->
  137. Macro = fun(Mod) ->
  138. begin
  139. Path = code:which(Mod),
  140. {ok, {Mod, [{compile_info, CompileInfo}]}} = beam_lib:chunks(Path, [compile_info]),
  141. Opts = proplists:get_value(options, CompileInfo, []),
  142. true = lists:member({d, 'EUNIT'}, Opts)
  143. end
  144. end,
  145. lists:foreach(Macro, [basic_app, basic_app_tests, basic_app_tests_helper]).
  146. %% === tests for multiple applications in the `apps' directory of a project ===
  147. %% check that project compiles properly
  148. multi_app_compiles(Config) ->
  149. AppDir = ?config(apps, Config),
  150. State = ?config(result, Config),
  151. {ok, _} = rebar_prv_eunit:do(State),
  152. rebar_test_utils:check_results(AppDir, [{app, "multi_app_bar"}, {app, "multi_app_baz"}], "*").
  153. %% check that all files expected to be present are present
  154. multi_app_files(Config) ->
  155. AppDir = ?config(apps, Config),
  156. lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin", F])) end,
  157. ["multi_app_bar.app", "multi_app_bar.beam"]),
  158. lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "ebin", F])) end,
  159. ["multi_app_baz.app", "multi_app_baz.beam"]),
  160. lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "test", F])) end,
  161. ["multi_app_bar_tests.beam", "multi_app_bar_tests_helper.beam"]),
  162. lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "test", F])) end,
  163. ["multi_app_baz_tests.beam", "multi_app_baz_tests_helper.beam"]),
  164. lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "extras", "test", F])) end,
  165. ["multi_app_tests.beam", "multi_app_tests_helper.beam"]).
  166. %% check that the correct tests are exported from modules for project
  167. %% note that this implies `TEST` is set correctly
  168. multi_app_exports(_Config) ->
  169. Tests = fun(Mod) ->
  170. begin
  171. Ex = Mod:module_info(exports),
  172. true = lists:member({sanity_test, 0}, Ex)
  173. end
  174. end,
  175. Helpers = fun(Mod) ->
  176. begin
  177. Ex = Mod:module_info(exports),
  178. true = lists:member({help, 0}, Ex)
  179. end
  180. end,
  181. lists:foreach(Tests, [multi_app_bar, multi_app_bar_tests,
  182. multi_app_baz, multi_app_baz_tests,
  183. multi_app_tests]),
  184. lists:foreach(Helpers, [multi_app_bar_tests_helper, multi_app_baz_tests_helper, multi_app_tests_helper]).
  185. %% check that the correct tests are schedule to run for project
  186. multi_app_testset(Config) ->
  187. Result = ?config(result, Config),
  188. Set = {ok, [{application, multi_app_baz},
  189. {application, multi_app_bar},
  190. {module, multi_app_bar_tests_helper},
  191. {module, multi_app_baz_tests_helper},
  192. {module, multi_app_tests},
  193. {module, multi_app_tests_helper}]},
  194. Set = rebar_prv_eunit:prepare_tests(Result).
  195. multi_app_eunit_macro(_Config) ->
  196. Macro = fun(Mod) ->
  197. begin
  198. Path = code:which(Mod),
  199. {ok, {Mod, [{compile_info, CompileInfo}]}} = beam_lib:chunks(Path, [compile_info]),
  200. Opts = proplists:get_value(options, CompileInfo, []),
  201. true = lists:member({d, 'EUNIT'}, Opts)
  202. end
  203. end,
  204. lists:foreach(Macro, [multi_app_bar, multi_app_bar_tests,
  205. multi_app_baz, multi_app_baz_tests,
  206. multi_app_tests, multi_app_tests_helper,
  207. multi_app_bar_tests_helper, multi_app_baz_tests_helper]).
  208. %% === tests for command line arguments ===
  209. %% no explicit test for cmd line args taking precedence over the rebar.config since
  210. %% almost every single test implies it
  211. %% check tests in the rebar.config are run if no cmd line opts are specified
  212. eunit_tests(Config) ->
  213. State = ?config(result, Config),
  214. Expect = {ok, [{test, multi_app_bar, sanity_test}, {test, multi_app_baz, sanity_test}]},
  215. Expect = rebar_prv_eunit:prepare_tests(State).
  216. %% check eunit_opts from the rebar.config are respected
  217. eunit_opts(Config) ->
  218. State = ?config(result, Config),
  219. Apps = rebar_state:project_apps(State),
  220. lists:foreach(fun(App) -> [verbose] = rebar_app_info:get(App, eunit_opts) end,
  221. Apps).
  222. %% check eunit_first_files from the rebar.config are respected
  223. eunit_first_files(Config) ->
  224. State = ?config(result, Config),
  225. FirstFiles = [filename:join(["apps", "multi_app_bar", "test", "multi_app_bar_tests_helper.erl"]),
  226. filename:join(["apps", "multi_app_baz", "test", "multi_app_baz_tests_helper.erl"])],
  227. Apps = rebar_state:project_apps(State),
  228. lists:foreach(fun(App) -> FirstFiles = rebar_app_info:get(App, eunit_first_files) end,
  229. Apps).
  230. %% check that the --application cmd line opt generates the correct test set
  231. single_application_arg(Config) ->
  232. S = ?config(result, Config),
  233. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--application=multi_app_bar"]),
  234. State = rebar_state:command_parsed_args(S, Args),
  235. {ok, [{application, multi_app_bar}]} = rebar_prv_eunit:prepare_tests(State).
  236. multi_application_arg(Config) ->
  237. S = ?config(result, Config),
  238. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--application=multi_app_bar,multi_app_baz"]),
  239. State = rebar_state:command_parsed_args(S, Args),
  240. {ok, [{application, multi_app_bar}, {application, multi_app_baz}]} = rebar_prv_eunit:prepare_tests(State).
  241. %% check that an invalid --application cmd line opt generates an error
  242. missing_application_arg(Config) ->
  243. S = ?config(result, Config),
  244. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--application=missing_app"]),
  245. State = rebar_state:command_parsed_args(S, Args),
  246. Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["Application `missing_app' not found in project."]}}},
  247. Error = rebar_prv_eunit:validate_tests(State, rebar_prv_eunit:prepare_tests(State)).
  248. %% check that the --module cmd line opt generates the correct test set
  249. single_module_arg(Config) ->
  250. AppDir = ?config(apps, Config),
  251. S = ?config(result, Config),
  252. %% necessary to fix paths
  253. Path = code:get_path(),
  254. code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"])]),
  255. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--module=multi_app_bar"]),
  256. State = rebar_state:command_parsed_args(S, Args),
  257. {ok, [{module, multi_app_bar}]} = rebar_prv_eunit:prepare_tests(State),
  258. %% restore path
  259. code:set_path(Path).
  260. multi_module_arg(Config) ->
  261. AppDir = ?config(apps, Config),
  262. S = ?config(result, Config),
  263. %% necessary to fix paths
  264. Path = code:get_path(),
  265. code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"])]),
  266. code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "ebin"])]),
  267. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--module=multi_app_bar,multi_app_baz"]),
  268. State = rebar_state:command_parsed_args(S, Args),
  269. {ok, [{module, multi_app_bar}, {module, multi_app_baz}]} = rebar_prv_eunit:prepare_tests(State),
  270. %% restore path
  271. code:set_path(Path).
  272. %% check that an invalid --module cmd line opt generates an error
  273. missing_module_arg(Config) ->
  274. S = ?config(result, Config),
  275. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--module=missing_app"]),
  276. State = rebar_state:command_parsed_args(S, Args),
  277. T = rebar_prv_eunit:prepare_tests(State),
  278. Tests = rebar_prv_eunit:validate_tests(S, T),
  279. Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["Module `missing_app' not found in project."]}}},
  280. Error = Tests.
  281. %% check that the --suite cmd line opt generates the correct test set
  282. single_suite_arg(Config) ->
  283. AppDir = ?config(apps, Config),
  284. S = ?config(result, Config),
  285. %% necessary to fix paths
  286. Path = code:get_path(),
  287. code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"])]),
  288. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--suite=multi_app_bar"]),
  289. State = rebar_state:command_parsed_args(S, Args),
  290. {ok, [{module, multi_app_bar}]} = rebar_prv_eunit:prepare_tests(State),
  291. %% restore path
  292. code:set_path(Path).
  293. multi_suite_arg(Config) ->
  294. AppDir = ?config(apps, Config),
  295. S = ?config(result, Config),
  296. %% necessary to fix paths
  297. Path = code:get_path(),
  298. code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"])]),
  299. code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "ebin"])]),
  300. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--suite=multi_app_bar,multi_app_baz"]),
  301. State = rebar_state:command_parsed_args(S, Args),
  302. {ok, [{module, multi_app_bar}, {module, multi_app_baz}]} = rebar_prv_eunit:prepare_tests(State),
  303. %% restore path
  304. code:set_path(Path).
  305. %% check that an invalid --suite cmd line opt generates an error
  306. missing_suite_arg(Config) ->
  307. S = ?config(result, Config),
  308. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--suite=missing_app"]),
  309. State = rebar_state:command_parsed_args(S, Args),
  310. Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["Module `missing_app' not found in project."]}}},
  311. Error = rebar_prv_eunit:validate_tests(State, rebar_prv_eunit:prepare_tests(State)).
  312. %% check that the --file cmd line opt generates the correct test set
  313. single_file_arg(Config) ->
  314. S = ?config(result, Config),
  315. AppDir = ?config(apps, Config),
  316. Path = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin", "multi_app_bar.beam"]),
  317. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--file=" ++ Path]),
  318. State = rebar_state:command_parsed_args(S, Args),
  319. {ok, [{file, Path}]} = rebar_prv_eunit:prepare_tests(State).
  320. multi_file_arg(Config) ->
  321. S = ?config(result, Config),
  322. AppDir = ?config(apps, Config),
  323. BarPath = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin", "multi_app_bar.beam"]),
  324. BazPath = filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "ebin", "multi_app_baz.beam"]),
  325. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--file=" ++ BarPath ++ "," ++ BazPath]),
  326. State = rebar_state:command_parsed_args(S, Args),
  327. {ok, [{file, BarPath}, {file, BazPath}]} = rebar_prv_eunit:prepare_tests(State).
  328. %% check that an invalid --file cmd line opt generates an error
  329. missing_file_arg(Config) ->
  330. S = ?config(result, Config),
  331. AppDir = ?config(apps, Config),
  332. Path = filename:join([AppDir, "_build", "test", "lib", "missing_app", "ebin", "missing_app.beam"]),
  333. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--file=" ++ Path]),
  334. State = rebar_state:command_parsed_args(S, Args),
  335. Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["File `" ++ Path ++"' not found."]}}},
  336. Error = rebar_prv_eunit:validate_tests(State, rebar_prv_eunit:prepare_tests(State)).
  337. %% check that the --dir cmd line opt generates the correct test set
  338. single_dir_arg(Config) ->
  339. S = ?config(result, Config),
  340. AppDir = ?config(apps, Config),
  341. Path = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"]),
  342. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--dir=" ++ Path]),
  343. State = rebar_state:command_parsed_args(S, Args),
  344. {ok, [{dir, Path}]} = rebar_prv_eunit:prepare_tests(State).
  345. multi_dir_arg(Config) ->
  346. S = ?config(result, Config),
  347. AppDir = ?config(apps, Config),
  348. BarPath = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"]),
  349. BazPath = filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "ebin"]),
  350. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--dir=" ++ BarPath ++ "," ++ BazPath]),
  351. State = rebar_state:command_parsed_args(S, Args),
  352. {ok, [{dir, BarPath}, {dir, BazPath}]} = rebar_prv_eunit:prepare_tests(State).
  353. %% check that an invalid --dir cmd line opt generates an error
  354. missing_dir_arg(Config) ->
  355. S = ?config(result, Config),
  356. AppDir = ?config(apps, Config),
  357. Path = filename:join([AppDir, "_build", "test", "lib", "missing_app", "ebin"]),
  358. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--dir=" ++ Path]),
  359. State = rebar_state:command_parsed_args(S, Args),
  360. Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["Directory `" ++ Path ++"' not found."]}}},
  361. Error = rebar_prv_eunit:validate_tests(State, rebar_prv_eunit:prepare_tests(State)).
  362. %% check that multiple args are composed
  363. multiple_arg_composition(Config) ->
  364. S = ?config(result, Config),
  365. AppDir = ?config(apps, Config),
  366. %% necessary to fix paths
  367. Path = code:get_path(),
  368. code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"])]),
  369. FilePath = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin", "multi_app_bar.beam"]),
  370. DirPath = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"]),
  371. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--application=multi_app_bar",
  372. "--module=multi_app_bar",
  373. "--suite=multi_app_bar",
  374. "--file=" ++ FilePath,
  375. "--dir=" ++ DirPath]),
  376. State = rebar_state:command_parsed_args(S, Args),
  377. Expect = [{application, multi_app_bar},
  378. {dir, DirPath},
  379. {file, FilePath},
  380. {module, multi_app_bar},
  381. {module, multi_app_bar}],
  382. {ok, Expect} = rebar_prv_eunit:prepare_tests(State),
  383. %% restore path
  384. code:set_path(Path).
  385. %% check that multiple errors are reported
  386. multiple_arg_errors(Config) ->
  387. S = ?config(result, Config),
  388. AppDir = ?config(apps, Config),
  389. FilePath = filename:join([AppDir, "_build", "test", "lib", "missing_app", "ebin", "missing_app.beam"]),
  390. DirPath = filename:join([AppDir, "_build", "test", "lib", "missing_app", "ebin"]),
  391. {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--application=missing_app",
  392. "--module=missing_app",
  393. "--suite=missing_app",
  394. "--file=" ++ FilePath,
  395. "--dir=" ++ DirPath]),
  396. State = rebar_state:command_parsed_args(S, Args),
  397. T = rebar_prv_eunit:prepare_tests(State),
  398. Tests = rebar_prv_eunit:validate_tests(S, T),
  399. Expect = ["Application `missing_app' not found in project.",
  400. "Directory `" ++ DirPath ++ "' not found.",
  401. "File `" ++ FilePath ++ "' not found.",
  402. "Module `missing_app' not found in project.",
  403. "Module `missing_app' not found in project."],
  404. {error, {rebar_prv_eunit, {eunit_test_errors, Expect}}} = Tests.
  405. misspecified_eunit_tests(Config) ->
  406. State = rebar_test_utils:init_rebar_state(Config, "basic_app_"),
  407. AppDir = ?config(apps, State),
  408. PrivDir = ?config(priv_dir, State),
  409. AppDirs = ["src", "include", "test"],
  410. lists:foreach(fun(F) -> ec_file:copy(filename:join([PrivDir, "basic_app", F]),
  411. filename:join([AppDir, F]),
  412. [recursive]) end, AppDirs),
  413. BaseConfig = [{erl_opts, [{d, config_define}]}, {eunit_compile_opts, [{d, eunit_compile_define}]}],
  414. RebarConfig = [{eunit_tests, {dir, "test"}}|BaseConfig],
  415. {error, {rebar_prv_eunit, Error}} = rebar_test_utils:run_and_check(State, RebarConfig, ["eunit"], return),
  416. {badconfig, {"Value `~p' of option `~p' must be a list", {{dir, "test"}, eunit_tests}}} = Error.
  417. misspecified_eunit_compile_opts(Config) ->
  418. State = rebar_test_utils:init_rebar_state(Config, "basic_app_"),
  419. AppDir = ?config(apps, State),
  420. PrivDir = ?config(priv_dir, State),
  421. AppDirs = ["src", "include", "test"],
  422. lists:foreach(fun(F) -> ec_file:copy(filename:join([PrivDir, "basic_app", F]),
  423. filename:join([AppDir, F]),
  424. [recursive]) end, AppDirs),
  425. RebarConfig = [{erl_opts, [{d, config_define}]}, {eunit_compile_opts, {d, eunit_compile_define}}],
  426. {error, {rebar_prv_eunit, Error}} = rebar_test_utils:run_and_check(State, RebarConfig, ["eunit"], return),
  427. {badconfig, {"Value `~p' of option `~p' must be a list", {{d, eunit_compile_define}, eunit_compile_opts}}} = Error.
  428. misspecified_eunit_first_files(Config) ->
  429. State = rebar_test_utils:init_rebar_state(Config, "basic_app_"),
  430. AppDir = ?config(apps, State),
  431. PrivDir = ?config(priv_dir, State),
  432. AppDirs = ["src", "include", "test"],
  433. lists:foreach(fun(F) -> ec_file:copy(filename:join([PrivDir, "basic_app", F]),
  434. filename:join([AppDir, F]),
  435. [recursive]) end, AppDirs),
  436. BaseConfig = [{erl_opts, [{d, config_define}]}, {eunit_compile_opts, [{d, eunit_compile_define}]}],
  437. RebarConfig = [{eunit_first_files, some_file}|BaseConfig],
  438. {error, {rebar_prv_eunit, Error}} = rebar_test_utils:run_and_check(State, RebarConfig, ["eunit"], return),
  439. {badconfig, {"Value `~p' of option `~p' must be a list", {some_file, eunit_first_files}}} = Error.