Skip to content

Commit

Permalink
Enable code coverage report (#1675)
Browse files Browse the repository at this point in the history
* Enable code coverage report

* Correct ExitDieTest

* Correct ExitDieTest (2)
  • Loading branch information
sergeyklay authored Oct 19, 2018
1 parent 22e249b commit 664381e
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 46 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ build/

phpunit.xml
phpcs.xml
coverage.xml
clover.xml

# Ignore for all projects based on Zephir
.temp/
Expand Down
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ addons:
apt:
packages:
- gdb
- lcov

env:
global:
Expand All @@ -29,6 +30,7 @@ env:
- ZEPHIR_PARSER_VERSION="v1.1.2"
- DEFAULT_ZFLAGS="-Wnonexistent-function -Wnonexistent-class -Wunused-variable"
- DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest"
- REPORT_COVERAGE=1

matrix:
fast_finish: true
Expand All @@ -55,8 +57,9 @@ before_install:
- phpenv config-add ./unit-tests/ci/999-default.ini

install:
- composer install $DEFAULT_COMPOSER_FLAGS
- ./unit-tests/ci/install-re2c $RE2C_VERSION
- travis_retry composer install $DEFAULT_COMPOSER_FLAGS
- travis_retry gem install coveralls-lcov
- ./unit-tests/ci/install-re2c.sh $RE2C_VERSION
- ./unit-tests/ci/install-zephir-parser.sh
- ./install

Expand All @@ -77,22 +80,21 @@ jobs:
compiler: clang
env:
- CC=clang
- REPORT_COVERAGE=0
before_script:
- $(phpenv which php) compiler.php generate $DEFAULT_ZFLAGS
- ./unit-tests/ci/install-test-ext.sh
script:
- ./unit-tests/ci/run-unit-tests.sh
- stage: Benchmark
php: 7.2
before_script:
- $(phpenv which php) compiler.php generate $DEFAULT_ZFLAGS
- ./unit-tests/ci/install-test-ext.sh
script:
- phpenv config-rm xdebug.ini || true
- $(phpenv which php) unit-tests/microbench.php
- $(phpenv which php) -d extension=ext/modules/test.so unit-tests/microbench.php

after_success:
- if [[ ! -z "${CODECOV_TOKEN}" ]]; then bash <(curl -s https://codecov.io/bash); fi;
- ./unit-tests/ci/after-success.sh

after_failure:
- ./unit-tests/ci/after-failure.sh
Expand Down
5 changes: 5 additions & 0 deletions unit-tests/Extension/ExitDieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public function setUp()
}

$this->phpBinary .= " -d 'enable_dl=true'";
$extension = realpath( __DIR__ . '/../../ext/modules/test.so');

if (file_exists($extension)) {
$this->phpBinary .= sprintf(" -d 'extension=%s'", $extension);
}

parent::setUp();
}
Expand Down
29 changes: 29 additions & 0 deletions unit-tests/ci/after-success.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# This file is part of the Zephir.
#
# (c) Zephir Team <[email protected]>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.

if [ "${CI}" != "true" ]; then
echo "This script is designed to run inside a CI container only. Stop."
exit 1
fi

PROJECT_ROOT=$(readlink -enq "$(dirname $0)/../../")

if [ "x${REPORT_COVERAGE}" = "x1" ]; then
output=${PROJECT_ROOT}/unit-tests/output/coverage.info

lcov --no-checksum --directory ${PROJECT_ROOT}/ext --capture --compat-libtool --output-file ${output}
lcov \
--remove ${output} "/usr*" \
--remove ${output} "*/.phpenv/*" \
--remove ${output} "${HOME}/build/include/*" \
--compat-libtool \
--output-file ${output}

coveralls-lcov ${output}
fi
56 changes: 28 additions & 28 deletions unit-tests/ci/install-re2c → unit-tests/ci/install-re2c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,45 @@ prefix="${HOME}/.local/opt/${pkgname}/${pkgname}-${RE2C_VERSION}"
bindir="${prefix}/bin"

if [ ! -f "${bindir}/re2c" ]; then
if [ ! -d `dirname ${downloaddir}` ]; then
mkdir -p `dirname ${downloaddir}`
fi
if [ ! -d `dirname ${downloaddir}` ]; then
mkdir -p `dirname ${downloaddir}`
fi

cd `dirname ${downloaddir}`
cd `dirname ${downloaddir}`

if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then
curl -sSL "$source" -o "${pkgname}-${RE2C_VERSION}.tar.gz"
fi
if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then
curl -sSL "$source" -o "${pkgname}-${RE2C_VERSION}.tar.gz"
fi

if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then
echo "Unable to locate ${pkgname}-${RE2C_VERSION}.tar.gz file. Stop."
exit 1
fi
if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then
echo "Unable to locate ${pkgname}-${RE2C_VERSION}.tar.gz file. Stop."
exit 1
fi

