Skip to content

Commit

Permalink
WIP Split tests by runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Feb 2, 2017
1 parent 55c8ce7 commit e320695
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 47 deletions.
13 changes: 13 additions & 0 deletions .ci/bears.dirs.prune.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Delete empty bear directories
set -e

dirs=$(find bears -depth -type d -and -not -name '__pycache__')

for dir in $dirs; do
bears=$(ls $dir/*Bear.py 2>/dev/null || true)
subdirs=$(ls -d $dir/*/ 2>/dev/null || true)
if [[ -z "$bears""$subdirs" ]]; then
echo Removing $dir
rm -rf $dir
fi
done
91 changes: 91 additions & 0 deletions .ci/bears.prune.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Delete bears
set -e

if [[ "$BEARS" == "all" ]]; then
echo "No bears pruned."
exit 0
fi

bears=$(find bears -type f -and -name '*Bear.py' | sort)

yield_result_bears=$(grep -m 1 -l 'yield Result' $bears)

non_yield_result_bears=$(comm -23 <(ls $bears) <(ls $yield_result_bears))

requirement_bears=$(grep -m 1 -l 'Requirement(' $bears)

cabal_requirement_bears=$(grep -m 1 -l CabalRequirement $requirement_bears)
gem_requirement_bears=$(grep -m 1 -l GemRequirement $requirement_bears)
go_requirement_bears=$(grep -m 1 -l GoRequirement $requirement_bears)
npm_requirement_bears=$(grep -m 1 -l NpmRequirement $requirement_bears)
rscript_requirement_bears=$(grep -m 1 -l RscriptRequirement $requirement_bears)

pip_requirement_bears=$(grep -m 1 -l PipRequirement $requirement_bears)

non_pip_runtime_requirement_bears="$cabal_requirement_bears $gem_requirement_bears $go_requirement_bears $npm_requirement_bears $rscript_requirement_bears"

other_requirement_bears=$(comm -23 <(ls $requirement_bears) <(ls $non_pip_runtime_requirement_bears $pip_requirement_bears))

distribution_only_bears=$(grep -Pl 'DistributionRequirement\(' $other_requirement_bears)

# Verify that DistributionRequirement is the only other Requirement subclass used
unknown_requirement_bears=$(grep -Pl '(?<!Distribution)Requirement\(' $other_requirement_bears || true)

if [[ -n "$unknown_requirement_bears" ]]; then
echo "Unknown requirements for $unknown_requirement_bears"
exit 1
fi

pip_only_requirement_bears=$(comm -23 <(ls $pip_requirement_bears) <(ls $non_pip_runtime_requirement_bears))
pip_plus_requirement_bears=$(comm -23 <(ls $pip_requirement_bears) <(ls $pip_only_requirement_bears))

no_requirement_bears=$(comm -23 <(ls $bears) <(ls $requirement_bears))

clang_bears=''
other_bears=''
for bear in $no_requirement_bears; do
if [[ ${bear/Clang/} != $bear ]]; then
clang_bears="$clang_bears $bear"
else
other_bears="$other_bears $bear"
fi
done

executable_linter_bears=$(grep -m 1 -l '@linter(executable=' $other_bears)
executable_other_bears=$(grep -m 1 -l 'run_shell_command' $other_bears)

other_bears=$(comm -23 <(ls $other_bears) <(ls $executable_linter_bears $executable_other_bears))

non_yield_result_other_bears=$(comm -23 <(ls $other_bears) <(ls $yield_result_bears))

if [[ -n "$non_yield_result_other_bears" ]]; then
echo "Unknown bear type $non_yield_result_other_bears"
exit 1
fi

python_bears="$pip_only_requirement_bears $clang_bears $other_bears"

non_python_bears=$(comm -23 <(ls $bears) <(ls $python_bears))

remove_bears=''

if [[ $BEARS == "python" ]]; then
# The test for generate_package depends on non-Python bears
remove_bears="$non_python_bears"
elif [[ $BEARS == "npm" ]]; then
remove_bears=$(comm -23 <(ls $bears) <(ls $npm_requirement_bears))
elif [[ $BEARS == "gem" ]]; then
remove_bears=$(comm -23 <(ls $bears) <(ls $gem_requirement_bears))
fi

