Permalink
Browse files

Add code coverage support [skip appveyor]

  • Loading branch information...
sergeyklay committed Nov 16, 2018
1 parent 10d0fe5 commit fc1006f2b47b68065e282717052fe663f3e3fe7e
@@ -10,7 +10,7 @@ insert_final_newline = true
indent_style = space
indent_size = 4

[*.{c,h,awk,w32,bat,mk,Makefile,frag,zep,lemon,re,psm1}]
[*.{c,h,awk,w32,bat,mk,Makefile,frag,zep,lemon,re,psm1,sh}]
charset = utf-8
end_of_line = lf
indent_size = 4
@@ -19,7 +19,7 @@ tab_width = 4
trim_trailing_whitespace = true
insert_final_newline = true

[*.{yml,m4,sh,json,xml}]
[*.{yml,m4,json,xml}]
charset = utf-8
end_of_line = lf
indent_size = 2
@@ -50,65 +50,48 @@ env:
- ZEPHIR_VERSION="0.10.12"
- RE2C_VERSION="1.1.1"
- REPORT_EXIT_STATUS=1
- REPORT_COVERAGE=1
- NO_INTERACTION=1
- TEST_PHP_ARGS="--show-diff"
- CFLAGS="-g -O0 -Wall -std=gnu90"
- PATH="${HOME}/bin:${HOME}/.composer/vendor/bin:${PATH}"
- DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest"

before_install:
- '[[ -z "${GH_TOKEN}" ]] || composer config github-oauth.github.com ${GH_TOKEN}; echo "Configured Github token"'
- if [ ! -z "${GITHUB_TOKEN}" ]; then composer config github-oauth.github.com ${GITHUB_TOKEN}; echo "Add Github token"; fi
- export PHP_MAJOR="$(php -r 'echo phpversion();' | cut -d '.' -f 1)"
- export PHP_MINOR="$(php -r 'echo phpversion();' | cut -d '.' -f 2)"
- export PHP_VERNUM="$(php-config --vernum)"
- ./tests/_ci/pear-setup.sh
- ./tests/_ci/setup-dbs.sh
- source ./tests/_ci/environment
- export $(cut -d= -f1 ./tests/_ci/environment)
- tests/_ci/pear-setup.sh
- tests/_ci/setup-dbs.sh
- source tests/_ci/environment
- export $(cut -d= -f1 tests/_ci/environment)

install:
- ./tests/_ci/install-prereqs.sh
- ./tests/_ci/install-re2c.sh
- tests/_ci/install-prereqs.sh
- tests/_ci/install-re2c.sh
- travis_retry composer install ${DEFAULT_COMPOSER_FLAGS}
- travis_retry composer global require ${DEFAULT_COMPOSER_FLAGS} "phalcon/zephir:${ZEPHIR_VERSION}"
- zephir generate
- ./tests/_ci/precompile-headers.sh
- |
cd ext
phpize
./configure --with-php-config=$(phpenv which php-config) --enable-phalcon
make -j"$(getconf _NPROCESSORS_ONLN)" > /dev/null 2> ../compile-errors.log
make install
cd ..
- phpenv config-add ./tests/_ci/phalcon.ini
- phpenv config-add ./tests/_ci/ci.ini
- tests/_ci/build.sh

before_script:
- ulimit -c unlimited -S || true
# see: https://github.com/sebastianbergmann/phpunit/pull/3359
- '[[ "${PHP_VERNUM}" -lt 70300 ]] || export USE_ZEND_ALLOC=1'
- phpenv config-add tests/_ci/999-default.ini

