roboticslab-uc3m / questions-and-answers

A place for general debate and question&answer
https://robots.uc3m.es/developer-manual/appendix/repository-index.html
2 stars 0 forks source link

Simplify code coverage in CI builds #50

Closed PeterBowman closed 3 years ago

PeterBowman commented 6 years ago

Our Travis lines for code coverage (via Coveralls) look like this (source):

install:
  # see http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/
  - if [ "$CXX" = "g++" ]; then wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz; fi
  - if [ "$CXX" = "g++" ]; then tar xf lcov_1.11.orig.tar.gz; fi
  - if [ "$CXX" = "g++" ]; then sudo make -C lcov-1.11/ install; fi
  - if [ "$CXX" = "g++" ]; then gem install coveralls-lcov; fi

after_success:
  # capture coverage info
  - if [ "$CXX" = "g++" ]; then lcov --directory . --capture --output-file coverage.info; fi
  # filter out system and test code
  - if [ "$CXX" = "g++" ]; then lcov --remove coverage.info  '/usr/*' 'tests/*' --output-file coverage.info; fi
  # debug before upload
  - if [ "$CXX" = "g++" ]; then lcov --list coverage.info; fi
  # uploads to coveralls
  - if [ "$CXX" = "g++" ]; then coveralls-lcov --source-encoding=ISO-8859-1 coverage.info; fi

Perhaps a bit too convoluted if we take a look at official docs:

Copy-paste from the latter:

language: cpp
compiler:
  - gcc
before_install:
  - pip install --user cpp-coveralls
script:
  - ./configure --enable-gcov && make && make check
after_success:
  - coveralls --exclude lib --exclude tests --gcov-options '\-lp'

More links (compiler flags et al.):

jgvictores commented 6 years ago

Yes. That looks cleaner, clearer, and much more efficient.

PeterBowman commented 6 years ago

BTW:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")

This also sets linker flags, while the following doesn't (and makes lcov/gcov crash with undefined reference errors, see this Travis job):

add_compile_options(-fprofile-arcs -ftest-coverage)
PeterBowman commented 3 years ago

Perhaps not worth the trouble if we switch to Codecov at some point: https://github.com/roboticslab-uc3m/questions-and-answers/issues/71.

jgvictores commented 3 years ago

Not too sure, form a quick glance, Codecov looks different but not automatic: https://github.com/codecov/example-cpp11-cmake/blob/9c09479b7edfdc5e75f29a00e36a94394e688bdf/.travis.yml

Edit: Seeing https://docs.codecov.io/docs, maybethe "upload" step can be automatic, but all the lcov stuff seems required.

PeterBowman commented 3 years ago

As part of our ongoing transition to GitHub Actions at https://github.com/roboticslab-uc3m/questions-and-answers/issues/91, we decided to drop support for automated code coverage since we had not been using this tool anyway. In case it is deemed convenient to reinstate such support, see modern alternatives and complementary tools to Coveralls such as https://github.com/roboticslab-uc3m/questions-and-answers/issues/71 and https://github.com/roboticslab-uc3m/questions-and-answers/issues/68.

Marking as wontfix and closing due to obsolescence.