Skip to content

Commit

Permalink
Merge pull request #9753 from keymanapp/chore/linux/coverage
Browse files Browse the repository at this point in the history
chore(linux): Add code coverage reports for keyman-config and keyman-system-service
  • Loading branch information
ermshiperete authored Oct 12, 2023
2 parents d283165 + fe81d8c commit 5be0865
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 11 deletions.
37 changes: 36 additions & 1 deletion docs/settings/linux/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@
"group": "test",
"detail": "unit test keyman-config"
},
{
"type": "shell",
"label": "keyman-config: report",
"command": "${workspaceFolder}/linux/keyman-config/build.sh",
"args": [
"test",
"--report",
"--debug",
"--coverage",
"--no-integration"
],
"options": {
"cwd": "${workspaceFolder}/linux/keyman-config",
},
"group": "test",
"detail": "run tests and create unit test coverage report"
},
{
"type": "shell",
"label": "keyman-system-service: clean",
Expand Down Expand Up @@ -265,6 +282,7 @@
"command": "${workspaceFolder}/linux/keyman-system-service/build.sh",
"args": [
"--debug",
"--coverage",
"configure"
],
"options": {
Expand All @@ -282,13 +300,30 @@
"command": "${workspaceFolder}/linux/keyman-system-service/build.sh",
"args": [
"--debug",
"test:arch"
"test"
],
"problemMatcher": [
"$gcc"
],
"group": "test",
"detail": "run tests for keyman-system-service"
},
{
"type": "shell",
"label": "keyman-system-service: report",
"command": "${workspaceFolder}/linux/keyman-system-service/build.sh",
"args": [
"test",
"--report",
"--debug",
"--coverage",
"--no-integration",
],
"problemMatcher": [
"$gcc"
],
"group": "test",
"detail": "run tests and create unit test coverage report"
},
]
}
4 changes: 3 additions & 1 deletion linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ builder_describe \
"test" \
"install install artifacts" \
"uninstall uninstall artifacts" \
"--no-integration+ don't run integration tests"
"--no-integration+ don't run integration tests" \
"--report+ create coverage report" \
"--coverage+ capture test coverage"

builder_parse "$@"

Expand Down
18 changes: 16 additions & 2 deletions linux/keyman-config/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ builder_describe \
"test" \
"install install artifacts" \
"uninstall uninstall artifacts" \
"--no-integration don't run integration tests"
"--no-integration don't run integration tests" \
"--report create coverage report" \
"--coverage capture test coverage"

builder_parse "$@"

Expand Down Expand Up @@ -87,7 +89,19 @@ build_action() {
}

test_action() {
execute_with_temp_schema ./run-tests.sh
local options

if builder_has_option --coverage; then
options="--coverage"
else
options=""
fi
execute_with_temp_schema ./run-tests.sh "${options}"

if builder_has_option --report; then
builder_echo "Creating coverage report"
python3 -m coverage html --directory="$THIS_SCRIPT_PATH/build/coveragereport/" --data-file=build/.coverage
fi
}

install_action() {
Expand Down
15 changes: 10 additions & 5 deletions linux/keyman-config/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ if [ -f /usr/libexec/ibus-memconf ]; then
export GSETTINGS_BACKEND=keyfile
fi

if [ "$1" == "--coverage" ]; then
coverage="-m coverage run --source=. --data-file=build/.coverage"
fi

if [ -n "$TEAMCITY_VERSION" ]; then
if ! pip3 list --format=columns | grep -q teamcity-messages; then
pip3 install teamcity-messages
fi
python3 -m teamcity.unittestpy discover -s tests -p test_*.py
if ! pip3 list --format=columns | grep -q teamcity-messages; then
pip3 install teamcity-messages
fi
python3 -m teamcity.unittestpy discover -s tests -p test_*.py
else
python3 -m unittest discover -v -s tests -p test_*.py
# shellcheck disable=SC2086
python3 ${coverage:-} -m unittest discover -v -s tests -p test_*.py
fi

rm -rf "$XDG_CONFIG_HOME"
16 changes: 14 additions & 2 deletions linux/keyman-system-service/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ builder_describe \
"test" \
"install install artifacts" \
"uninstall uninstall artifacts" \
"--no-integration don't run integration tests"
"--no-integration don't run integration tests" \
"--report create coverage report" \
"--coverage capture test coverage"

builder_parse "$@"

Expand All @@ -37,10 +39,16 @@ builder_describe_outputs \
configure "${MESON_PATH}/build.ninja" \
build "${MESON_PATH}/src/keyman-system-service"

if builder_has_option --coverage; then
MESON_COVERAGE=-Db_coverage=true
else
MESON_COVERAGE=
fi

builder_run_action clean rm -rf "$THIS_SCRIPT_PATH/build/"

# shellcheck disable=SC2086
builder_run_action configure meson setup "$MESON_PATH" --werror --buildtype $MESON_TARGET "${builder_extra_params[@]}"
builder_run_action configure meson setup "$MESON_PATH" --werror --buildtype $MESON_TARGET ${MESON_COVERAGE} "${builder_extra_params[@]}"

if builder_start_action build; then
cd "$MESON_PATH"
Expand All @@ -51,6 +59,10 @@ fi
if builder_start_action test; then
cd "$MESON_PATH"
meson test --print-errorlogs $builder_verbose
if builder_has_option --coverage; then
# Note: requires lcov > 1.16 to properly work (see https://github.com/mesonbuild/meson/issues/6747)
ninja coverage-html
fi
builder_finish_action success test
fi

Expand Down

0 comments on commit 5be0865

Please sign in to comment.