script:
# To avoud this:
# sh: 1: /home/travis/build/phalcon/cphalcon/libtool: not found
- ln -s ${TRAVIS_BUILD_DIR}/ext/libtool ${TRAVIS_BUILD_DIR}/libtool
# Syntax recognize tests
- |
$(phpenv which php) "${TRAVIS_BUILD_DIR}/ext/run-tests.php" \
-p $(phpenv which php) \
-g "FAIL,XFAIL,BORK,WARN,LEAK,SKIP" \
--offline \
--show-diff \
--set-timeout 120
- vendor/bin/phpcs
- vendor/bin/codecept build
# TODO: Add `cli' suite and refactor current cli-tests
- vendor/bin/codecept run -v -n tests/integration/
- vendor/bin/codecept run -v -n tests/unit/
# TODO: Refactor legacy unit tests from the "unit-tests" directory
- phpenv config-rm xdebug.ini || true
- tests/_ci/volt-tests.sh

after_failure:
- ./tests/_ci/after-failure.sh
- tests/_ci/after-failure.sh

after_success:
- tests/_ci/after-success.sh

notifications:
email: false
File renamed without changes.
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
#
# This file is part of the Zephir.
#
# (c) Zephir Team <team@zephir-lang.com>
#
# For the full copyright and license information, please view the
# https://docs.zephir-lang.com/en/latest/license license.

set -e +o pipefail

PROJECT_ROOT=$(readlink -enq "$(dirname $0)/../../")
LCOV_REPORT=${PROJECT_ROOT}/tests/_output/lcov.info

if [[ -z ${REPORT_COVERAGE+x} ]] || [[ "$REPORT_COVERAGE" != "1" ]]; then
echo -e "\nUploading coverage data is not enabled.\nSkip uploading reports to Codecov.\n"
exit 0
fi

if [[ $(command -v lcov 2>/dev/null) = "" ]]; then
echo -e "lcov does not exist.\nSkip capturing coverage data."
else
# Capture coverage data
lcov \
--quiet \
--no-checksum \
--directory ext \
--base-directory=${PROJECT_ROOT} \
--capture \
--compat-libtool \
--output-file ${LCOV_REPORT}

# Remove files matching non-project patterns
lcov \
--quiet \
--remove ${LCOV_REPORT} "/usr*" \
--remove ${LCOV_REPORT} "${PROJECT_ROOT}/kernel/*" \
--remove ${LCOV_REPORT} "${PROJECT_ROOT}/ext/kernel/*" \
--remove ${LCOV_REPORT} "${HOME}/.phpenv/*" \
--compat-libtool \
--output-file ${LCOV_REPORT}
fi

# Note: to upload a coverage report, set the CODECOV_TOKEN environment variable
# export CODECOV_TOKEN=<codecov token>

if [[ -z ${CODECOV_TOKEN+x} ]]; then
echo -e "\nThe CODECOV_TOKEN variable is absent or empty.\nSkip uploading reports to Codecov.\n"
exit 0
fi

curl -sSl https://codecov.io/bash -o codecov.sh
chmod +x codecov.sh

if [[ -f "${LCOV_REPORT}" ]]; then
echo -e "Uploading coverage report: ${LCOV_REPORT}...\n"
./codecov.sh -f "${LCOV_REPORT}"
fi
@@ -0,0 +1,99 @@
#!/usr/bin/env bash
#
# This file is part of the Zephir.
#
# (c) Zephir Team <team@zephir-lang.com>
#
# For the full copyright and license information, please view the
# https://docs.zephir-lang.com/en/latest/license license.

PROJECT_ROOT=$(readlink -enq "$(dirname $0)/../../")
LCOV_REPORT=${PROJECT_ROOT}/tests/_output/lcov.info

shopt -s nullglob

zephir clean 2>&1
zephir fullclean 2>&1
zephir generate 2>&1

if [[ -z ${CC+x} ]]; then
echo -e "The CC variable is unset or set to the empty string.\nSkip precompiling headers.\n"
else
echo "Creating precompiled headers..."
if [[ "${CC:0:5}" = "clang" ]]; then
_ext="pch"
_option="-emit-pch"
_arg="-cc1"
else
_ext="ghc"
_option=
_arg=
fi

