diff options
author | Lukas Larsson <lukas@erlang.org> | 2021-04-06 10:31:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-06 10:31:17 +0200 |
commit | 41816872b72292e4650aa86b812ad448b3578f9a (patch) | |
tree | 5624d1f0feb79a3f1e06ca76c355efd11d30fb99 | |
parent | 874d09fa7618dbdc90f03584a4e497257e7a9a50 (diff) | |
parent | 90c5ea371e467176373208a350c62f612e51eb23 (diff) | |
download | erlang-41816872b72292e4650aa86b812ad448b3578f9a.tar.gz |
Merge pull request #4695 from joaohf/ensure_surefire_directory/OTP-17300
eunit: ensure the output directory exist for surefire xml files
-rw-r--r-- | lib/eunit/src/eunit_surefire.erl | 14 | ||||
-rw-r--r-- | lib/eunit/test/eunit_SUITE.erl | 9 |
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/eunit/src/eunit_surefire.erl b/lib/eunit/src/eunit_surefire.erl index 002a069a92..71f3765f21 100644 --- a/lib/eunit/src/eunit_surefire.erl +++ b/lib/eunit/src/eunit_surefire.erl @@ -95,6 +95,7 @@ start(Options) -> init(Options) -> XMLDir = proplists:get_value(dir, Options, ?XMLDIR), + ensure_xmldir(XMLDir), St = #state{verbose = proplists:get_bool(verbose, Options), xmldir = XMLDir, testsuites = []}, @@ -255,6 +256,19 @@ add_testcase_to_testsuite({error, Exception}, TestCaseTmp, TestSuite) -> testcases = [TestCase|TestSuite#testsuite.testcases] } end. +ensure_xmldir(XMLDir) -> + Steps = [ + fun filelib:ensure_dir/1, + fun file:make_dir/1], + lists:foldl(fun ensure_xmldir/2, XMLDir, Steps). + +ensure_xmldir(Fun, XMLDir) -> + case Fun(XMLDir) of + ok -> XMLDir; + {error, eexist} -> XMLDir; + {error, _Reason} = Error -> throw(Error) + end. + %% ---------------------------------------------------------------------------- %% Write a report to the XML directory. %% This function opens the report file, calls write_report_to/2 and closes the file. diff --git a/lib/eunit/test/eunit_SUITE.erl b/lib/eunit/test/eunit_SUITE.erl index e55091e8c1..df754e46c5 100644 --- a/lib/eunit/test/eunit_SUITE.erl +++ b/lib/eunit/test/eunit_SUITE.erl @@ -22,7 +22,7 @@ -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, app_test/1,appup_test/1,eunit_test/1,surefire_utf8_test/1,surefire_latin_test/1, - surefire_c0_test/1]). + surefire_c0_test/1, surefire_ensure_dir_test/1]). -include_lib("common_test/include/ct.hrl"). @@ -30,7 +30,7 @@ suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [app_test, appup_test, eunit_test, surefire_utf8_test, surefire_latin_test, - surefire_c0_test]. + surefire_c0_test, surefire_ensure_dir_test]. groups() -> []. @@ -76,6 +76,11 @@ surefire_c0_test(Config) when is_list(Config) -> true = lists:member($\t, Chars), ok. +surefire_ensure_dir_test(Config) when is_list(Config) -> + XMLDir = filename:join(proplists:get_value(priv_dir, Config), "c1"), + ok = eunit:test(tc0, [{report,{eunit_surefire,[{dir,XMLDir}]}}]), + ok = file:del_dir_r(XMLDir). + check_surefire(Module) -> File = "TEST-"++atom_to_list(Module)++".xml", file:delete(File), |