if [[ -n "$remove_bears" ]]; then
# generate_package.py only needs testing with BEARS=all
remove_bears="bears/generate_package.py $remove_bears"
fi

for bear in $remove_bears; do
echo Removing $bear
rm $bear
done

source .ci/bears.dirs.prune.sh
17 changes: 17 additions & 0 deletions .ci/tests.prune.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Delete tests for bears that have been removed
set -e

bear_tests=$(find tests -type f -and -name '*Test.py')

for test in tests/generate_packageTest.py $bear_tests; do
bear=${test/Test.py/.py}
bear=${bear/tests/bears}
dir=$(dirname $bear)
if [[ ! -d $dir ]]; then
echo Removing $test
rm -f $test
elif [[ ! -f $bear ]]; then
echo Removing $test
rm -f $test
fi
done
2 changes: 1 addition & 1 deletion .ci/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source .ci/env_variables.sh
args=()

if [ "$system_os" == "LINUX" ] ; then
args+=('--cov' '--cov-fail-under=100' '--doctest-modules')
args+=('--cov' '--cov-fail-under=100' '--cov-append' '--doctest-modules')
fi

python3 -m pytest "${args[@]}"
127 changes: 84 additions & 43 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,59 @@
sudo: required
sudo: false

language: python
python:
# 2.7 is rejected by dependency mypy-lang
- 3.3
- 3.4
- 3.5
- 3.6-dev

dist: trusty
- 3.6

addons:
apt:
sources:
- ubuntu-toolchain-r-test
- avsm # OPAM stable
- hvr-ghc # Haskell
packages:
- cabal-install
- chktex
- clang-3.4
- cppcheck
- flawfinder
- gfortran
- ghc
- haskell-platform
- indent
- libblas-dev
- liblapack-dev
- libperl-critic-perl
- libxml2-utils
- luarocks
- menhir
- mono-mcs
- ocaml
- opam
- php-codesniffer
- verilator

dist: trusty

matrix:
include:
- language: node_js
node_js: 4
env: BEARS=npm
- language: ruby
rvm: 2
env: BEARS=gem
- python: 3.5
sudo: required
env: BEARS=all
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- avsm # OPAM stable
- hvr-ghc # Haskell
packages:
- cabal-install
- chktex
- clang-3.4
- cppcheck
- flawfinder
- gfortran
- ghc
- haskell-platform
- indent
- libblas-dev
- liblapack-dev
- libperl-critic-perl
- libxml2-utils
- luarocks
- menhir
- mono-mcs
- ocaml
- opam
- php-codesniffer
- verilator

- python: 3.3
env: UNSUPPORTED=true

cache:
pip: true
Expand All @@ -62,45 +79,55 @@ cache:

env:
global:
- BEARS=python
- CIRCLE_NODE_INDEX=-1 # Avoid accidentially being a CircleCI worker
- USE_PPAS="marutter/rdev staticfloat/juliareleases ondrej/golang"
- R_LIB_USER=~/R/Library
- LINTR_COMMENT_BOT=false
- PATH="$PATH:$TRAVIS_BUILD_DIR/node_modules/.bin:$TRAVIS_BUILD_DIR/vendor/bin:$HOME/dart-sdk/bin:$HOME/.cabal/bin:$HOME/infer-linux64-v0.7.0/infer/bin:$HOME/pmd-bin-5.4.1/bin:$HOME/bakalint-0.4.0:$HOME/.local/tailor/tailor-latest/bin"
- PATH="$HOME/bin:$PATH:$TRAVIS_BUILD_DIR/node_modules/.bin:$TRAVIS_BUILD_DIR/vendor/bin:$HOME/dart-sdk/bin:$HOME/.cabal/bin:$HOME/infer-linux64-v0.7.0/infer/bin:$HOME/pmd-bin-5.4.1/bin:$HOME/bakalint-0.4.0:$HOME/.local/tailor/tailor-latest/bin"

