From cc67814b657380507c3aee1222f9f2c8b8b061b4 Mon Sep 17 00:00:00 2001 From: Arjan Scherpenisse Date: Wed, 1 Aug 2012 20:47:47 +0200 Subject: [PATCH] ct: skip instead of halt on missing/unknown suite This allows `rebar ct suites=abc` to consider all suites when you have a rebar setup with multiple sub_dirs. Previously, rebar halted after it could not find the suite in the first dir. But the suite might be present in another dir (when sub_dirs contains multiple dirs). This commit makes it so instead of halting, it prints a warning and continues with looking for the suite in the other `sub_dir`s. Note -- This uses try/catch to cause the test to be skipped because otherwise I needed to adjust the return values of 4 functions, the code path is pretty deeply nested here. Otherwise the whole call chain needed to be adjusted for this return value: `run_test -> make_cmd -> get_suites -> find_suite_path` IMHO, I think for exceptional cases like this it is fine to use throw; specially since only the {skip} is catched and nothing else. --- src/rebar_ct.erl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl index 6fd5bc7..e33c6c9 100644 --- a/src/rebar_ct.erl +++ b/src/rebar_ct.erl @@ -65,7 +65,12 @@ run_test_if_present(TestDir, LogDir, Config, File) -> ++ " SUITES - skipping\n", [TestDir]), ok; _ -> - run_test(TestDir, LogDir, Config, File) + try + run_test(TestDir, LogDir, Config, File) + catch + throw:skip -> + ok + end end end. @@ -270,8 +275,10 @@ find_suite_path(Suite, TestDir) -> Path = filename:join(TestDir, Suite ++ "_SUITE.erl"), case filelib:is_regular(Path) of false -> - ?ERROR("Suite ~s not found\n", [Suite]), - ?FAIL; + ?WARN("Suite ~s not found\n", [Suite]), + %% Note - this throw is caught in run_test_if_present/3; + %% this solution was easier than refactoring the entire module. + throw(skip); true -> Path end.