# If a `*.gch' (or a `*.pch') file is not found then the normal header files
# will be used. For more see: http://en.wikipedia.org/wiki/Precompiled_header
for file in `find ./ext/kernel -name "*.h"`; do
printf "\t>>> ${file}\n\t<<< ${file}.ghc\n"
${CC} ${_arg} "${file}" -I. -I./ext $(php-config --includes) ${_option} -o "${file}.${_ext}"
done
fi

cd ext

phpize

if [[ ! -z ${REPORT_COVERAGE+x} ]] && [[ "$REPORT_COVERAGE" = "1" ]]; then
# The ltmain.sh which bundled with PHP it's from libtool 1.5.26.
# However, the version of libtool that claims to no longer remove
# ".gcno" profiler information is libtool 2.2.6. The fix is probably
# in later libtool versions as well.
if [[ "$(uname -s 2>/dev/null)" = "Darwin" ]]; then
# macOS
LIBTOOLIZE_BIN=$(command -v glibtoolize 2>/dev/null)
else
# Linux, Gentoo, etc
LIBTOOLIZE_BIN=$(command -v libtoolize 2>/dev/null)
fi

aclocal && ${LIBTOOLIZE_BIN} --copy --force && autoheader && autoconf

CFLAGS=`echo "${CFLAGS}" | sed -e 's/-O[0-9s]*//g'`
CXXFLAGS=`echo "${CXXFLAGS}" | sed -e 's/-O[0-9s]*//g'`
LDFLAGS=`echo "${LDFLAGS}" | sed -e 's/--coverage//g'`

LDFLAGS="${LDFLAGS} --coverage"
CFLAGS="${CFLAGS} -O0 -ggdb -fprofile-arcs -ftest-coverage"
CXXFLAGS="${CXXFLAGS} -O0 -ggdb -fprofile-arcs -ftest-coverage"
fi

./configure --with-php-config=$(phpenv which php-config) --enable-phalcon CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}"

make -j"$(getconf _NPROCESSORS_ONLN)" > /dev/null 2> ${PROJECT_ROOT}/compile-errors.log
make install

phpenv config-add ${PROJECT_ROOT}/tests/_ci/phalcon.ini

cd ..

if [[ ! -z ${REPORT_COVERAGE+x} ]] && [[ "$REPORT_COVERAGE" = "1" ]]; then
if [[ $(command -v lcov 2>/dev/null) = "" ]]; then
echo -e "lcov does not exist.\nSkip capturing coverage data.\n"
else
# Reset all execution counts to zero
lcov \
--quiet \
--directory ext \
--base-directory=${PROJECT_ROOT} \
--zerocounters

# Capture coverage data
lcov \
--quiet \
--directory ext \
--base-directory=${PROJECT_ROOT} \
--capture \
--compat-libtool \
--initial \
--output-file ${LCOV_REPORT}
fi
fi
@@ -7,13 +7,13 @@
# For the full copyright and license information, please view the LICENSE.txt
# file that was distributed with this source code.

if [ -z "${CC}" ]; then
if [[ -z "${CC}" ]]; then
echo "The CC variable is unset or set to the empty string. Skip"
exit 0
fi

echo "Creating precompiled headers..."
if [ "${CC:0:5}" = "clang" ]; then
if [[ "${CC:0:5}" = "clang" ]]; then
_ext="pch"
_option="-emit-pch"
_arg="-cc1"
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# This file is part of the Phalcon.
#
# (c) Phalcon Team <team@phalconphp.com>
#
# For the full copyright and license information, please view the LICENSE.txt
# file that was distributed with this source code.

php ext/run-tests.php \
--offline \
--show-diff \
--set-timeout 120 \
-n \
-g "FAIL,XFAIL,SKIP,BORK,WARN,LEAK" \
-p $(phpenv which php) \
tests/syntax

0 comments on commit fc1006f

Please sign in to comment.