Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions private/ct.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ set -eo pipefail
{maybe_install_erlang}

COVER_ARGS=
if [ -n "${{COVERAGE}}" ]; then
if [ -n "{coverage}" ] && [ -n "${{COVERAGE}}" ]; then
cat << EOF > "${{TEST_UNDECLARED_OUTPUTS_DIR}}/ct.cover.spec"
{{incl_app, '{app_name}', details}}.
{{incl_dirs, {apps_ebin_dirs_term}}}.
Expand Down Expand Up @@ -194,13 +194,14 @@ set -x
-hidden \\
-sname {sname} ${{COVER_ARGS}} {extra_args}
set +x
if [ -n "${{COVERAGE}}" ]; then
if [ -n "{coverage}" ] && [ -n "${{COVERAGE}}" ]; then
"{erlang_home}"/bin/escript $TEST_SRCDIR/$TEST_WORKSPACE/{coverdata_to_lcov} \\
${{COVERAGE_OUTPUT_FILE}} \\
${{COVERAGE_OUTPUT_FILE}} \\
> ${{TEST_UNDECLARED_OUTPUTS_DIR}}/coverdata_to_lcov.log
fi
""".format(
coverage = "1" if ctx.configuration.coverage_enabled else "",
maybe_install_erlang = maybe_install_erlang(ctx, short_path = True),
app_name = app_name,
apps_ebin_dirs_term = to_erlang_string_list(apps_ebin_dirs),
Expand Down Expand Up @@ -271,6 +272,17 @@ if NOT [{package}] == [] cd {package}

if not exist "{drive_letter}:" mkdir {drive_letter}:

if [{coverage}] == [] set "COVERAGE="
set "COVER_ARGS="
if not defined COVERAGE goto :no_cover
set "COVERAGE_OUT=%COVERAGE_OUTPUT_FILE:\\=/%"
set "COVER_SRCDIR=%TEST_SRCDIR:\\=/%"
set "COVER_SPEC=%TEST_UNDECLARED_OUTPUTS_DIR:/=\\%\\ct.cover.spec"
echo {{incl_app, '{app_name}', details}}.> "%COVER_SPEC%"
echo {{incl_dirs, {apps_ebin_dirs_term}}}.>> "%COVER_SPEC%"
echo {{export, "%COVERAGE_OUT%"}}.>> "%COVER_SPEC%"
set "COVER_ARGS=-cover "%COVER_SPEC:\\=/%""
:no_cover
echo on
"{erlang_home}\\bin\\ct_run" ^
-no_auto_compile ^
Expand All @@ -279,13 +291,22 @@ echo on
-dir test {pa_args} ^
-logdir {drive_letter}: ^
-hidden ^
-sname {sname} {extra_args}
-sname {sname} %COVER_ARGS% {extra_args}
set CT_RUN_ERRORLEVEL=%ERRORLEVEL%
subst {drive_letter}: /d
exit /b %CT_RUN_ERRORLEVEL%
if not [%CT_RUN_ERRORLEVEL%] == [0] exit /b %CT_RUN_ERRORLEVEL%
@echo off
if not defined COVERAGE exit /b 0
set "COVERAGE_LOG=%TEST_UNDECLARED_OUTPUTS_DIR:/=\\%\\coverdata_to_lcov.log"
"{erlang_home}\\bin\\escript.exe" "%TEST_SRCDIR%/%TEST_WORKSPACE%/{coverdata_to_lcov}" "%COVERAGE_OUTPUT_FILE%" "%COVERAGE_OUTPUT_FILE%" > "%COVERAGE_LOG%" || exit /b 1
exit /b 0
:skip_test
""".format(
package = package,
coverage = "1" if ctx.configuration.coverage_enabled else "",
app_name = app_name,
apps_ebin_dirs_term = to_erlang_string_list([d.replace("$TEST_SRCDIR", "%COVER_SRCDIR%").replace("$TEST_WORKSPACE", "%TEST_WORKSPACE%") for d in apps_ebin_dirs]),
coverdata_to_lcov = coverdata_to_lcov_path,
erlang_home = windows_path(erlang_home),
erl_libs_path = erl_libs_path,
shard_suite = shard_suite_path,
Expand Down
25 changes: 21 additions & 4 deletions private/eunit.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fi

COVER_PRE=
COVER_POST=
if [ -n "${{COVERAGE}}" ]; then
if [ -n "{coverage}" ] && [ -n "${{COVERAGE}}" ]; then
COVER_PRE="[case cover:compile_beam_directory(D) of {{error, _}} -> halt(1); _ -> ok end || D <- {apps_ebin_dirs_term}], "
COVER_POST="cover:export(\\"${{COVERAGE_OUTPUT_FILE}}\\"), "
fi
Expand All @@ -141,13 +141,14 @@ set -x
{pa_args} {extra_args} \\
-eval "${{COVER_PRE}}case eunit:test({eunit_mods_term},{eunit_opts_term}) of ok -> ok; error -> halt(2) end, ${{COVER_POST}}halt()."
set +x
if [ -n "${{COVERAGE}}" ]; then
if [ -n "{coverage}" ] && [ -n "${{COVERAGE}}" ]; then
"{erlang_home}"/bin/escript $TEST_SRCDIR/$TEST_WORKSPACE/{coverdata_to_lcov} \\
${{COVERAGE_OUTPUT_FILE}} \\
${{COVERAGE_OUTPUT_FILE}} \\
> ${{TEST_UNDECLARED_OUTPUTS_DIR}}/coverdata_to_lcov.log
fi
""".format(
coverage = "1" if ctx.configuration.coverage_enabled else "",
maybe_install_erlang = maybe_install_erlang(ctx, short_path = True),
erlang_home = erlang_home,
apps_ebin_dirs_term = _quote(to_erlang_string_list(apps_ebin_dirs)),
Expand Down Expand Up @@ -177,11 +178,27 @@ set ERL_LIBS=%ERL_LIBS:/=\\%

if NOT [{package}] == [] cd {package}

if [{coverage}] == [] set "COVERAGE="
set "COVER_PRE="
set "COVER_POST="
set "COVER_ARGS="
if defined COVERAGE set "COVER_PRE=[case cover:compile_beam_directory(D) of {{error, _}} -> halt(1); _ -> ok end || D <- hd(element(2, init:get_argument(cover_dirs)))], "
if defined COVERAGE set "COVER_POST=cover:export(hd(hd(element(2, init:get_argument(cover_out))))), "
if defined COVERAGE set "COVERAGE_OUT=%COVERAGE_OUTPUT_FILE:\\=/%"
if defined COVERAGE set COVER_ARGS=-cover_dirs {apps_ebin_dirs_args} -cover_out "%COVERAGE_OUT%"

echo on
"{erlang_home}\\bin\\erl" +A1 -noinput -boot no_dot_erlang ^
{pa_args} {extra_args} ^
-eval "case eunit:test({eunit_mods_term},{eunit_opts_term}) of ok -> ok; error -> halt(2) end, halt()" || exit /b 1
{pa_args} %COVER_ARGS% {extra_args} ^
-eval "%COVER_PRE%case eunit:test({eunit_mods_term},{eunit_opts_term}) of ok -> ok; error -> halt(2) end, %COVER_POST%halt()" || exit /b 1
@echo off
if not defined COVERAGE exit /b 0
set "COVERAGE_LOG=%TEST_UNDECLARED_OUTPUTS_DIR:/=\\%\\coverdata_to_lcov.log"
"{erlang_home}\\bin\\escript.exe" "%TEST_SRCDIR%/%TEST_WORKSPACE%/{coverdata_to_lcov}" "%COVERAGE_OUTPUT_FILE%" "%COVERAGE_OUTPUT_FILE%" > "%COVERAGE_LOG%" || exit /b 1
""".format(
coverage = "1" if ctx.configuration.coverage_enabled else "",
apps_ebin_dirs_args = " ".join(['"{}"'.format(d.replace("$TEST_SRCDIR", "%TEST_SRCDIR%").replace("$TEST_WORKSPACE", "%TEST_WORKSPACE%")) for d in apps_ebin_dirs]),
coverdata_to_lcov = coverdata_to_lcov_path,
package = package,
erlang_home = windows_path(erlang_home),
erl_libs_path = erl_libs_path if len(erl_libs_files) > 0 else "",
Expand Down