language: c

compiler:
  - gcc
  - clang

install:
  - sudo apt-get update -qq
  # for unit tests
  - sudo apt-get install -y check
  # for static code analysis
  - sudo apt-get install -y cppcheck rats
  # for test code coverage
  - sudo apt-get install -y lcov
  - gem install coveralls-lcov

before_script:
  - cd ${TRAVIS_BUILD_DIR}
  - lcov --directory . --zerocounters

script:
  # - find . -type f -name "*.c" -print | grep -v t\/ | xargs cppcheck 2>&1
  # - find . -type f -name "*.c" -print | grep -v t\/ | xargs rats --language=c
  - git clone --depth 50 https://github.com/proftpd/proftpd.git
  - mkdir -p proftpd/contrib/mod_statsd/
  - cp *.[ch] proftpd/contrib/mod_statsd/
  - cp mod_statsd.* proftpd/contrib/mod_statsd/
  - cp Makefile.in proftpd/contrib/mod_statsd/
  - cp config* proftpd/contrib/mod_statsd/
  - cp install-sh proftpd/contrib/mod_statsd/
  - cp -R t/ proftpd/contrib/mod_statsd/t/
  - cd proftpd
  - ./configure --enable-devel=coverage --enable-dso --enable-tests --with-shared=mod_statsd
  - make
  - make clean
  - ./configure --enable-devel=coverage --enable-tests --with-modules=mod_statsd
  - make
  - cd contrib/mod_statsd && make TEST_VERBOSE=1 check && cd ../../
  # Run `tidy -e -q mod_statsd.html` for doc validation

after_success:
  - cd ${TRAVIS_BUILD_DIR}
  # capture the test coverage info
  - lcov --ignore-errors gcov,source --base-directory ${TRAVIS_BUILD_DIR}/proftpd/contrib/mod_statsd --directory proftpd/contrib/mod_statsd --capture --output-file coverage.info
  # filter out system and test code
  - lcov --remove coverage.info 'api/*' 't/*' '/usr/*' --output-file coverage.info
  # debug before upload
  - lcov --list coverage.info
  # upload coverage info to coveralls
  - coveralls-lcov coverage.info
