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.

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