unit.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. ###########################################################################
  3. # This requires coverage and nosetests:
  4. #
  5. # pip install -r requirements.txt
  6. #
  7. # test_base_vcs_mercurial.py requires hg >= 1.6.0 with mq, rebase, share
  8. # extensions to fully test.
  9. ###########################################################################
  10. COVERAGE_ARGS="--omit='/usr/*,/opt/*'"
  11. OS_TYPE='linux'
  12. uname -v | grep -q Darwin
  13. if [ $? -eq 0 ] ; then
  14. OS_TYPE='osx'
  15. COVERAGE_ARGS="--omit='/Library/*,/usr/*,/opt/*'"
  16. fi
  17. uname -s | egrep -q MINGW32 # Cygwin will be linux in this case?
  18. if [ $? -eq 0 ] ; then
  19. OS_TYPE='windows'
  20. fi
  21. NOSETESTS=`env which nosetests`
  22. echo "### Finding mozharness/ .py files..."
  23. files=`find mozharness -name [a-z]\*.py`
  24. if [ $OS_TYPE == 'windows' ] ; then
  25. MOZHARNESS_PY_FILES=""
  26. for f in $files; do
  27. file $f | grep -q "Assembler source"
  28. if [ $? -ne 0 ] ; then
  29. MOZHARNESS_PY_FILES="$MOZHARNESS_PY_FILES $f"
  30. fi
  31. done
  32. else
  33. MOZHARNESS_PY_FILES=$files
  34. fi
  35. echo "### Finding scripts/ .py files..."
  36. files=`find scripts -name [a-z]\*.py`
  37. if [ $OS_TYPE == 'windows' ] ; then
  38. SCRIPTS_PY_FILES=""
  39. for f in $files; do
  40. file $f | grep -q "Assembler source"
  41. if [ $? -ne 0 ] ; then
  42. SCRIPTS_PY_FILES="$SCRIPTS_PY_FILES $f"
  43. fi
  44. done
  45. else
  46. SCRIPTS_PY_FILES=$files
  47. fi
  48. export PYTHONPATH=`env pwd`:$PYTHONPATH
  49. echo "### Running pyflakes"
  50. pyflakes $MOZHARNESS_PY_FILES $SCRIPTS_PY_FILES | grep -v "local variable 'url' is assigned to" | grep -v "redefinition of unused 'json'" | egrep -v "mozharness/mozilla/testing/mozpool\.py.*undefined name 'requests'"
  51. echo "### Running pylint"
  52. pylint -E -e F -f parseable $MOZHARNESS_PY_FILES $SCRIPTS_PY_FILES 2>&1 | egrep -v '(No config file found, using default configuration|Instance of .* has no .* member|Unable to import .devicemanager|Undefined variable .DMError|Module .hashlib. has no .sha512. member)'
  53. rm -rf build logs
  54. if [ $OS_TYPE != 'windows' ] ; then
  55. echo "### Testing non-networked unit tests"
  56. coverage run -a --branch $COVERAGE_ARGS $NOSETESTS test/test_*.py
  57. echo "### Running *.py [--list-actions]"
  58. for filename in $MOZHARNESS_PY_FILES; do
  59. coverage run -a --branch $COVERAGE_ARGS $filename
  60. done
  61. for filename in $SCRIPTS_PY_FILES ; do
  62. coverage run -a --branch $COVERAGE_ARGS $filename --list-actions > /dev/null
  63. done
  64. echo "### Running scripts/configtest.py --log-level warning"
  65. coverage run -a --branch $COVERAGE_ARGS scripts/configtest.py --log-level warning
  66. echo "### Creating coverage html"
  67. coverage html $COVERAGE_ARGS -d coverage.new
  68. if [ -e coverage ] ; then
  69. mv coverage coverage.old
  70. mv coverage.new coverage
  71. rm -rf coverage.old
  72. else
  73. mv coverage.new coverage
  74. fi
  75. else
  76. echo "### Running nosetests..."
  77. nosetests test/
  78. fi
  79. rm -rf build logs