if [ ! -d "${downloaddir}" ]; then
mkdir -p "${downloaddir}"
tar -zxf "${pkgname}-${RE2C_VERSION}.tar.gz"
fi
if [ ! -d "${downloaddir}" ]; then
mkdir -p "${downloaddir}"
tar -zxf "${pkgname}-${RE2C_VERSION}.tar.gz"
fi

if [ ! -d "${downloaddir}" ]; then
echo "Unable to locate re2c source. Stop."
exit 1
fi
if [ ! -d "${downloaddir}" ]; then
echo "Unable to locate re2c source. Stop."
exit 1
fi

if [ ! -d "${prefix}" ]; then
mkdir -p "${prefix}"
fi
if [ ! -d "${prefix}" ]; then
mkdir -p "${prefix}"
fi

cd "${downloaddir}"
./configure --prefix="${prefix}"
cd "${downloaddir}"
./configure --prefix="${prefix}"

make -j"$(getconf _NPROCESSORS_ONLN)"
make install
make -j"$(getconf _NPROCESSORS_ONLN)"
make install
fi

if [ ! -x "${bindir}/re2c" ]; then
echo "Unable to locate re2c executable. Stop."
exit 1
echo "Unable to locate re2c executable. Stop."
exit 1
fi

mkdir -p ${HOME}/bin
Expand Down
33 changes: 31 additions & 2 deletions unit-tests/ci/install-test-ext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,39 @@ phpenv config-rm zephir-parser.ini || true

$(phpenv which phpize)

./configure --with-php-config=$(phpenv which php-config) --enable-test
# 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 [ -f /etc/gentoo-release ]; then
# Gentoo Linux
LIBTOOLIZE_BIN=$(command -v libtoolize 2>/dev/null)
aclocal && ${LIBTOOLIZE_BIN} --copy --force && autoheader && autoconf
elif [ "$(uname -s 2>/dev/null)" = "Darwin" ]; then
# macOS
LIBTOOLIZE_BIN=$(command -v glibtoolize 2>/dev/null)
aclocal && ${LIBTOOLIZE_BIN} --copy --force && autoheader && autoconf
else
# Linux
aclocal && libtoolize --copy --force && autoheader && autoconf
fi

CFLAGS="${CFLAGS}"
LDFLAGS="${LDFLAGS}"

if [ "${REPORT_COVERAGE}" = "1" ]; then
CFLAGS="--coverage -fprofile-arcs -ftest-coverage $CFLAGS"
LDFLAGS="--coverage ${LDFLAGS}"
fi

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

make -j"$(getconf _NPROCESSORS_ONLN)"
make install

if [ "x${REPORT_COVERAGE}" = "x1" ]; then
output=${PROJECT_ROOT}/unit-tests/output/coverage.info

lcov --directory ${PROJECT_ROOT}/ext --zerocounters
lcov --directory ${PROJECT_ROOT}/ext --capture --compat-libtool --initial --output-file ${output}
fi

popd

Expand Down
3 changes: 2 additions & 1 deletion unit-tests/ci/run-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ if [ "${PHP_MAJOR}.${PHP_MINOR}" = "7.3" ] || [ "${PHP_MAJOR}.${PHP_MINOR}" = "7
fi

$(phpenv which php) -d extension=ext/modules/test.so unit-tests/phpunit -c ${confing_file}
status=$?

popd

exit $?
exit ${status}
1 change: 0 additions & 1 deletion unit-tests/ci/test.ini

This file was deleted.

6 changes: 4 additions & 2 deletions unit-tests/fixtures/exit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
if (ini_get('enable_dl') == '1') {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
dl($prefix . 'test.' . PHP_SHLIB_SUFFIX);
} else {
exit('"test" extension not loaded; cannot run tests without it');
}
}

if (!extension_loaded('test')) {
exit('"test" extension not loaded; cannot run tests without it');
}

$t = new ExitDie();
$t->testExit();
6 changes: 4 additions & 2 deletions unit-tests/fixtures/exit_int.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
if (ini_get('enable_dl') == '1') {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
dl($prefix . 'test.' . PHP_SHLIB_SUFFIX);
} else {
exit('"test" extension not loaded; cannot run tests without it');
}
}

if (!extension_loaded('test')) {
exit('"test" extension not loaded; cannot run tests without it');
}

$argv = $_SERVER['argv'];

if (isset($argv[1])) {
Expand Down
6 changes: 4 additions & 2 deletions unit-tests/fixtures/exit_string.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
if (ini_get('enable_dl') == '1') {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
dl($prefix . 'test.' . PHP_SHLIB_SUFFIX);
} else {
exit('"test" extension not loaded; cannot run tests without it');
}
}

if (!extension_loaded('test')) {
exit('"test" extension not loaded; cannot run tests without it');
}

$argv = $_SERVER['argv'];
if (isset($argv[1])) {
$t = new ExitDie();
Expand Down
2 changes: 2 additions & 0 deletions unit-tests/output/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit 664381e

Please sign in to comment.