before_install:
- export TRAVIS_PYTHON_VERSION_MAJOR=${TRAVIS_PYTHON_VERSION%.[0-9]}
- export TRAVIS_PYTHON_VERSION_MINOR=${TRAVIS_PYTHON_VERSION#[0-9].}
- >
if [[ $TRAVIS_PYTHON_VERSION_MINOR < 4 || $TRAVIS_PYTHON_VERSION_MAJOR == 2 ]]; then
UNSUPPORTED=true
if [[ -z "$TRAVIS_PYTHON_VERSION" ]]; then
mkdir -p $HOME/bin
ln -sf $(which pip3) $HOME/bin/pip
ln -sf $(which python3) $HOME/bin/python
pip --version
python --version
fi
- nvm install 4
- nvm use 4
# Remove Ruby directive from Gemfile as this image has 2.2.5
- sed -i '/^ruby/d' Gemfile
- mkdir -p ~/.apt-cache
- if [[ "$UNSUPPORTED" != true ]]; then bash .ci/deps.sh; fi
- if [[ "$UNSUPPORTED" != true ]]; then bash .ci/deps.shellcheck.sh; fi
- if [[ "$BEARS" == "all" ]]; then nvm install 4; nvm use 4; bash .ci/deps.sh; fi
- if [[ "$BEARS" == "all" ]]; then bash .ci/deps.shellcheck.sh; fi
# https://github.com/coala/coala/issues/3183
- cp requirements.txt requirements.orig
- cat test-requirements.txt docs-requirements.txt bear-requirements.txt >> requirements.txt
- cat test-requirements.txt docs-requirements.txt >> requirements.txt
- if [[ "$BEARS" == "all" || "$BEARS" == "python" ]]; then
cat bear-requirements.txt >> requirements.txt;
fi
- sed -i '/^-r/d' requirements.txt
# On unsupported versions, coala will be installed in the `script` block
- >
if [[ "$UNSUPPORTED" == true ]]; then
sed -e '/^coala/d' requirements.txt > requirements.new
mv requirements.new requirements.txt
BEARS=none
fi
- if [[ -z "$TRAVIS_PYTHON_VERSION" ]]; then pip install -r requirements.txt; fi

before_script:
- mv requirements.orig requirements.txt
# nltk 3.2.2 dropped support for Python 3.3
- >
if [[ "$TRAVIS_PYTHON_VERSION" != "3.3" ]]; then
if [[ "$BEARS" == "all" || "$BEARS" == "python" ]]; then
python -m nltk.downloader punkt maxent_treebank_pos_tagger averaged_perceptron_tagger
fi
# Only keep non-Python bears on Python 3.4
- bash .ci/bears.prune.sh
# Delete tests for removed bears
- bash .ci/tests.prune.sh

script:
- >
Expand All @@ -113,12 +140,26 @@ script:
fi
fi
- if [[ "$UNSUPPORTED" == true ]]; then exit; fi
- python setup.py bdist_wheel
- pip install $(ls ./dist/*.whl)"[alldeps]"
- coverage run setup.py bdist_wheel
- >
if [[ "$BEARS" == "all" || "$BEARS" == "python" ]]; then
pip install $(ls ./dist/*.whl)"[alldeps]"
else
pip install $(ls ./dist/*.whl)
fi
- bash .ci/tests.sh
# Ensure bear requirements are in sync with the bear PipRequirement
- .ci/generate_bear_requirements.py
- git diff --exit-code bear-requirements.txt Gemfile package.json
- >
if [[ "$BEARS" == "all" || "$BEARS" == "python" ]]; then
git diff --exit-code bear-requirements.txt
fi;
if [[ "$BEARS" == "all" || "$BEARS" == "gem" ]]; then
git diff --exit-code Gemfile
fi;
if [[ "$BEARS" == "all" || "$BEARS" == "npm" ]]; then
git diff --exit-code package.json
fi
# https://github.com/coala/coala-bears/issues/1037
- >
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion bears/java/JavaPMDBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from coala_utils.param_conversion import negate


@linter('bash', output_format='regex',
@linter(executable='bash', output_format='regex',
output_regex=r'.+:(?P<line>.+):(?P<message>.*)')
class JavaPMDBear:
"""
Expand Down
3 changes: 1 addition & 2 deletions bears/perl/PerlCriticBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class PerlCriticBear:
"""

LANGUAGES = {'Perl'}
REQUIREMENTS = {DistributionRequirement(apt_get='perl'),
DistributionRequirement(apt_get='libperl-critic-perl')}
REQUIREMENTS = {DistributionRequirement(apt_get='libperl-critic-perl')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
LICENSE = 'AGPL-3.0'
Expand Down

0 comments on commit e320695

Please sign in to comment.