diff --git a/README.md b/README.md index 0db75a571..349eaed2d 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ $ bin/shell Run a specific test (the shell offers autocompletion): ```sh -(master@127.0.0.1)1> eunit:test(ar_fork_recovery_tests:height_plus_one_fork_recovery_test_()). +bin/test ar_fork_recovery_tests:height_plus_one_fork_recovery_test_ ``` If it fails, the nodes keep running so you can inspect them through Erlang shell or HTTP API. diff --git a/apps/arweave/src/ar.erl b/apps/arweave/src/ar.erl index d9d30f5ce..f91a77adf 100644 --- a/apps/arweave/src/ar.erl +++ b/apps/arweave/src/ar.erl @@ -871,9 +871,10 @@ tests(Mods, Config) when is_list(Mods) -> io:format("Failed to start the peers due to ~p:~p~n", [Type, Reason]), erlang:halt(1) end, + Tests = extract_single_test(Mods), Result = try - eunit:test({timeout, ?TEST_TIMEOUT, [Mods]}, [verbose, {print_depth, 100}]) + eunit:test({timeout, ?TEST_TIMEOUT, [Tests]}, [verbose, {print_depth, 100}]) after ar_test_node:stop_peers() end, @@ -882,6 +883,27 @@ tests(Mods, Config) when is_list(Mods) -> _ -> erlang:halt(1) end. +extract_single_test(Modules) -> + lists:map( + fun(TestRep) -> + case string:split(atom_to_list(TestRep), ":") of + [TestModule, TestFunction] -> + parse_generator_or_test(TestModule, TestFunction); + _ -> + TestRep + end + end, + Modules + ). + +parse_generator_or_test(TestModule, TestFunction) -> + TestType = case string:split(TestFunction, "_test_") of + [_, []] -> + generator; + _ -> + test + end, + {TestType, list_to_atom(TestModule), list_to_atom(TestFunction)}. start_for_tests(Config) -> UniqueName = ar_test_node:get_node_namespace(), diff --git a/bin/test b/bin/test index 13e79e197..4b2c0d807 100755 --- a/bin/test +++ b/bin/test @@ -8,10 +8,20 @@ cd "$SCRIPT_DIR/.." export ERL_EPMD_ADDRESS=127.0.0.1 +if [[ $# -gt 0 ]]; then + MODULES=$@ +else + SRC_MODULES=$(ls $SCRIPT_DIR/../apps/arweave/src | sed -n 's/.erl$//p' | sort) + TEST_MODULE_BASENAMES=$(ls $SCRIPT_DIR/../apps/arweave/test | sed -n 's/_tests.erl$//p' | sort) + NON_SRC_TEST_MODULE_BASENAMES=$(comm -13 <(printf "%s\n" $SRC_MODULES) <(printf "%s\n" $TEST_MODULE_BASENAMES)) + NON_SRC_TEST_MODULES=$(echo $NON_SRC_TEST_MODULE_BASENAMES | xargs -I{} echo '{}_tests') + MODULES="$SRC_MODULES $NON_SRC_TEST_MODULES" +fi + ERL_TEST_OPTS="-pa `./rebar3 as test path` `./rebar3 as test path --base`/lib/arweave/test -config config/sys.config" echo -e "\033[0;32m===> Running tests...\033[0m" set -x set -o pipefail -stdbuf -oL -eL erl $ERL_TEST_OPTS -noshell -name main-localtest@127.0.0.1 -setcookie test -run ar tests ${@:1} -s init stop 2>&1 | tee main-localtest.out -set +x \ No newline at end of file +stdbuf -oL -eL erl $ERL_TEST_OPTS -noshell -name main-localtest@127.0.0.1 -setcookie test -run ar tests $MODULES -s init stop 2>&1 | tee main-localtest.out +set +x